简体   繁体   English

带有 Gradle 插件版本 3.6.1 和 Gradle 版本 5.6.4 的 Android Studio 3.6.1 不起作用

[英]Android Studio 3.6.1 with Gradle Plugin Version 3.6.1 and Gradle Version 5.6.4 not working

My application is working very well.我的应用程序运行良好。 I have just updated Android Studio 3.6.1 ,我刚刚更新了Android Studio 3.6.1

After updating Android Studio I got this dialog and I am going to update the version of the Gradle Plugin as below.更新 Android Studio 后,我收到此对话框,我将更新 Gradle 插件的版本,如下所示。

在此处输入图片说明

After updating, My application getting crashed and getting the following errors.更新后,我的应用程序崩溃并出现以下错误。

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/R$string;
        at com.google.android.gms.common.internal.StringResourceValueReader.<init>(Unknown Source:4)
        at com.google.firebase.FirebaseOptions.fromResource(com.google.firebase:firebase-common@@19.3.0:156)
        at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@19.3.0:244)
        at com.google.firebase.provider.FirebaseInitProvider.onCreate(com.google.firebase:firebase-common@@19.3.0:51)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1940)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1915)
        at com.google.firebase.provider.FirebaseInitProvider.attachInfo(com.google.firebase:firebase-common@@19.3.0:45)
        at android.app.ActivityThread.installProvider(ActivityThread.java:6770)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6317)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6232)
        at android.app.ActivityThread.access$1200(ActivityThread.java:237)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1792)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7078)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:974)

My Project Level build.gradle is:我的项目级build.gradle是:

