简体   繁体   English

gradle 插件更新后,Android Studio 无法构建我的应用程序

[英]Android studio unable to build my app after gradle plugin updated

I updated the Gradle plugin yesterday and now the android studio is not able to build my app.我昨天更新了 Gradle 插件,现在 android studio 无法构建我的应用程序。 The app shows the following error.该应用程序显示以下错误。

    ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve io.grpc:grpc-core:[1.16.1].
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve io.grpc:grpc-core:[1.16.1].
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve io.grpc:grpc-core:[1.16.1].
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve io.grpc:grpc-core:[1.16.1].
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve io.grpc:grpc-core:[1.16.1].
Show Details
Affected Modules: app


WARNING: API 'variant.getExternalNativeBuildTasks()' is obsolete and has been replaced with 'variant.getExternalNativeBuildProviders()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getExternalNativeBuildTasks(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.
Affected Modules: app

My app level build.gradle file looks like this:我的应用程序级 build.gradle 文件如下所示:

    apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.mvp1stockmeter"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding
            {
                enabled true
            }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation 'com.android.support:multidex:1.0.3'
    implementation 'org.jsoup:jsoup:1.11.3'

    implementation 'com.google.firebase:firebase-core:16.0.7'
    implementation 'com.google.firebase:firebase-firestore:18.0.0'

    implementation 'com.google.firebase:firebase-core:16.0.7'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
    implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
    implementation 'com.google.firebase:firebase-auth:16.1.0'
    //implementation 'com.facebook.android:facebook-android-sdk:4.x'

    implementation 'com.jjoe64:graphview:4.2.2'
}
apply plugin: 'com.google.gms.google-services'

My project level build.gradle file looks like this:我的项目级 build.gradle 文件如下所示:

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

buildscript {
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'io.fabric.tools:gradle:1.26.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.google.com/'
        }
    }
}

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

I searched this on StackOverflow and google as well.我也在 StackOverflow 和 google 上搜索过这个。 But did not find any information.但是没有找到任何资料。 Please help.请帮忙。 I am stuck here.我被困在这里。

I don't have a clue why this is happening, but it is happening since yesterday, March 21 2019. I think it is a problem in the maven repository?我不知道为什么会发生这种情况,但它从昨天,即 2019 年 3 月 21 日开始发生。我认为这是 Maven 存储库中的问题? Because the url where android studio is trying to get that library is down.因为 android studio 试图获取该库的 url 已关闭。

Anyway, the fix is to "manually" point AS to that missing dependency, adding this line into your build.gradle, inside dependencies{...}无论如何,解决方法是“手动”将 AS 指向缺少的依赖项,将此行添加到 build.gradle 中的依赖项{...}

implementation group: 'io.grpc', name: 'grpc-core', version: '1.16.1'

Then sync, then you can delete that line.然后同步,然后您可以删除该行。

Well, I hope someone can explain what happened.好吧,我希望有人能解释发生了什么。

将 mavenCentral() 添加到项目级 build.gradle 文件的 allprojects{} 部分已经为我解决了这个问题。

Adding mavenCentral() to buildScript{} section of project level build.gradle file has resolved this issue for me.将 mavenCentral() 添加到项目级 build.gradle 文件的 buildScript{} 部分已经为我解决了这个问题。 Thanks for your support.谢谢您的支持。

I had three build errors of the following type:我有以下类型的三个构建错误:

Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve io.grpc:grpc-core:[1.28.0].

As with many of these android studio related issues,与许多与 android studio 相关的问题一样,

File -> Invalidate Caches / Restart...

did the trick for me.帮我解决了这个问题。

删除这一行:- testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"...它对我有用

将 mavenCentral() 添加到您的 buildscripts->repositories 和 allprojects->repositories 并同步项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM