android - 无法签署发布 APK - :app:shrinkReleaseMultiDexComponents FAILED

标签 android gradle apk proguard

我正在尝试生成签名的 apk,但日志一直显示以下错误:

:app:compileReleaseJavaWithJavac
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:app:compileReleaseNdk UP-TO-DATE
:app:compileReleaseSources
:app:collectReleaseMultiDexComponents
:app:proguardRelease
Warning:com.google.android.gms.internal.zzac: can't find referenced class android.net.http.AndroidHttpClient
Warning:com.google.android.gms.internal.zzw: can't find referenced method 'void addHeader(java.lang.String,java.lang.String)' in program class com.google.android.gms.internal.zzw$zza
Warning:com.google.android.gms.internal.zzw$zza: can't find referenced method 'void setURI(java.net.URI)' in program class com.google.android.gms.internal.zzw$zza
Warning:com.ironsource.mobilcore.j: can't find referenced method 'void setLatestEventInfo(android.content.Context,java.lang.CharSequence,java.lang.CharSequence,android.app.PendingIntent)' in library class android.app.Notification
Warning:com.mopub.volley.toolbox.HttpClientStack: can't find referenced method 'void addHeader(java.lang.String,java.lang.String)' in program class com.mopub.volley.toolbox.HttpClientStack$HttpPatch
Warning:com.mopub.volley.toolbox.HttpClientStack$HttpPatch: can't find referenced method 'void setURI(java.net.URI)' in program class com.mopub.volley.toolbox.HttpClientStack$HttpPatch
Warning:com.mopub.volley.toolbox.Volley: can't find referenced class android.net.http.AndroidHttpClient
Warning:there were 4 unresolved references to classes or interfaces.
         You may need to add missing library jars or update their versions.
         If your code works fine without the missing classes, you can suppress
         the warnings with '-dontwarn' options.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning:there were 4 unresolved references to program class members.
         Your input classes appear to be inconsistent.
         You may need to recompile the code.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
Warning:there were 1 unresolved references to library class members.
         You probably need to update the library versions.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
Exception while processing task 
java.io.IOException: Please correct the above warnings first.
    at proguard.Initializer.execute(Initializer.java:473)
    at proguard.ProGuard.initialize(ProGuard.java:233)
    at proguard.ProGuard.execute(ProGuard.java:98)
    at proguard.gradle.ProGuardTask.proguard(ProGuardTask.java:1074)
    at com.android.build.gradle.tasks.AndroidProGuardTask.doMinification(AndroidProGuardTask.java:139)
    at com.android.build.gradle.tasks.AndroidProGuardTask$1.run(AndroidProGuardTask.java:115)
    at com.android.builder.tasks.Job.runTask(Job.java:48)
    at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41)
    at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:227)
    at java.lang.Thread.run(Thread.java:745)
:app:shrinkReleaseMultiDexComponents FAILED
Error:Execution failed for task ':app:shrinkReleaseMultiDexComponents'.
> java.io.IOException: The output jar [<project_path>\app\build\intermediates\multi-dex\release\componentClasses.jar] must be specified after an input jar, or it will be empty.

下面是我的应用级build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.my.app"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 25
        versionName "2.5"

        // Enabling multidex support.
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dexOptions {
        incremental true
        javaMaxHeapSize "2048M"
    }
}

repositories {
    mavenCentral()
    maven { url "https://jitpack.io" }
}

dependencies {
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile 'com.google.android.gms:play-services:8.1.0'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    compile 'com.facebook.android:facebook-android-sdk:4.2.0'
    compile 'me.dm7.barcodescanner:zxing:1.7.2'
    compile 'de.hdodenhof:circleimageview:1.3.0'
    compile 'com.scottyab:secure-preferences-lib:0.1.3'
    compile 'com.soundcloud.android:android-crop:1.0.0@aar'
    compile('com.afollestad.material-dialogs:core:0.8.1.0@aar') {
        transitive = true
    }
    compile('com.mopub:mopub-sdk:3.13.0@aar') {
        transitive = true
    }
    compile project(':android-support-v4-preferencefragment')
    compile project(':circular_progress_bar')
    compile files('libs/mobilecore_V1.1.jar')
    compile files('libs/libAdapterSDKMoPub.jar')
    compile files('libs/adcolony.jar')
}

还有我的顶级build.gradle:

// 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:1.3.0'

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

allprojects {
    repositories {
        jcenter()
    }
}

我尝试过其他版本的 gradle,例如 1.4.0-beta1'、1.4.0-beta21.3.1 仍然没有成功。

最佳答案

你的踪迹中有一些信息 --

Warning:there were 4 unresolved references to classes or interfaces. You may need to add missing library jars or update their versions. If your code works fine without the missing classes, you can suppress the warnings with '-dontwarn' options. (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)

至少部分问题是 AndroidHttpClient 在 API 23 中被删除,并且至少有一个库依赖于它。你有三个选择。

1) 您可以在 build.gradle 文件中包含以下内容。其中包括您的 apk 中的遗留库。参见 Apache HTTP Client Removal .

android {
    useLibrary 'org.apache.http.legacy'
}

2) 您可以降低目标并将 sdk 编译为 22 而不是 23。这应该允许您编译,或者至少解决 AndroidHttpClient 问题,直到库更新为不需要它。

3) 您可以将 -dontwarn 命令添加到您的 proguard 文件中以抑制警告以获得构建。如文档中所述,如果您不确定可以安全地忽略警告,这可能很危险。我不确定忽略因删除 HttpClient 和相关类而产生的警告是否安全。在 M 上运行时可能会导致构建不稳定,但对于 L 及以下版本应该是安全的,因为这些类存在于该 API 级别的设备上。

添加: 对于遇到同样问题的人,请记住,您必须将依赖项中的 builToolsVersioncom.android.support 降低到 22.0.1.

关于android - 无法签署发布 APK - :app:shrinkReleaseMultiDexComponents FAILED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32813843/

相关文章:

android - 如何动态添加按钮和总计?

android - 如何更改 Android 的默认帧缓冲区?

android - ListView 在图像上使用 AsynTask 滚动到底部

android - 这是什么意思: Failure [INSTALL_FAILED_CONTAINER_ERROR]?

android - Gradle assembleDebug 和 preDexDebug 即使对于新项目也会失败

android - 使用$ VARIABLE作为Jenkins中Gradle插件的构建任务

java - gradle:封装自定义dsl的最佳方法

android - 在 VS Xamarin 中导出 Apk 失败

android - 如何使用命令行生成apk文件?

android - APK未优化