错误构建签名apk:超出主要Dex容量

时间:2017-08-28 07:55:19

标签: android build dex

我可以在调试模式下成功运行我的应用程序但是当我尝试生成已签名的apk时,我收到以下错误:

Information:Gradle tasks [:app:assembleRelease]
Warning:bolts.AggregateException: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.amazonaws.mobileconnectors.pinpoint.analytics.Session: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.amazonaws.mobileconnectors.pinpoint.targeting.TargetingClient: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.amazonaws.services.sns.util.SignatureChecker: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.bumptech.glide.load.engine.cache.SafeKeyGenerator: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.bumptech.glide.signature.ApplicationVersionSignature: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.facebook.accountkit.internal.ConsoleLogger: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.facebook.common.internal.Throwables: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.facebook.common.logging.FLogDefaultLoggingDelegate: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.facebook.imageutils.WebpUtil: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.facebook.internal.Logger: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.accountshelper.service.WorkerService: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.activity.AlbumPage: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.activity.ArtistPage: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.activity.GenreSelection: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.activity.Home: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.activity.NilandPlayer: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.activity.PlaylistActivity: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.activity.PlaylistTracks: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.activity.RadioPlayer: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.activity.SeriesActivity: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.activity.Splash: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.activity.TrackPlayer: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.activity.UserInfo: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.activity.VideoPlayer: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.dialog.CreateCollectionDialog: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.dialog.PlaylistEditDialog: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.dialog.SurveyDialog: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.fragment.AlbumsFragment: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.fragment.ArtistsFragment: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.fragment.Discover: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.fragment.FMRadio: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.fragment.GenresFragment: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.fragment.PlaylistOverview$PlaylistTrackDialog: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.fragment.SongsFragment: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.service.DownloadService: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.service.FetcherService: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.service.LoaderService: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.service.LocalMusicService: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.service.MusicService: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.service.StartUpService: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.utils.DownloadUtil: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.radioafrica.music.utils.FeaturedFavoritesUtil: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:com.thin.downloadmanager.DownloadDispatcher: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:org.apache.commons.lang3.exception.ExceptionUtils: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:uk.co.chrisjenx.calligraphy.ReflectionUtils: can't find referenced class com.google.devtools.build.android.desugar.runtime.ThrowableExtension
Warning:there were 93 unresolved references to classes or interfaces.
Error:Execution failed for task ':app:transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Too many classes in --main-dex-list, main dex capacity exceeded
Information:BUILD FAILED in 3m 22s
Information:1 error
Information:47 warnings
Information:See complete output in console

我的Application课程延长了MultidexApplication,我正在使用v1.0.2图书馆的Multidex

以下是我的gradle文件:

buildscript {
    repositories {
        mavenCentral();
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.24.1'
        classpath "com.newrelic.agent.android:agent-gradle-plugin:5.9.0"
    }
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'
apply plugin: 'newrelic'

repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }
    maven { url "http://dl.bintray.com/glomadrian/maven" }
   }

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        applicationId "com.android.app"
        minSdkVersion 19
        targetSdkVersion 26
        renderscriptTargetApi 20
        renderscriptSupportModeEnabled true
        versionCode 75
        versionName "0.9.9"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true

        multiDexKeepProguard file("proguard.multidex.config")
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', 'proguard-fresco.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile('io.fabric.sdk.android:fabric:1.3.16@aar') {
        transitive = true;
    }
    compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') {
        transitive = true;
    }
    compile 'com.newrelic.agent.android:android-agent:5.9.0'
    compile 'com.android.support:multidex:1.0.2'
    compile 'com.android.support:cardview-v7:26.0.1'
    compile 'com.android.support:recyclerview-v7:26.0.1'
    compile 'com.android.support:palette-v7:26.0.1'
    compile 'com.android.support:design:26.0.1'
    compile 'com.google.code.gson:gson:2.8.1'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'de.hdodenhof:circleimageview:1.3.0'
    compile 'jp.wasabeef:glide-transformations:2.0.2'
    compile 'com.google.android.exoplayer:exoplayer:r2.3.1'
    compile 'uk.co.chrisjenx:calligraphy:2.1.0'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'com.google.firebase:firebase-core:11.2.0'
    compile 'io.realm:android-adapters:2.1.0'
    compile 'org.parceler:parceler-api:1.1.6'
    compile 'com.jakewharton:butterknife:8.4.0'
    compile 'com.andrognito.kerningview:kerningview:1.0.0'
    compile 'com.flurry.android:analytics:6.4.2'
    compile 'com.amazonaws:aws-android-sdk-core:2.3.9'
    compile 'com.amazonaws:aws-android-sdk-pinpoint:2.3.9'
    compile 'com.amazonaws:aws-android-sdk-sns:2.3.9'
    compile 'com.google.android.gms:play-services-gcm:11.2.0'
    compile 'com.wdullaer:materialdatetimepicker:3.1.3'
    testCompile 'junit:junit:4.12'
    annotationProcessor 'org.parceler:parceler:1.1.5'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
    compile "com.mixpanel.android:mixpanel-android:5.0.2"
    compile 'com.mani:ThinDownloadManager:1.3.0'
    compile 'com.google.android:flexbox:0.3.0-alpha3'
    compile 'com.airbnb:deeplinkdispatch:3.1.0'
    annotationProcessor 'com.airbnb:deeplinkdispatch-processor:3.1.0'
    compile 'com.facebook.fresco:fresco:1.5.0'
}

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