buildscript {
    ext.objectboxVersion = '2.5.0'
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.1'
        classpath 'com.google.gms:google-services:4.3.3'

        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.2.1"
        classpath "io.objectbox:objectbox-gradle-plugin:$objectboxVersion"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        // Add dependency
        classpath 'io.fabric.tools:gradle:1.31.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

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

and My App Level build.gradle is:我的应用程序级别build.gradle是:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: "androidx.navigation.safeargs"

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.sohamerp.marsremedies"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    }
    dataBinding {
        enabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}

dependencies {
    //implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.navigation:navigation-fragment:2.2.1'
    implementation 'androidx.navigation:navigation-ui:2.2.1'

    implementation 'androidx.multidex:multidex:2.0.1'

    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.2.0-alpha05'

    implementation 'com.github.mukeshsolanki:android-otpview-pinview:2.1.0'

    implementation 'com.squareup.retrofit2:retrofit:2.7.1'
    implementation 'com.squareup.retrofit2:converter-gson:2.7.1'
    implementation 'com.squareup.okhttp3:logging-interceptor:4.4.0'

    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.google.firebase:firebase-core:17.2.2'
    implementation 'com.google.firebase:firebase-auth:19.2.0'
    implementation 'com.google.firebase:firebase-messaging:20.1.0'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'

    implementation 'com.github.bumptech.glide:glide:4.11.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
    annotationProcessor 'androidx.annotation:annotation:1.1.0'

    implementation "com.github.firdausmaulan:GlideSlider:1.5.1"

    implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'

    implementation 'org.greenrobot:eventbus:3.1.1'

    debugImplementation "io.objectbox:objectbox-android-objectbrowser:$objectboxVersion"
    releaseImplementation "io.objectbox:objectbox-android:$objectboxVersion"

    implementation 'com.intuit.sdp:sdp-android:1.0.6'
}
// apply the plugin after the dependencies block

apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.objectbox'

There is only one solution which I have tried is reverting back the version of Gradle which I have updated but what if I want to use the latest versions.我尝试过的只有一种解决方案是恢复我已更新的 Gradle 版本,但如果我想使用最新版本怎么办。

Update:更新:

One of my projects is working with some version of Android Studio and Gradle.我的一个项目正在使用某些版本的Android Studio 和 Gradle。 Here is Firebase SDK is different in both project so I am thinking that Firebase is Project.这是两个项目中的 Firebase SDK 不同,所以我认为 Firebase 是项目。

Any help?有什么帮助吗? What should I do?我该怎么办?

I have tried many ways to solve this problem as follow:我尝试了很多方法来解决这个问题,如下所示:

1st solution: I have tried the solution of Mayur Sojitra and it worked for one day.第一个解决方案:我尝试了Mayur Sojitra的解决方案,并且它工作了一天。 (Next day I got the same problem again.) (第二天我又遇到了同样的问题。)

2nd solution: I have tried to revert back with a lower version of Gradle that is 3.5.0 and It's working but I wanted to use the latest version only.第二种解决方案:我尝试使用 3.5.0 的较低版本的 Gradle 恢复,它可以工作,但我只想使用最新版本。 (Way to find a new solution) (寻找新解决方案的方法)

3rd solution: I am using firebase dependencies and I thought that error is coming because of Firebase version conflicts with Gradle so I have updated all the firebase repository.第 3 个解决方案:我正在使用 firebase 依赖项,我认为由于 Firebase 版本与 Gradle 冲突而出现错误,所以我更新了所有 firebase 存储库。 (May this is also working for you) (也许这也对你有用)

4th solution: I have used ObjectBox library so updated that version to the latest 2.5.1.第四个解决方案:我使用了ObjectBox库,因此将该版本更新到最新的 2.5.1。

5th solution: Finally I caught the problem that My Internet Connection is restricted (as per company rules) and My Gradle and other dependencies are not downloading successfully so I thought updating all dependencies and download it successfully will be the solution for this weird question.第 5 个解决方案:最后我发现我的 Internet 连接受到限制(根据公司规则)并且我的 Gradle 和其他依赖项没有成功下载的问题,所以我认为更新所有依赖项并成功下载将是这个奇怪问题的解决方案。

Do let me know If you have any questions or still get a problem.如果您有任何问题或仍有问题,请告诉我。

Thank you.谢谢你。

buildToolsVersion "29.0.2"

build.gradle删除这一行

It seems like you're mixing old fabric&crashlytics with new firebase&crashlytics.看起来您正在将旧的结构和崩溃与新的火力和崩溃混合在一起。 Try:尝试:

Project Level build.gradle :项目级build.gradle

buildscript {
    ext.objectboxVersion = '2.5.0'
    repositories {
        google()
        jcenter()
//        maven {
//            url 'https://maven.fabric.io/public'
//        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.1'
        classpath 'com.google.gms:google-services:4.3.3'

        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.2.1"
        classpath "io.objectbox:objectbox-gradle-plugin:$objectboxVersion"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        // Add dependency
//        classpath 'io.fabric.tools:gradle:1.31.0'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.1.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

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

App Level build.gradle:应用级 build.gradle:

apply plugin: 'com.android.application'
apply plugin: "androidx.navigation.safeargs"
//apply plugin: 'io.fabric'
apply plugin: 'com.google.firebase.crashlytics'

android {
    compileSdkVersion 29
//    buildToolsVersion "29.0.2"    // buildtools is now automatically determined, based on compileSDKVersion
    defaultConfig {
        applicationId "com.sohamerp.marsremedies"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    }
    dataBinding {
        enabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}

dependencies {
    //implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.navigation:navigation-fragment:2.2.1'
    implementation 'androidx.navigation:navigation-ui:2.2.1'

    implementation 'androidx.multidex:multidex:2.0.1'

    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.2.0-alpha05'

    implementation 'com.github.mukeshsolanki:android-otpview-pinview:2.1.0'

    implementation 'com.squareup.retrofit2:retrofit:2.7.1'
    implementation 'com.squareup.retrofit2:converter-gson:2.7.1'
    implementation 'com.squareup.okhttp3:logging-interceptor:4.4.0'

    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.google.firebase:firebase-core:17.2.2'
    implementation 'com.google.firebase:firebase-auth:19.2.0'
    implementation 'com.google.firebase:firebase-messaging:20.1.0'
//    implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
    implementation 'com.google.firebase:firebase-crashlytics:17.0.0'

    implementation 'com.github.bumptech.glide:glide:4.11.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
    annotationProcessor 'androidx.annotation:annotation:1.1.0'

    implementation "com.github.firdausmaulan:GlideSlider:1.5.1"

    implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'

    implementation 'org.greenrobot:eventbus:3.1.1'

    debugImplementation "io.objectbox:objectbox-android-objectbrowser:$objectboxVersion"
    releaseImplementation "io.objectbox:objectbox-android:$objectboxVersion"

    implementation 'com.intuit.sdp:sdp-android:1.0.6'
}
// apply the plugin after the dependencies block

apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.objectbox'

如果你还在看这个,我刚刚更新到 3.6.2,它在重启后立即做了一些与 firebase 相关的更新(虽然我的代码没有使用 firebase..)。

I ran into the same error.我遇到了同样的错误。 However, I succeeded in building in the following way.但是,我通过以下方式成功构建。

- classpath 'com.google.firebase:firebase-plugins:1.1.1'
+ classpath 'com.google.firebase:firebase-plugins:1.2.0'

Possible solution:可能的解决方案:

Upgrade the version of plugins in Top-level build.gradle .升级顶级build.gradle的插件版本。

Detail:细节:

I upgraded the Gradle version from 5.4.1 to 5.6.4 , and the plugin version from 3.5.3 to 3.6.2 , and then I encountered a problem that the class could not find.我将 Gradle 版本从5.4.1升级到5.6.4 ,插件版本从3.5.3升级到3.6.2 ,然后遇到了类找不到的问题。

I have used Realm in the project and the top-level build.gradle is:我在项目中使用了Realm ,顶层build.gradle是:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    /.../
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.2'
        classpath "io.realm:realm-gradle-plugin:5.8.0"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

This problem seems like some library/plugin does not process R classes in R.jar but in R.java after the Gradle plugin version greater than 3.6.0 .这个问题似乎有些库/插件不处理R.jar中的R类,但在 Gradle 插件版本大于3.6.0之后的R.java See here for detail.请参阅此处了解详细信息。

And the solution is to upgrade Realm to a newer version, for me is 6.0.2 .解决方案是将Realm升级到更新的版本,对我来说是6.0.2 See here for detail.请参阅此处了解详细信息。

    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.2'
        classpath "io.realm:realm-gradle-plugin:6.0.2" // <- modify
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }

gradle 5.6.4 having some sync problem . gradle 5.6.4 有一些同步问题。 go to the gradle-wrapper.properties and change the url to this转到 gradle-wrapper.properties 并将网址更改为此

distributionUrl=https://services.gradle.org/distributions/gradle-6.0-all.zip distributionUrl=https://services.gradle.org/distributions/gradle-6.0-all.zip

I tried many suggestions from stackoverflow(here), github forums etc. Checked gradle and gradle plugin versions if there is any compatibility problems.我尝试了来自 stackoverflow(here)、github 论坛等的许多建议。如果有任何兼容性问题,请检查 gradle 和 gradle 插件版本。 Only worked : I clean .idea and .gradle file, exit AndroidS, and I open my react native proj on Android studio and I did open from file choose android folder, after that waited android studio finish indexing(really waited this time) and press hammer icon for build and wait again patiently and build-run on simulator successfully.只工作:我清理 .idea 和 .gradle 文件,退出 AndroidS,我在 Android studio 上打开我的 React Native 项目,我从file打开,选择 android 文件夹,然后等待 android studio 完成索引(这次真的等了)并按构建的hammer图标并再次耐心等待并成功在模拟器上构建运行。

I didn't wait before, I guess I didn't imagine that Android studio takes so much time to index-run-build之前没等,估计没想到Android studio要花这么多时间index-run-build

I am sharing if somebody still stuck, key was waiting for me, good luck如果有人仍然卡住,我正在分享,钥匙在等我,祝你好运

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

相关问题 Gradle 插件 3.6.1 中的 Gradle 构建错误,分发 URL 版本 5.6.4 - Gradle Build Error in Gradle Plugin 3.6.1, Distribution URL version 5.6.4 "更新到 Gradle 5.6.4 和 Android Studio 3.6.1 后 nativeLibraryDir 显示为空" - nativeLibraryDir appears empty after updating to Gradle 5.6.4 and Android Studio 3.6.1 什么是 gradle 版本,应该与 3.6.1 android studio 一起使用 - What is gradle version which should be used with 3.6.1 android studio 我将 Android Studio 更新到最新版本 (3.6.1),现在找不到 Gradle 插件 - I updated the Android Studio to the latest version (3.6.1) and Gradle Plugin is not found now Android Studio 3.6.1 中的 Gradle 同步失败 - Gradle sync failed in Android studio 3.6.1 Android studio 3.6.1 gradle 同步太慢 - Android studio 3.6.1 gradle sync too slow 将 Android Studio 升级到 gradle 版本 5.6.4 时出错 - Error when upgrading Android Studio to gradle version 5.6.4 Gradle插件版本与Real Gradle版本Android Studio冲突 - Gradle plugin version conflicting with realm gradle version Android Studio Android Studio 3.6.3 Error: No cached version of com.android.tools.build:gradle:3.6.3 available for offline mode. Gradle 版本:5.6.4 - Android Studio 3.6.3 Error: No cached version of com.android.tools.build:gradle:3.6.3 available for offline mode. Gradle Version: 5.6.4 BuildConfig 在 Android Studio 3.6.1 中不起作用 - BuildConfig is not working in Android studio 3.6.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM