【问题标题】:Unable to generate signed APK - duplicate entry: javax/annotation/CheckForNull.class无法生成签名的 APK - 重复条目:javax/annotation/CheckForNull.class
【发布时间】:2017-02-15 14:03:58
【问题描述】:
 Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: javax/annotation/CheckForNull.class 

以下是我的应用级 gradle 文件。我尝试删除 appcompat,支持 v4,但没有帮助。该应用程序运行正常,否则只有当我尝试生成签名的 apk 时才会出现错误。

buildsript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.1"

    defaultConfig {
        applicationId "com.aubergine.resqv1"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 10109
        versionName "1.2.0"
        // Enabling multidex support.
        multiDexEnabled true

        // Flag to tell aapt to keep the attribute ids around
        aaptOptions {
            additionalParameters "--no-version-vectors"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    mavenCentral()
    //For Mint bug reporter
    maven { url "https://mint.splunk.com/gradle/" }
    //For bug report and crash report
    maven { url "https://jitpack.io" }
    maven { url 'https://maven.fabric.io/public' }
    maven { url 'http://maven.localytics.com/public' }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    // libs for Material design
    // libs for dependency Injection
    // libs for Common font for Application
    //libs for calling api using Retrofit
    //For calling api using retrofit
    //For Mint bug reporter
    //For graph
    //libs for MaterialDesign EditText
    //For Circle Image
    //for universal image loader
    //For Number Picker in Estimated Time https://github.com/KasualBusiness/MaterialNumberPicker

    compile('com.crashlytics.sdk.android:crashlytics:2.6.6@aar') {
        transitive = true;
    }
    compile('com.digits.sdk.android:digits:2.0.5@aar') {
        transitive = true;
    }


    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:design:25.1.0'
    compile 'com.android.support:support-v4:25.1.0'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'uk.co.chrisjenx:calligraphy:2.1.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
    compile 'com.squareup.okhttp:okhttp:2.0.0'
    compile 'com.github.PhilJay:MPAndroidChart:v2.1.5'
    compile 'com.rengwuxian.materialedittext:library:2.1.4'
    compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
    compile 'de.hdodenhof:circleimageview:2.0.0'
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
    compile 'biz.kasual:materialnumberpicker:1.2.0'
    compile 'com.google.android.gms:play-services-analytics:10.0.1'
    compile 'com.google.firebase:firebase-appindexing:10.0.1'
    compile 'com.facebook.stetho:stetho:1.4.2'
    compile 'com.facebook.stetho:stetho-okhttp3:1.4.2'
    compile 'com.shawnlin:number-picker:2.4.1'
    compile 'com.google.android.gms:play-services-ads:10.0.1'
    compile 'com.localytics.android:library:4.2.+'
    compile 'com.google.firebase:firebase-core:10.0.1'
    compile 'com.google.firebase:firebase-messaging:10.0.1'
    testCompile 'junit:junit:4.12'
}

另外,有两个 CheckForNull 类,实际上在 jsr-305 中有重复的类。截图:

什么是解决这个问题的明智方法?

【问题讨论】:

  • 在我看来,您的build.gradle 中至少有两个库,它们都将javax 作为它们的依赖项(又名传递依赖项)。因此,您将两个不同版本的 javax lib 导入到您的代码库中,这就是为什么您有双重类。只需查看所有依赖项 ./gradlew app:dependencies 并找到两个具有 javax 依赖项的库并排除其中一个的依赖项。
  • 请参阅stackoverflow.com/a/22441017/192373 和此问题的其他答案
  • jsr305包含CheckForNull et al.两次没关系:一个是源(java),另一个是编译(类)。

标签: java android apk signed-apk


【解决方案1】:

请使用命令./gradlew clean 对 gradle 构建进行清理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-16
    • 2020-06-29
    • 1970-01-01
    相关资源
    最近更新 更多