Proguard 在构建发布 apk 时导致错误
Posted
技术标签:
【中文标题】Proguard 在构建发布 apk 时导致错误【英文标题】:Proguard causing error while building release apk 【发布时间】:2017-10-16 20:13:54 【问题描述】:Note: there were 1188 duplicate class definitions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
Initializing...
Note: the configuration refers to the unknown class 'rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef'
Note: the configuration refers to the unknown class 'rx.internal.util.atomic.LinkedQueueNode'
Note: the configuration refers to the unknown class 'rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef'
Note: the configuration refers to the unknown class 'rx.internal.util.atomic.LinkedQueueNode'
Note: the configuration refers to the unknown class 'dagger.internal.Binding'
Maybe you meant the fully qualified name 'com.sun.xml.internal.ws.wsdl.writer.document.Binding'?
Maybe you meant the fully qualified name 'com.sun.xml.internal.ws.wsdl.writer.document.http.Binding'?
Maybe you meant the fully qualified name 'dagger.internal.codegen.Binding'?
Maybe you meant the fully qualified name 'javax.naming.Binding'?
Maybe you meant the fully qualified name 'javax.xml.ws.Binding'?
Maybe you meant the fully qualified name 'org.eclipse.jdt.internal.compiler.lookup.Binding'?
Maybe you meant the fully qualified name 'org.omg.CosNaming.Binding'?
Note: the configuration refers to the unknown class 'dagger.internal.ModuleAdapter'
Note: the configuration refers to the unknown class 'dagger.internal.StaticInjection'
Note: the configuration refers to the unknown class 'Object'
Maybe you meant the fully qualified name 'java.lang.Object'?
Maybe you meant the fully qualified name 'org.omg.CORBA.Object'?
Note: the configuration refers to the unknown class 'org.greenrobot.eventbus.Subscribe'
Maybe you meant the fully qualified name 'com.squareup.otto.Subscribe'?
Maybe you meant the fully qualified name 'com.google.common.eventbus.Subscribe'?
Note: the configuration refers to the unknown class 'org.greenrobot.eventbus.ThreadMode'
Note: the configuration refers to the unknown class 'org.greenrobot.eventbus.util.ThrowableFailureEvent'
Note: the configuration refers to the unknown class 'com.google.android.gms.location.LocationServices'
Note: the configuration refers to the unknown class 'com.abed.hexagonrecyclerview.view.HorizontallyAdaptableHexagonImageView'
Note: the configuration refers to the unknown class 'com.abed.hexagonrecyclerview.view.VerticallyAdaptableHexagonImageView'
Note: the configuration refers to the unknown class 'com.facebook.drawee.view.SimpleDraweeView'
Warning: library class dagger.producers.monitoring.internal.Monitors$1 extends or implements program class javax.inject.Provider
Note: bo.app.aw: can't find dynamically referenced class com.amazon.device.messaging.ADM
Note: com.google.android.exoplayer.extractor.ExtractorSampleSource: can't find dynamically referenced class com.google.android.exoplayer.ext.flac.FlacExtractor
Note: com.google.android.gms.internal.zzast: can't find dynamically referenced class android.os.SystemProperties
Note: com.google.android.youtube.player.internal.aa: can't find dynamically referenced class com.google.android.youtube.api.locallylinked.LocallyLinkedFactory
Note: com.squareup.okhttp.internal.Platform: can't find dynamically referenced class com.android.org.conscrypt.SSLParametersImpl
Note: com.squareup.okhttp.internal.Platform: can't find dynamically referenced class org.apache.harmony.xnet.provider.jsse.SSLParametersImpl
Note: com.squareup.okhttp.internal.Platform: can't find dynamically referenced class sun.security.ssl.SSLContextImpl
Note: okhttp3.internal.platform.AndroidPlatform: can't find dynamically referenced class com.android.org.conscrypt.SSLParametersImpl
Note: okhttp3.internal.platform.AndroidPlatform: can't find dynamically referenced class org.apache.harmony.xnet.provider.jsse.SSLParametersImpl
Note: okhttp3.internal.platform.AndroidPlatform$CloseGuard: can't find dynamically referenced class dalvik.system.CloseGuard
Note: okhttp3.internal.platform.Platform: can't find dynamically referenced class sun.security.ssl.SSLContextImpl
Note: com.google.android.gms.dynamite.DynamiteModule accesses a declared field 'MODULE_ID' dynamically
Maybe this is program field 'com.google.android.gms.dynamite.descriptors.com.google.android.gms.flags.ModuleDescriptor java.lang.String MODULE_ID; '
Note: com.google.android.gms.dynamite.DynamiteModule accesses a declared field 'MODULE_VERSION' dynamically
Maybe this is program field 'com.google.android.gms.dynamite.descriptors.com.google.android.gms.flags.ModuleDescriptor int MODULE_VERSION; '
Note: com.google.android.gms.dynamite.DynamiteModule accesses a declared field 'sClassLoader' dynamically
Maybe this is program field 'com.google.android.gms.dynamite.DynamiteModule$DynamiteLoaderClassLoader java.lang.ClassLoader sClassLoader; '
Note: com.google.gson.internal.UnsafeAllocator accesses a declared field 'theUnsafe' dynamically
Note: the configuration explicitly specifies 'sun.misc.Unsafe' to keep library class 'sun.misc.Unsafe'
Note: the configuration explicitly specifies 'org.xmlpull.v1.**' to keep library class 'org.xmlpull.v1.XmlPullParser'
Note: the configuration explicitly specifies 'org.xmlpull.v1.**' to keep library class 'org.xmlpull.v1.XmlPullParserException'
Note: the configuration explicitly specifies 'org.xmlpull.v1.**' to keep library class 'org.xmlpull.v1.XmlPullParserFactory'
Note: the configuration explicitly specifies 'org.xmlpull.v1.**' to keep library class 'org.xmlpull.v1.XmlSerializer'
Note: there were 15 references to unknown classes.
You should check your configuration for typos.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unknownclass)
Note: there were 5 library classes explicitly being kept.
You don't need to keep library classes; they are already left unchanged.
(http://proguard.sourceforge.net/manual/troubleshooting.html#libraryclass)
Note: there were 11 unresolved dynamic references to classes or interfaces.
You should check if you need to specify additional program jars.
(http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass)
Note: there were 4 accesses to class members by means of introspection.
You should consider explicitly keeping the mentioned class members
(using '-keep' or '-keepclassmembers').
(http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclassmember)
Warning: there were 1 instances of library classes depending on program classes.
You must avoid such dependencies, since the program classes will
be processed, while the library classes will remain unchanged.
(http://proguard.sourceforge.net/manual/troubleshooting.html#dependency)
Warning: Exception while processing task java.io.IOException: Please correct the above warnings first.
:app:transformClassesAndResourcesWithProguardForRelease FAILED
:app:transformClassesAndResourcesWithProguardForRelease (Thread[Daemon worker Thread 3,5,main]) completed. Took 4.602 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> Job failed, see logs for details
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.
BUILD FAILED
Total time: 7.685 secs
Stopped 0 worker daemon(s).
【问题讨论】:
执行此操作时出错 -> 读取库 jar [/Users/harsh/Development/sdk/platforms/android-25/optional/org.apache.http.legacy.jar] 【参考方案1】:我通过在 proguard 中添加几行来解决此错误。我在 gradle 中使用 twitter 库。
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception
-printmapping mapping.txt
-keep class com.crashlytics.** *;
-dontwarn com.crashlytics.**
-dontwarn com.squareup.okhttp.**
-dontwarn com.google.appengine.api.urlfetch.**
-dontwarn rx.**
-dontwarn retrofit.**
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.squareup.okhttp.** *;
-keep interface com.squareup.okhttp.** *;
-keep class retrofit.** *;
-keepclasseswithmembers class *
@retrofit.http.* <methods>;
【讨论】:
【参考方案2】:确保升级到最新的 Gradle 版本以使用 annotationProcessor 语法:
dependencies
compile "com.google.dagger:dagger:2.9"
annotationProcessor "com.google.dagger:dagger-compiler:2.9"
provided 'javax.annotation:jsr250-api:1.0'
取自android wiki in codepath
【讨论】:
以上是关于Proguard 在构建发布 apk 时导致错误的主要内容,如果未能解决你的问题,请参考以下文章