无法生成签名APK - 重复项:javax/annotation/CheckForNull.class

问题描述:

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时才会出现错误。无法生成签名APK - 重复项:javax/annotation/CheckForNull.class

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:[email protected]') { 
     transitive = true; 
    } 
    compile('com.digits.sdk.android:digits:[email protected]') { 
     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。截图:

screenshot

这将是一个明智的解决这个问题?

+0

在我看来,你的'build.gradle'中至少有两个库,它们都具有'javax'作为它们的依赖(aka transitive dependency)。所以,你正在将两个不同版本的'javax'库导入到你的代码库中,这就是为什么你有两个双重类。只需查看所有依赖关系'./gradlew app:dependencies'并查找两个依赖于'javax'的库并排除其中一个依赖关系。 – azizbekian

请使用命令./gradlew clean进行gradle build的清理。

+0

已经做到了。没有帮助! –