Android Gradle 无法解决
Posted
技术标签:
【中文标题】Android Gradle 无法解决【英文标题】:Android Gradle Failed to resolve 【发布时间】:2017-05-01 16:59:35 【问题描述】:我在 gradle 文件中收到此错误:
错误:无法解决:com.google.android.gms:play-services-measurement:10.2.4
-安装存储库并同步项目
-打开文件
-在项目结构对话框中显示
但我没有在我的应用中使用 play-services-measurement。 另一方面,如果我单击“安装存储库并同步项目”链接,则不会发生任何事情。 任何人都可以帮助我吗?我一直在这个问题上浪费时间。
这是我的完整 gradle 文件:
apply plugin: 'com.android.application'
buildscript
repositories
mavenCentral()
dependencies
classpath 'com.google.gms:google-services:3.0.0'
android
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileOptions
encoding "UTF-8"
lintOptions
disable 'MissingTranslation'
abortOnError false
defaultConfig
applicationId "xxx.yyy.zzz"
minSdkVersion 9
targetSdkVersion 25
versionCode 120
versionName "1.20"
multiDexEnabled true
//Enabling multi dex support due to exceeding the 65K methods dex limit imposed by Android: http://***.com/questions/29756188/java-finished-with-non-zero-exit-value-2-android-gradle
buildTypes
release
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all variant ->
variant.outputs.each output ->
def formattedDate = new Date().format('yyyyMMddHHmmss')
def newName = output.outputFile.name
newName = newName.replace("app-", "MyAppName")
newName = newName.replace("-release", "-release" + formattedDate)
//noinspection GroovyAssignabilityCheck
output.outputFile = new File(output.outputFile.parent, newName)
dependencies
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':simple-crop-image-lib')
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.firebase:firebase-messaging:10.2.4'
compile 'com.google.android.gms:play-services:10.2.4' //8.3.0' 10.2.4' 9.0.0' 9.6.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:mediarouter-v7:25.3.1'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
//For soap:
compile files('libs/ksoap2-android-assembly-2.5.8-jar-with-dependencies.jar')
apply plugin: 'com.google.gms.google-services'
【问题讨论】:
【参考方案1】:在 Android SDK 中更新 Google 存储库。适用于我的版本 47。
来自火力基地doc:
dependencies
// ...
compile 'com.google.firebase:firebase-core:10.2.4'
compile 'com.google.firebase:firebase-messaging:10.2.4'
// Getting a "Could not find" error? Make sure you have
// the latest Google Repository in the Android SDK manager
【讨论】:
很高兴知道,官方文档中没有这个firebase.google.com/docs/android/setup【参考方案2】:我努力从“app build.gradle”中删除这些行:
buildscript
repositories
mavenCentral()
dependencies
classpath 'com.google.gms:google-services:3.0.0'
并将这些添加到“项目 build.gradle”:
buildscript
repositories
jcenter()
dependencies
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
【讨论】:
以上是关于Android Gradle 无法解决的主要内容,如果未能解决你的问题,请参考以下文章
Weex 添加插件之解决could not find gradle wrapper within android sdk
MyEclipse中android 项目如何解决第三方jar无法关联源码的问题( The JAR of this class file belongs to container 'Androi
android studio firebase 错误:“无法解析 Android 应用程序模块的 Gradle 配置。解决 gradle 构建问题和/或重新同步。”