0

Sorry for the silly question but after installing Android Studio, while creating a new project it was giving me following error:

Error:Failed to resolve: com.android.support:support-core-ui:27.1.1

I added this dependencies in my gradle dependency file as follows:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso- 
    core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:27.+'
    compile "com.android.support:support-core-ui:27.1.1"
    testCompile 'junit:junit:4.12'
}

But still it is showing the same error. Please suggest me some solution to rectify this problem.

Build.gradle for My project:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Chanfool21
  • 57
  • 9

1 Answers1

2

You are missing repository URL Add following:

buildscript {
    repositories {
        google()
        jcenter()
    }
    ...
}
allprojects {
    repositories {
        google()  
        jcenter()
        ...
    }
}

If you're using a version of Gradle lower than 4.1, use following instead of google():

maven {
    url 'https://maven.google.com'
    // An alternative URL is 'https://dl.google.com/dl/android/maven2/'

}
Sagar
  • 23,903
  • 4
  • 62
  • 62
  • I tried adding this on the same repositories block as jcenter() , but now it's showing this error: Gradle sync failed: Could not find method google() for arguments [] on repository container. Consult IDE log for more details (Help | Show Log) – Chanfool21 Jun 09 '18 at 11:44
  • @Chanfool21 use `maven { url 'https://maven.google.com' // An alternative URL is 'https://dl.google.com/dl/android/maven2/' }` as indicated in answer – Sagar Jun 09 '18 at 11:45
  • As you suggested Sagar, I added maven is place of google there in repositories block, after that it's giving me strange error: Gradle sync failed: Could not find common.jar (android.arch.core:common:1.1.0). Searched in the following locations: https://jcenter.bintray.com/android/arch/core/common/1.1.0/common-1.1.0.jar – Chanfool21 Jun 09 '18 at 11:51
  • @Chanfool21 you need to add `maven {...}` before `jcenter()`. Then clean and rebuild. – Sagar Jun 09 '18 at 11:53
  • Thanks for the help Sagar, it successfully built. A lot of thanks Sir :) – Chanfool21 Jun 09 '18 at 11:57
  • Hi Sagar, need help with this: https://stackoverflow.com/questions/50781208/error-in-activity-main-xml-after-creating-a-new-project?noredirect=1#comment88569342_50781208 If you can see, it will be lot of help – Chanfool21 Jun 10 '18 at 07:18