19
votes

I am getting below error in my new Android studio version basic hello world is also not building in gradle. cloud you please help on the same.

This is the error I am getting in new android studio version :

This is the error I am getting in new android studio version

My gradle file is as below

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "payments.com.java.payments"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

This is the logs i am getting

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0-rc01. Open File Show Details

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.2. Open File Show Details

Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.test:runner:1.0.2. Open File Show Details

Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.test.espresso:espresso-core:3.0.2. Open File Show Details

Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0-rc01. Open File Show Details

Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.2. Open File Show Details

Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0-rc01. Open File Show Details

Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.2. Open File Show Details

Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0-rc01. Open File Show Details

Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.2. Open File Show Details

Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0-rc01. Open File Show Details

Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.2. Open File Show Details

15
share your gradle file. And instead of pasting a screenshot, paste the stack trace in text. - Abubakar
I suggest moving to androidx.appcompat:appcompat libraries instead of com.android.support:appcompat-v7 as the support library will not be getting anymore updates after 28.0.0 - tyczj
Updated question with gradle file and logs - user2454202
@tyczj That didnt help. I still have the issue.and it is not just with appcompat all of below elements are failing implementation 'com.android.support:appcompat-v7:28.0.0-rc01' implementation 'com.android.support.constraint:constraint-layout:1.1.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - user2454202

15 Answers

10
votes

Check your internet connectivity. For me it was just internet connectivity problem. If you are under a proxy server. Go to File > Settings > Appearance & Behavior >System Settings >HTTP Proxy and enter your proxy details there. Use the check connection option to verify your connection. Here is a reference to my gradle file.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
       applicationId "com.oops.pk.birthday_card"
       minSdkVersion 23
       targetSdkVersion 28
       versionCode 1
       versionName "1.0"
       testInstrumentationRunner 
       "android.support.test.runner.AndroidJUnitRunner"  
    }
    buildTypes {
         release {
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 
             'proguard-rules.pro'
          }
     }
}

dependencies {
     implementation fileTree(dir: 'libs', include: ['*.jar'])
     implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
     implementation 'com.android.support:support-v4:28.0.0'
     implementation 'com.android.support:recyclerview-v7:28.0.0'
     implementation 'com.android.support:design:28.0.0'
     testImplementation 'junit:junit:4.12'
     androidTestImplementation 'com.android.support.test:runner:1.0.2'
     androidTestImplementation 'com.android.support.test.espresso:espresso- 
     core:3.0.2'
 }
4
votes

I use Shadowsocks proxy in China, open ~/.gradle/gradle.properties and comment https host and port

#systemProp.https.proxyPort=1080
systemProp.http.proxyHost=127.0.0.1
#systemProp.https.proxyHost=127.0.0.1
systemProp.http.proxyPort=1080

after that, create new project again or build your project again, done

2
votes

My colleague ran into same problem. We solve this issue by deleting .android , .AndroidStudiox.x and .gradle folders.This will delete all current android settings and will download again when open android studio. make sure android studio must be close.enter image description here

2
votes

This approach worked for me.

Go to - build.gradle (Module: app)

Search for (for me) :

implementation 'com.android.support:appcompat-v7:29.+’

Replace it with:

implementation 'com.android.support:appcompat-v7:28.+'

Hit 'Sync' or 'Try Again'.

Reference:

Before:

After

1
votes

Use :

implementation 'com.android.support:appcompat-v7:28.+'

The .+ will match any version of appcompat-v7:28. Currently there are 28.0.0-alpha1 and 28.0.0-alpha3 in Google's Maven repository.

1
votes

You nee to disable Offline mode if you've checked it. File > Settings > Build,Execution and deployment > Gradle - Uncheck offline mode and apply.

Also, please check your internet connectivity.

1
votes

Try this: delete your gradle http proxy C:\Users***.gradle\gradle.properties

enter image description here

1
votes
  1. The reason

    If you are in China, the reason about this maybe be your Android Studio hadn't set the proxy correctly. So when you built the application, the gradle can't access to the Google's Maven Repository to download the dependencies(such as support library).

    And notice: The Android Studio is allow socks proxy and http proxy, but the gradle is only allow http proxy. So you may find that your Android Studio can download the SDK or even upgrade if you had set socks proxy in Android Studio. But when you built, the gradle can't download the support library because you are use socks proxy now.

  2. How to fix

    If you use Shadowsocks proxy. Follow this:

    • For Mac OS:

      You should download ShadowsocksX-NG not ShadowsocksX, because ShadowsocksX may not compatible with the Android Studio. And the ShadowsocksX-NG is use socks5 proxy, the Android Studio is access socks5 proxy, but remember gradle didn't.

      You can see the ShadowsocksX-NG's proxy info in the Preferences Setting, you can find that:

      • local socks5 host: 127.0.0.1

      • local socks5 port: 1086

      • local PAC port: 1089

      • local http port: 1087

      So you should set the http proxy in Android Studio like this:

      set http proxy in AS on Mac

    • For Windows:

      You can download the Shadowsocks-windows and have a look at the correct host and port, and then set them to the Android Studio proxy.

      • If you select http proxy, you may set like this:

        set http proxy in AS on Windows

        And if it still can't work, try to add these below codes to the ~/.gradle/gradle.properties file:

        systemProp.https.proxyHost=127.0.0.1

        systemProp.https.proxyPort=1080

        systemProp.http.proxyHost=127.0.0.1

        systemProp.http.proxyPort=1080

      • If you select socks proxy, you may set like this:

        set socks proxy in AS on Windows

        And if you use socks proxy, it may still can't work, trying to add these codes to the ~/.gradle/gradle.properties file, like this:

        set socks proxy for gradle

        The purpose of this is to set gradle proxy.

    Hopefully it can help you.

0
votes

If you have any other working (not error) Android Studio Project,

You can check the settings of build.gradle under your Project - app and look for this line:

implementation 'com.android.support:appcompat-v7:***'

Is your working SDK version in your working project, then replace your

implementation 'com.android.support:appcompat-v7:28.0.0-rc01'

with the working SDK version (***)

if you don't have any working (without error) project, you can try mine:

implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'

Hopefully this can solve your problem, because it solved mine just now.

0
votes

I faced same error.I found a solution.I hope it helps you too.

Go to build.gradle(Module:app) and delete

 implementation 'com.android.support:design:28.0.0-rc01'
0
votes

if not 28 version supported means change the complied and target version to 27

0
votes

Refer to this Youtube video which I created as a solution to this Problem,

https://www.youtube.com/watch?v=ZAYtPzjDSQU&feature=youtu.be

This is how your Gradle Should look.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "payments.banamex.citi.com.banamexpayments"
        minSdkVersion 17
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
0
votes

I just had same problem and it is fixed by replacing a dependency file from previous properly working project. Just replace the depndency file in the gradle by another project's dependency gradle file.

0
votes

I had similar issue when I created a new project and androidx was marked but I was connected to internet. The simple solution was to just connect to internet and sync the project again. Voila it builds with no error. You can try that.

-1
votes

"Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0-rc02."

This was the error i was getting in the gradle and is simply solved just by connecting to the internet.