2015-03-18 16 views
15

Ich habe versucht, mein Projekt von Intellij zu Android Studio zu wechseln, wofür ich eine build.gradle-Datei erstellen musste. Ich weiß, dass ich jede davon als eine Bibliotheksabhängigkeit hinzufügen kann, aber ich möchte im Idealfall in der Lage sein, die Abhängigkeit vom Maven-Repository zu erhalten.Gradle in Android Studio: Fehler beim Auflösen von Drittanbieterbibliotheken

Jedes Mal, wenn ich synchronisieren, sind meine Unterstützung Bibliotheken fein synchronisiert, aber für jede Bibliothek von Drittanbietern, erhalte ich für jede Bibliothek etwas wie

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

.

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') 
} 
} 

Antwort

19

Anzahl:

repositories { 
    mavenCentral() 
} 

zum build.gradle. Jetzt haben Sie repositories nur in Build-Skript definiert, die Abhängigkeiten nur für die buildscript selbst nicht für das Projekt löst.

+1

Das hat funktioniert, danke! –

+0

Gern geschehen! – Opal

+1

Ich hatte auch das selbe Problem, aber ich musste die Option "Offline arbeiten" in Gradle-Einstellungen von Android Studio deaktivieren, damit es funktionierte. Fügen Sie es einfach hier hinzu, damit andere davon profitieren können. – Supreethks

7

Wenn Sie VPN | Proxy auf Ihrem System verwenden dann Ihre Proxy-Informationen in der gradle.properties Datei in Ihrem Projekt wie die folgenden Codezeilen:

# 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 

Jetzt ersetzen Sie einfach {.....} in dem obigen Code mit den entsprechenden Daten


Sie auch kann in File>Settings von Ihrem Proxy-Informationen Proxies Android Studio wie das folgende Bild gesetzt:

enter image description here

Jetzt noch einmal testen ...!

0

Vielleicht Hilfe

allprojects { 
    repositories { 
     jcenter() 
    } 
} 
0
repositories { 
jcenter { 
    url "http://jcenter.bintray.com/" 
} 

// mavenCentral() }

0

gut, wenn die Netzwerkverbindung in Ordnung ist (wheter Proxy | VPNs oder nicht), einfach nur versuchen, turn off'offline mode' and sync bei der anwendung von android studio mit gradle 2.3, funktionierte das für mich :)

0

dies hilft

in projects's gradle

Verwandte Themen