我的计划规则如下:

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/kombo/Android/Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}
-keepattributes Exceptions, Signature, InnerClasses
-include ../proguard-com.twitter.sdk.android.twitter.txt
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-dontwarn com.squareup.okhttp.**
-dontwarn okio.**
-dontwarn com.android.support.**
-dontwarn android.support.**
-keepattributes Exceptions, Signature, InnerClasses, LineNumberTable
-keep class com.google.code.gson.**
-keep class com.github.ksoichiro.**
-keep class org.jsoup.**
-keep class com.mcxiaoke.volley.**
-keep class de.hdodenhof.**
-keep class jp.co.cyberagent.android.gpuimage.**
-keep class com.ms-square.**
-keep class com.nineoldandroids.**
-keep class jp.wasabeef.**
-keep class com.facebook.** { *; }
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keep class io.realm.annotations.RealmModule
-keep @io.realm.annotations.RealmModule class *
-keep class io.realm.internal.Keep
-keep @io.realm.internal.Keep class * { *; }
-dontwarn javax.**
-dontwarn io.realm.**
-keepattributes Signature
-keepattributes Exceptions
-keepclassmembers class ** {
    @org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}
-keep public class * {
    public protected *;
}

-keepclassmembernames class * {
    java.lang.Class class$(java.lang.String);
    java.lang.Class class$(java.lang.String, boolean);
}

-keepclasseswithmembernames,includedescriptorclasses class * {
    native <methods>;
}
-assumenosideeffects class android.util.Log {
    public static *** d(...);
    public static *** v(...);
    public static *** e(...);
    public static *** i(...);
}
-keepclasseswithmembernames class * {
    native <methods>;
}
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
# rxjava
-keep class rx.schedulers.Schedulers {
    public static <methods>;
}
-keep class rx.schedulers.ImmediateScheduler {
    public <methods>;
}
-keep class rx.schedulers.TestScheduler {
    public <methods>;
}
-keep class rx.schedulers.Schedulers {
    public static ** test();
}
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
    long producerIndex;
    long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
    long producerNode;
    long consumerNode;
}
-dontwarn java.lang.invoke.*
-keep class com.flurry.** { *; }
-dontwarn com.flurry.**
-keepattributes *Annotation*,EnclosingMethod,Signature
#-keepclasseswithmembers class * {
#    public (android.content.Context, android.util.AttributeSet, int);
#}
# Class names are needed in reflection
-keepnames class com.amazonaws.**
# Request handlers defined in request.handlers
-keep class com.amazonaws.services.**.*Handler
# The following are referenced but aren't required to run
-dontwarn com.fasterxml.jackson.**
-dontwarn org.apache.commons.logging.**
# Android 6.0 release removes support for the Apache HTTP client
-dontwarn org.apache.http.**
# The SDK has several references of Apache HTTP client
-dontwarn com.amazonaws.http.**
-dontwarn com.amazonaws.metrics.**
-keep class com.newrelic.** { *; }
-dontwarn com.newrelic.**
-keepattributes Exceptions, Signature, InnerClasses, LineNumberTable
-dontwarn java.lang.invoke.*
-dontwarn **$$Lambda$*
-dontwarn com.mixpanel.**
-keep class com.airbnb.deeplinkdispatch.** { *; }
-keepclasseswithmembers class * {
     @com.airbnb.deeplinkdispatch.DeepLink <methods>;
}
-ignorewarnings
-keep class * {
    public private *;
}
## Platform calls Class.forName on types which do not exist on Android to determine platform.
#-dontnote retrofit2.Platform
## Platform used when running on Java 8 VMs. Will not be used at runtime.
#-dontwarn retrofit2.Platform$Java8

1 个答案:

答案 0 :(得分:0)

我会尝试添加以下规则:

-keep class com.google.devtools.build.android.desugar.runtime.ThrowableExtension

另外,请关注this other SO question,因为它也可能相关(影响Gradle插件3.0测试版1和测试版3,测试版2不受影响)。

最后,如果应用程序编译但崩溃,您可以使用Android Studio 3.0 APK分析器来诊断它。在AS 3.0中,可以选择加载ProGuard映射文件,以查看ProGuard对您的APK所做的更改。

请参阅此blog postthis video(大约5分钟)。