【问题标题】:DUPLICATE ERROR: While generating signed APK for release in android重复错误:生成已签名的 APK 以在 android 中发布
【发布时间】:2017-10-13 04:27:47
【问题描述】:

我正在尝试生成 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
}

【问题讨论】:

    标签: android build.gradle signed-apk


    【解决方案1】:

    只需在你的 libs 文件夹中删除 android-support-v4.jar.. 删除它

    Clean-Rebuild-Run你的项目

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

    【讨论】:

    • 我从我的 libs 文件夹中删除了那个 jar,但现在几乎所有导入的 java 文件都出现构建错误。 @Nilesh
    • 尝试编译这个库compile 'com.android.support:design:26.0.0-alpha1'
    • 我在外部库中找到了该库。但是当我右键单击它时。我找不到编译选项。
    • @RakeshPolo 没有得到你
    • 正如你之前告诉我的,我正在尝试编译 lib,但不知道该怎么做。
    【解决方案2】:

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

    在您的情况下,请尝试使用 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'
    
      ...
    
    }
    

    尝试使用recent support library,即26.1.0从不在您的发行版 apk 中使用 alpha 版本。

    如果您的build.gradle 仅包含上述答案中的所有依赖项,则无需启用 multidex 并将其设置为 false 与 multiDexEnabled 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'
    
    
      }
    

    【讨论】:

    • 如果我删除配置并添加新的依赖项,我会收到以下错误。 Error:Could not find support-v4-26.0.+.jar (com.android.support:support-v4:26.0.0-alpha1). Searched in the following locations: file:/home/kumar/Android/Sdk/extras/android/m2repository/com/android/support/support-v4/26.0.0-alpha1/support-v4-26.0.0-alpha1-26.0.+.jar Please install the Android Support Repository from the Android SDK Manager. <a href="openAndroidSdkManager">Open Android SDK Manager</a>
    • 您需要添加 google maven。请看我关于 maven 的回答:stackoverflow.com/questions/45357000/…
    • 我也这样做了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 } }
    • 在 SDK 工具中,我安装了支持存储库下的所有内容。错误仍然存​​在。
    • 这很奇怪。你能在你的问题中附上你的 root build.gradle 吗?
    猜你喜欢
    • 2023-03-13
    • 2016-11-11
    • 1970-01-01
    • 2023-04-01
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 2020-08-02
    • 2019-12-25
    相关资源
    最近更新 更多