当前位置: 首页 > 知识库问答 >
问题:

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

淳于熙云
2023-03-14

我的申请很有效。我刚刚更新了Android Studio 3.6.1,

在更新Android Studio之后,我得到了这个对话框,我将更新Gradle插件的版本,如下所示。

更新后,我的应用程序崩溃,出现以下错误。

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)

我的项目级生成。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
}

我的应用程序级别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'

我尝试过的唯一解决方案是恢复我更新过的Gradle版本,但如果我想使用最新版本,该怎么办。

我的一个项目正在使用某些版本的Android Studio和Gradle。这是Firebase SDK在两个项目中都有所不同,所以我认为Firebase是Project。

有什么帮助吗?我该怎么办?

共有3个答案

申屠俊发
2023-03-14

你好像在混合旧布料

项目级构建。格拉德尔:

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
}

应用程序级生成。格拉德尔:

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'
司空实
2023-03-14
buildToolsVersion "29.0.2"

build.gradle中删除此行

司徒志强
2023-03-14

我尝试了以下多种方法来解决此问题:

第一种解决方案:我已经尝试了Mayur Sojitra的解决方案,并且成功了一天。(第二天,我又遇到了同样的问题。)

第二个解决方案:我曾尝试使用Gradle的较低版本3.5.0进行恢复,并且它正在运行,但我只想使用最新版本。(找到新解决方案的方法)

第三种解决方案:我使用的是firebase依赖项,我认为会出现错误,因为firebase版本与Gradle冲突,所以我更新了所有firebase存储库。(也许这对你也有用)

第四个解决方案:我使用了ObjectBox库,因此将该版本更新到最新的2.5.1。

第五个解决方案:最后我发现了我的Internet连接受到限制(根据公司规则)并且我的Gradle和其他依赖项无法成功下载的问题,所以我认为更新所有依赖项并成功下载将是这个奇怪问题的解决方案

如果您有任何问题或仍然有问题,请告诉我。

谢谢你。

 类似资料: