16

I have been trying to switch my project from Intellij to Android Studio, which has required me to create a build.gradle file. I know I can add each of these as a library dependency, but I ideally want to be able to get the maven repository dependency working.

Every time I sync, my support libraries are synced fine, but for each third-party library, I get something like

"Error:(30, 13) Failed to resolve: com.facebook.android:facebook-android-sdk:3.23.1"

for each library.

buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:1.1.0' } } apply plugin: 'com.android.application' dependencies { compile fileTree(dir: 'libs', include: '*.jar') // Google Play Services compile 'com.google.android.gms:play-services:6.5.87' // Support Libraries compile 'com.android.support:appcompat-v7:22.0.0' compile 'com.android.support:cardview-v7:21.0.3' compile 'com.android.support:gridlayout-v7:21.0.3' compile 'com.android.support:mediarouter-v7:21.0.3' compile 'com.android.support:palette-v7:21.0.3' compile 'com.android.support:recyclerview-v7:21.0.3' compile 'com.android.support:support-annotations:21.0.3' compile 'com.android.support:support-v13:21.0.3' compile 'com.android.support:support-v4:22.0.0' // third-party libraries compile 'com.amazonaws:aws-java-sdk:1.9.24' compile 'com.facebook.android:facebook-android-sdk:3.23.1' compile 'com.github.markushi:android-ui:1.2' compile 'de.hdodenhof:circleimageview:1.2.2' compile 'it.neokree:MaterialNavigationDrawer:1.3.2' } android { compileSdkVersion 21 buildToolsVersion "21.1.2" sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['src'] aidl.srcDirs = ['src'] renderscript.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] } // Move the tests to tests/java, tests/res, etc... instrumentTest.setRoot('tests') // Move the build types to build-types/<type> // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... // This moves them out of them default location under src/<type>/... which would // conflict with src/ being used by the main source set. // Adding new build types or product flavors should be accompanied // by a similar customization. debug.setRoot('build-types/debug') release.setRoot('build-types/release') } } 

8 Answers 8

21

Add:

repositories { mavenCentral() } 

to the build.gradle. Now you have repositories defined only in build script which resolves dependencies only for the buildscript itself not for the project.

Sign up to request clarification or add additional context in comments.

2 Comments

I too faced the same problem but I had to disable "work offline" option in gradle settings of Android Studio to make it work. Just adding it here so that if anyone else faces my issue can benefit from it.
Just to clarify: This block of code needs to be added to the allprojects block of the highest level build.gradle file.
10

Just to share infomation, I got same problem and the solution was different.

In my case, proxy server was used and it causes the problem. I needed to configure https proxy settings, as discussed in gradle behind proxy in Android Studio 1.3.

Comments

8

If you use VPN | Proxy on your system then use your proxy info in the gradle.properties file in your project like the following lines of code:

# HTTP Proxy systemProp.http.proxyHost={Host Address} systemProp.http.proxyPort={Port Number} systemProp.http.proxyUser={Proxy Username} systemProp.http.proxyPassword={Proxy Password} systemProp.http.nonProxyHosts={NonProxy Hosts Address} # like: 127.0.0.1,localhost # HTTPS Proxy systemProp.https.proxyHost={Host Address} systemProp.https.proxyPort={Port Number} systemProp.https.proxyUser={Proxy Username} systemProp.https.proxyPassword={Proxy Password} systemProp.https.nonProxyHosts={NonProxy Hosts Address} # like: 127.0.0.1,localhost 

Now just replace {.....} in the above code with appropriate data


Also you can set Android studio proxies like the following image by your proxy info in File>Settings:

enter image description here

Now test again...!

Comments

1
repositories { jcenter { url "http://jcenter.bintray.com/" } 

// mavenCentral() }

Comments

1

this helps

allprojects { repositories { jcenter() maven { url "https://jitpack.io" } } } 

in projects's gradle

Comments

0

Maybe this help

allprojects { repositories { jcenter() } } 

Comments

0

well , if your network connection is fine(wheter using proxy | VPNs or not), simply just try turn off'offline mode' and sync when using android studio with gradle 2.3,this worked for me :)

Comments

0

Most of the settings do not currently work with new Android updates, so the solution currently is to add this section to buuild.Gradle(Project:)

buildscript { repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.2.1' } } ****************************************** // Add this section if it does not exist repositories { mavenCentral() } ****************************************** allprojects { repositories { google() mavenCentral() maven { url "https://jitpack.io" } ********************************************** // Add this section if it does not exist gradlePluginPortal() ********************************************** } } task clean(type: Delete) { delete rootProject.buildDir } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.