【问题标题】:ClassCastException while building signed Apk构建签名 Apk 时出现 ClassCastException
【发布时间】:2021-03-31 21:09:57
【问题描述】:

我的 gradle 依赖是

     repositories {
        google()
        mavenCentral()
//        maven { url "http://maven.ghostscript.com" }
        maven { url 'https://jitpack.io' }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

使用这些应用依赖

     buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }


    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    //implementation files('libs/aspose-slides-20.6-android.via.java.jar')
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'com.github.bumptech.glide:glide:4.11.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
    implementation 'commons-io:commons-io:20030203.000550'
    implementation "com.pdfview:pdfview-android:1.0.0"


    //implementation 'com.android.support:multidex:1.0.3'
    // https://github.com/googlesamples/easypermissions
//    implementation 'pub.devrel:easypermissions:1.1.0'
    implementation ('com.github.junrar:junrar:7.4.0') {
        ['org.apache.commons','commons-logging'].each {
            exclude group: "$it"
        }
    }

    implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
    // Because RxAndroid releases are few and far between, it is recommended you also
    // explicitly depend on RxJava's latest version for bug fixes and new features.
    // (see https://github.com/ReactiveX/RxJava/releases for latest 3.x.x version)
    implementation 'io.reactivex.rxjava3:rxjava:3.0.8'

//    implementation files('libs/itsrts_pptviewer.jar')
    implementation 'com.agrawalsuneet.androidlibs:dotsloader:1.4'
    implementation 'com.google.android.gms:play-services-ads:19.6.0'


    implementation 'org.apache.commons:commons-lang3:3.11'
    implementation files('libs/jxl.jar')
    implementation files('libs/aspose-words-17.2.0-android.jar')
    implementation "com.folioreader:folioreader:0.5.4"

}

创建发布签名的 Apk 时出现此错误,我该如何解决?删除 gradle 缓存以及使 Android Studio 失效并重新启动时无法解决这些错误。

java.lang.ClassCastException: com.android.tools.r8.s.b.C 无法转换为 com.android.tools.r8.s.b.B

com.android.tools.r8.CompilationFailedException: 编译未能完成,位置:Lorg/readium/r2/streamer/parser/epub/OPFParser;parseSpine(Lorg/readium/r2/shared/parser/xml/Node; Lorg/readium/r2/shared/Publication;)V,来源:C:\Users\Asif Malik.gradle\caches\transforms2\files2.1\202fad4fee5b15436e55e2114f613e17\jetified-r2streamerkotlin1.0.42runtime.jar:org/readium/r2/ streamer/parser/epub/OPFParser.class

com.android.tools.r8.s.b.C 无法转换为 com.android.tools.r8.s.b.B

Gradle 的依赖缓存可能已损坏(这有时会在网络连接超时后发生。)

重新下载依赖并同步项目(需要网络)

Gradle 构建过程(守护进程)的状态可能已损坏

【问题讨论】:

  • ** 我已经解决了这个问题 ** 删除 { shrinkResources true minifyEnabled true } 并添加 ** ` {signingConfig signingConfigs.debug useProguard true minifyEnabled false} **它工作正常对我来说,这个解决方案运行良好,删除创建的签名 apk 上的所有错误
  • Asif,关闭缩小 (minifyEnabled false) 显然是一种摆脱 ClassCastException 的方法,就像在 R8 编译中发生的那样。如果可能的话,您能否在issuetracker.google.com/issues/new?component=326788 上打开一个问题,提供有关您看到此内容的 Android Studio 版本的更多信息?
  • @sgjesse 是的,我解决了这个问题,我使用'useProguard true minifyEnabled false'

标签: java android-studio signed-apk gradle-dependencies


【解决方案1】:

这是http://issuetracker.google.com/175132220 中跟踪的 R8 问题。

【讨论】:

  • 来自链接:此问题已在 r8 版本 2.1.87 中修复。遗憾的是,它没有与 Android Studio 4.1.3 捆绑,因此除非新版本发布,否则您可以通过将其显式添加到 build.gradle 来使用解决方法。
猜你喜欢
  • 1970-01-01
  • 2019-07-14
  • 1970-01-01
  • 1970-01-01
  • 2018-09-11
  • 2023-03-26
  • 2017-05-10
  • 2021-08-29
  • 1970-01-01
相关资源
最近更新 更多