将 Gradle 从 7.4.2 升级到 Gradle 8.0.0 在发布应用程序时出现错误 - java.lang.ClassCastException

问题描述 投票:0回答:1

我最近将 Android Studio 升级到 Flamingo,并将 Gradle 从 7.4.2 升级到 8.0.0。在 7.4.2. 版本中一切正常

当我使用 Gradle 8.0.0 生成签名的 APK 时,它给我一个运行时错误

java.lang.ClassCastException
.

我已经尝试了很多解决方案,比如为 Retrofit、Okio、OkHttp 等添加 Proguard 规则,但它仍然给我这样的错误。

注意:当我从 8.0.0 降级到 7.4.2 时,它正在工作。

所以任何人都可以帮我找出 AGP 8.0.0 的问题

build.gradle(应用程序)

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-kapt'
    id 'kotlin-parcelize'
    id 'com.google.dagger.hilt.android'
    id 'com.google.gms.google-services'
    id 'com.google.firebase.crashlytics'
}


android {
    
    compileSdk 33

    defaultConfig {
        
        minSdk 24
        targetSdk 33
        versionCode 22
        versionName "1.0.16"
        multiDexEnabled true

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        /*vectorDrawables {
            useSupportLibrary true
        }*/

        def localPropertiesFile = rootProject.file("local.properties")
        def localProperties = new Properties()
        localProperties.load(new FileInputStream(localPropertiesFile))
        buildConfigField "String", "API_KEY", localProperties['API_KEY']



    }

    
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = '17'
    }
    buildFeatures {
        compose true
        viewBinding = true
    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.4.2'
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
    bundle {
        language {
            enableSplit = false
        }
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.10.0'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.8.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.multidex:multidex:2.0.1'

    
    implementation 'com.google.accompanist:accompanist-permissions:0.24.11-rc'
    implementation 'com.google.accompanist:accompanist-webview:0.24.11-rc'
    implementation 'com.google.accompanist:accompanist-pager:0.24.13-rc'
    implementation "com.google.accompanist:accompanist-pager-indicators:0.24.13-rc"
    implementation "com.google.accompanist:accompanist-drawablepainter:0.25.1"
    implementation "com.google.accompanist:accompanist-flowlayout:0.31.0-alpha"


   
    implementation 'androidx.activity:activity-compose:1.7.1'
    implementation platform('androidx.compose:compose-bom:2022.10.00')
    implementation 'androidx.compose.ui:ui'
    implementation 'androidx.compose.ui:ui-graphics'
    implementation 'androidx.compose.ui:ui-tooling-preview'
    implementation 'androidx.compose.material:material'
//    implementation 'androidx.compose.material3:material3'
    implementation "androidx.navigation:navigation-compose:2.5.3"
    implementation 'com.google.firebase:protolite-well-known-types:18.0.0'
    implementation "androidx.compose.ui:ui-viewbinding"
    implementation project(path: ':pdfviewer')

  
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4"

    
    implementation "com.google.dagger:hilt-android:2.45"
    debugImplementation "androidx.compose.ui:ui-test-manifest"
    kapt "com.google.dagger:hilt-compiler:2.45"
    kapt "androidx.hilt:hilt-compiler:1.0.0"
    implementation 'androidx.hilt:hilt-navigation-compose:1.0.0'

  
    implementation "androidx.activity:activity-ktx:1.7.1"

  
    implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.6.1"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1"
    implementation "androidx.lifecycle:lifecycle-process:2.6.1"
    kapt "androidx.lifecycle:lifecycle-compiler:2.6.1"

    /* *****************************************************
       **** Retrofit2
       ****************************************************** */
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation "com.squareup.okhttp3:okhttp:4.9.0"
    implementation "com.squareup.okhttp3:logging-interceptor:4.9.0"
    implementation 'com.squareup.retrofit2:converter-moshi:2.9.0'

   
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'

   
    implementation "androidx.room:room-runtime:2.5.1"
    kapt "androidx.room:room-compiler:2.5.1"

    
    implementation "androidx.room:room-ktx:2.5.1"

   
    implementation 'androidx.core:core-splashscreen:1.0.1'

    
    def billing_version = "5.2.0"
    implementation "com.android.billingclient:billing:$billing_version"
    implementation "com.android.billingclient:billing-ktx:$billing_version"
    implementation 'com.google.firebase:firebase-crashlytics-buildtools:2.9.5'

   
    implementation platform('com.google.firebase:firebase-bom:31.1.0')
    implementation 'com.google.firebase:firebase-config-ktx'
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.google.firebase:firebase-crashlytics-ktx'
    implementation 'com.google.firebase:firebase-messaging-ktx'
    implementation 'com.google.android.gms:play-services-ads:22.0.0'

   
    implementation 'com.airbnb.android:lottie-compose:4.0.0'


}

kapt {
    correctErrorTypes true
}

项目 Gradle 文件

buildscript {
    ext {
        compose_ui_version = '1.5.0-alpha02'
        kotlin_version = '1.8.10'
    }
        dependencies {
            // Add this line
            classpath 'com.google.gms:google-services:4.3.15'
            classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.5'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    repositories {
        mavenCentral()
    }
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '8.0.0' apply false
    id 'com.android.library' version '8.0.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
    id 'com.google.dagger.hilt.android' version '2.44' apply false
}
java kotlin gradle android-gradle-plugin gradle-plugin
1个回答
0
投票

很可能您使用的插件与 Gradle 8.0 不兼容。如果没有必要升级到 Gradle 8.0,我建议您降级回 7.4.2,直到这些插件变得兼容。另一种方法是检查不兼容的插件,并在可以添加时尝试替换它们。

© www.soinside.com 2019 - 2024. All rights reserved.