17

Gradle 项目刷新失败

在我将KenBurnsView库添加到build.gradle应用程序级别之后。当我尝试同步 gradle 时,它​​失败了。

build.gradle(应用级别)

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
    applicationId "com.sample.ac"
    minSdkVersion 16
    targetSdkVersion 24
    versionCode 1
    versionName "1.0_dev"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    jackOptions {
        enabled true
    }
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

repositories {
    jcenter()
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
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:25.0.1'
compile 'com.android.support:design:25.0.1'
compile 'com.android.support:recyclerview-v7:25.0.1'
compile 'com.android.support:cardview-v7:25.0.1'

//ButterKnife for view injector
compile 'com.jakewharton:butterknife:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'

// EventBus for passing data between activities and fragments
compile 'org.greenrobot:eventbus:3.0.0'

//Material Loading Circular Progress Bar with white background
compile 'com.lsjwzh:materialloadingprogressbar:0.5.8-RELEASE'

//GSON for parsing JSON into Java Object and vice versa
compile 'com.google.code.gson:gson:2.6.2'

//For Image Loading from network
compile 'com.github.bumptech.glide:glide:3.7.0'

//SLiding up Panel Layout for Music Player
compile 'com.sothree.slidinguppanel:library:3.3.0'

//For Network Calling
compile 'com.mcxiaoke.volley:library:1.0.19'

//ViewPagerIndicator
compile 'com.romandanylyk:pageindicatorview:0.0.7'

//Google Play Services
compile 'com.google.android.gms:play-services-auth:10.0.0'
compile 'com.google.android.gms:play-services-plus:10.0.0'
compile 'com.google.android.gms:play-services-identity:10.0.0'
compile 'com.google.android.gms:play-services-base:10.0.0'
compile 'com.google.android.gms:play-services-location:10.0.0'
compile 'com.google.android.gms:play-services-maps:10.0.0'
compile 'com.google.android.gms:play-services-gcm:10.0.0'

//Ken Burns Effect for Image Background
compile 'com.flaviofaria:kenburnsview:1.0.7'

//Material Search View
// compile 'com.miguelcatalan:materialsearchview:1.4.0'
compile project(':searchlibrary')

testCompile 'junit:junit:4.12'

}
apply plugin: 'com.google.gms.google-services'

build.gradle(项目级别)

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

buildscript {
repositories {
    jcenter()
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.2'
    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
}
}

allprojects {
repositories {
    jcenter()
    mavenCentral()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
4

5 回答 5

45

我在尝试为 android 培训课程添加对“com.android.support.constraint:constraint-layout:1.0.0-beta4”的依赖项时得到了它。

正如@Scott 所怀疑的那样,我设法克服了它,它确实涉及杰克。

通过它过去了:

  1. 注释掉添加的依赖项,jackOptions enable true 块和 compileOptions 块,我让它与 1.8 兼容。
  2. Sync/Clean/Rebuild Gradle(不管是什么,我还在学习)
  3. 取消注释添加的依赖项,再次同步/重建 gradle
  4. 取消注释 jackOptions 和 compileOptions 块,再次同步/重建 gradle

那时,它对我有用。

于 2016-12-06T22:51:02.693 回答
6

将其添加到 app build.gradle 或项目 build.module:

repositories {
    maven {
        url 'https://maven.google.com'
    }
}

当我添加'constraint-layout'依赖项时我遇到了这个问题,我在官方手册中找到了答案:https ://developer.android.com/training/constraint-layout/index.html 我认为它会对你有所帮助!

于 2017-06-12T16:42:52.850 回答
2

经过数小时的尝试,这对我有用->升级com.google.gms:google-services到最新版本。案例:添加

dataBinding {
   enabled = true
}

解决方案:在项目中的 gradle 类路径已更改

'com.google.gms:google-services:3.3.1'

'com.google.gms:google-services:4.0.1'(最新版本)

于 2018-07-13T10:38:26.563 回答
1

我升级了 gradle 和 google-play-services 库,但没有意识到您显然需要apply plugin: 'com.google.gms.google-services'在应用模块的build.gradle. 删除它为我解决了这个问题。

文档有点误导。删除apply plugin: 'com.google.gms.google-services'确实解决了这个问题,但是 Firebase 仍然需要这条线才能实际工作。在玩了一些之后,我注意到删除也dataBinding{enabled true}使错误消失了。但同样,这也不是解决方案。最后我不得不降级到com.android.tools.build:gradle:3.0.0- 这显然不是一个解决方案,因为你错过了例如 InstantRun,但至少它可以构建。整个问题是在更新到 Android Studio 3.1.2 之后引入的,所以我认为再次降级会解决它。

于 2018-05-22T11:36:11.343 回答
0

我也遇到过这个问题,我在 repositories{...} 中添加了 maven,并在模块的 build.gradle 的依赖项 {...} 中添加了依赖项。

我找到了原因,因为 Android Studio 无法从 maven 存储库加载依赖项。然后编译,我将jar复制到模块,同步,错误消失了。

总之,您可以在“C:\Users\wjj.gradle\caches\modules-2\files-2.1”检查依赖项是否加载。

我希望它可以帮助你!

于 2017-04-07T10:14:05.290 回答