0

我正在尝试生成SignedAPK以将其部署在Play Store中,但出现以下错误。但是在构建为调试模式时,它工作得很好。

错误:

错误:

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

构建.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
}
4

2 回答 2

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. 切勿在您的发布 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'


  }
于 2017-10-13T04:58:01.883 回答
0

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

Clean-Rebuild-Run你的项目

如果这个android-support-v4.jar文件没有添加到build.gradle文件中。gradle无论如何,将其包含在构建中。

于 2017-10-13T04:32:11.613 回答