DUPLICATE ERROR:在android中生成签名APK以供发布

时间:2017-10-13 04:27:48

标签: android build.gradle signed-apk

我正在尝试生成 SignedAPK ,以便在 Play商店中部署它,但我收到以下错误。但是在构建为调试模式时,它可以正常工作。

错误:

错误:

Execution failed for task ':app:transformClassesWithJarMergingForRelease'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/hardware/fingerprint/FingerprintManagerCompat$Api23FingerprintManagerCompatImpl$1.class

的build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
    applicationId "com.meru.parryreward"
    minSdkVersion 16
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
lintOptions {
    checkReleaseBuilds false
    // Or, if you prefer, you can continue to check for errors in release builds,
    // but continue the build even when errors are found:
    abortOnError false
}
configurations {

    all*.exclude group: 'com.android.support', module: 'support-annotations'
    all*.exclude group: 'com.android.support', module: 'support-v7'
    all*.exclude group: 'com.android.support', module: 'support-v4'


    //  all*.exclude group: 'com.android.support', module: 'support-vector-drawable'


  }
dexOptions {
    javaMaxHeapSize "4g"
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
testCompile 'junit:junit:4.12'
compile files('libs/android-support-v4.jar')

}

我已经尝试了几乎所有建议的SO但无法解决此错误。我是初学者,提前谢谢。

编辑:

 // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
    jcenter()
    maven {
        url "https://maven.google.com"
    }
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
   }
}

allprojects {
repositories {
    jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

2 个答案:

答案 0 :(得分:0)

只需删除libs文件夹中的android-support-v4.jar即可将其删除

Clean-Rebuild-Run 您的项目

  

如果android-support-v4.jar文件中未添加此build.gradle文件。 gradle无论如何都将它包含在构建中。

答案 1 :(得分:0)

这可能是因为您的支持库版本存在冲突。您需要使用相同的支持库版本。

在您的情况下,尝试使用maven中的support-v4库而不是本地jar:

dependencies {
  ...

  compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
  compile 'com.android.support:support-v4::26.0.0-alpha1'

  ...

}

尝试使用26.1.0 build.gradle从不在您的发布版本中使用alpha版本。

如果您的multiDexEnabled false仅包含所有依赖项作为上述答案,则无需启用multidex并使用configurations { all*.exclude group: 'com.android.support', module: 'support-annotations' all*.exclude group: 'com.android.support', module: 'support-v7' all*.exclude group: 'com.android.support', module: 'support-v4' // all*.exclude group: 'com.android.support', module: 'support-vector-drawable' } 将其设置为false。另外,请尝试删除其中的以下代码:

{{1}}