【问题标题】:Can't generate signed apk but it works fine无法生成签名的 apk,但它工作正常
【发布时间】:2017-05-25 06:25:52
【问题描述】:

我可以运行应用程序并且可以使用它,但我无法生成签名的 apk。以下是仅在某些设备上运行的日志和调试 apk。

错误:任务执行失败 ':app:transformClassesWithJarMergingForRelease'.com.android.build.api.transform.TransformException: java.util.zip.ZipException:重复条目: com/google/gson/annotations/Expose.class

这是我的 app.gradle。

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

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

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


android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'
    compileOptions.encoding = 'UTF-8'
    signingConfigs {

    }
    repositories {
        //jcenter()
        mavenCentral()
        maven {
            url 'http://repo.brightcove.com/releases'
        }
    }

    defaultConfig {
        applicationId "com.asd.asd"
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        manifestPlaceholders = [partner: "asd"]
        multiDexEnabled = true

    }

    dexOptions {
        incremental true
        javaMaxHeapSize "4g"
    }

    buildTypes {
        debug {
            buildConfigField 'boolean', 'IS_ENABLE_ADS', 'true'
            signingConfig signingConfigs.debug
            debuggable true
        }

    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'

    compile(name: 'MfsAndroidLibrary', ext: 'aar')
    compile 'com.android.support:appcompat-v7:25.1.1'
    compile 'com.android.support:design:25.1.1'
    compile 'com.android.support:cardview-v7:25.1.1'
    compile 'com.android.support:recyclerview-v7:25.1.1'
    compile 'com.android.support:percent:25.1.1'
    //compile 'com.android.support:design:22.2.0'
    compile files('libs/gson-2.2.4.jar')
    compile 'com.facebook.android:facebook-android-sdk:4.17.0'

    compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
        transitive = true;
    }
    compile 'com.afollestad.material-dialogs:commons:0.9.3.0'
    compile 'com.brightcove.player:exoplayer:4.+'
    compile 'com.google.android.gms:play-services-gcm:10.0.1'
    compile 'com.google.android.gms:play-services-location:10.0.1'
    compile 'com.useinsider:insider:6.0.8'

    compile 'com.google.android.gms:play-services-maps:10.0.1'
    compile 'com.pitt.fresh.library:freshdownloadview:1.0'

    //compile 'cn.pedant.sweetalert:library:1.3'

    // compile 'com.tkurimura:flickabledialog:0.9.0'

    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'org.jetbrains:annotations-java5:15.0'
    compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar'
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    compile 'com.google.android.gms:play-services-analytics:10.0.1'
    compile 'org.jsoup:jsoup:1.7.3'
    compile 'com.afollestad:sectioned-recyclerview:0.2.3'
    compile 'com.tonicartos:superslim:0.4.13'
    //for select birthday

    compile 'com.github.flavienlaurent.datetimepicker:library:0.0.2'

    //image libraries
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.makeramen:roundedimageview:2.3.0'

    compile 'com.google.android.gms:play-services-ads:10.0.1'

    compile 'com.useinsider:insider:6.1.7'

    compile 'com.wang.avi:library:1.0.2'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'io.card:android-sdk:5.3.0'

    compile 'com.bkm.bexandroidsdk:bexandroidsdk:1.1.2'

}
apply plugin: 'com.google.gms.google-services'

和根目录

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

buildscript {
    repositories {
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'com.google.gms:google-services:3.0.0'

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

allprojects {
    repositories {
        jcenter()

        flatDir{

            dirs 'libs'
        }
        maven { url "http://mobile.useinsider.com" }
        maven { url 'https://dl.bintray.com/bkmexpress/maven' }
        maven {
            url "https://jitpack.io"
        }
    }
}

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

【问题讨论】:

  • 核心问题是您的某些依赖项使用了与2.2.4 不同版本的gson。您必须从该依赖项中找到该依赖项和 exclude module: 'gson'
  • 我在外部库中找到了 gson 2.7,但删除时出现了 sunsertificationexception。
  • 不,不要从外部库中删除它。您可以这样做 compile('lib using gson 2.7') { exclude module: 'gson' } 或只需下载 gson 2.7 jar 并替换 2.2.4mvnrepository.com/artifact/com.google.code.gson/gson/2.7

标签: android exception signed-apk gson


【解决方案1】:

我删除了这一行

 compile files('libs/gson-2.2.4.jar')

添加了这段代码,它可以工作

compile ('com.google.code.gson:gson:2.7'){
        transitive = true;
        exclude module: 'gson'
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-15
    • 1970-01-01
    • 2017-04-05
    • 1970-01-01
    相关资源
    最近更新 更多