Gradle 在 Android Studio 中:无法解析第三方库
Gradle in Android Studio: Failed to resolve third-party libraries
我一直在尝试将我的项目从 Intellij 切换到 Android Studio,这要求我创建一个 build.gradle 文件。我知道我可以将它们中的每一个添加为库依赖项,但理想情况下我希望能够使 Maven 存储库依赖项正常工作。
每次同步时,我的支持库都同步得很好,但对于每个第三方库,我都会得到类似
的信息
"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')
}
}
添加:
repositories {
mavenCentral()
}
到build.gradle
。现在你只在构建脚本中定义了 repositories
,它只解决 buildscript
本身而不是项目的依赖关系。
只是为了分享信息,我遇到了同样的问题,但解决方案不同。
在我的例子中,使用了代理服务器并导致了问题。我需要 configure https proxy settings, as discussed in .
如果你使用VPN
| Proxy
在您的系统上,然后在项目的 gradle.properties
文件中使用您的代理信息,如以下代码行:
# 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
现在只需用适当的数据替换上面代码中的{.....}
您也可以通过 File>Settings
中的代理信息设置 Android 工作室代理,如下图所示:
现在再次测试...!
也许这有帮助
allprojects {
repositories {
jcenter()
}
}
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
// mavenCentral()
}
好吧,如果您的网络连接正常(无论是否使用代理 | VPN),只需在使用 android studio 和 gradle 2.3
时尝试 turn off'offline mode' and sync
,这对我有用:)
这有帮助
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
在项目的 gradle
我一直在尝试将我的项目从 Intellij 切换到 Android Studio,这要求我创建一个 build.gradle 文件。我知道我可以将它们中的每一个添加为库依赖项,但理想情况下我希望能够使 Maven 存储库依赖项正常工作。
每次同步时,我的支持库都同步得很好,但对于每个第三方库,我都会得到类似
的信息"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')
}
}
添加:
repositories {
mavenCentral()
}
到build.gradle
。现在你只在构建脚本中定义了 repositories
,它只解决 buildscript
本身而不是项目的依赖关系。
只是为了分享信息,我遇到了同样的问题,但解决方案不同。
在我的例子中,使用了代理服务器并导致了问题。我需要 configure https proxy settings, as discussed in
如果你使用VPN
| Proxy
在您的系统上,然后在项目的 gradle.properties
文件中使用您的代理信息,如以下代码行:
# 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
现在只需用适当的数据替换上面代码中的{.....}
您也可以通过 File>Settings
中的代理信息设置 Android 工作室代理,如下图所示:
现在再次测试...!
也许这有帮助
allprojects {
repositories {
jcenter()
}
}
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
// mavenCentral() }
好吧,如果您的网络连接正常(无论是否使用代理 | VPN),只需在使用 android studio 和 gradle 2.3
时尝试 turn off'offline mode' and sync
,这对我有用:)
这有帮助
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
在项目的 gradle