Gradle 在使用 Proguard 编译发布版本时无法找到一些引用和库类
Posted
技术标签:
【中文标题】Gradle 在使用 Proguard 编译发布版本时无法找到一些引用和库类【英文标题】:Gradle unable to find some referenced and library classes while using Proguard to compile release build 【发布时间】:2016-11-21 02:09:13 【问题描述】:我正在尝试使用 proguard 构建我的应用程序的发布版本,以便我可以缩减资源并混淆我的代码。我面临一些 gradle 在运行时找不到的引用和库类问题,因此给出了一些警告,如下所述。
Gradle 控制台警告
我在编译以使用 proguard 准备发布版本时遇到这些警告
Warning:com.vividsolutions.jts.awt.GeometryCollectionShape: can't find superclass or interface java.awt.Shape
Warning:com.vividsolutions.jts.awt.PolygonShape: can't find superclass or interface java.awt.Shape
Warning:com.vividsolutions.jts.awt.ShapeCollectionPathIterator: can't find superclass or interface java.awt.geom.PathIterator
Warning:com.vividsolutions.jts.awt.ShapeCollectionPathIterator$1: can't find superclass or interface java.awt.geom.PathIterator
Warning:library class android.content.res.XmlResourceParser extends or implements program class org.xmlpull.v1.XmlPullParser
Warning:com.google.firebase.messaging.FirebaseMessaging: can't find referenced method 'void zziy(java.lang.String)' in program class com.google.firebase.iid.FirebaseInstanceId
Warning:com.google.firebase.messaging.FirebaseMessaging: can't find referenced method 'java.lang.String zzaX(android.content.Context)' in program class com.google.firebase.iid.zzf
Warning:com.google.firebase.messaging.FirebaseMessagingService: can't find referenced method 'android.content.Intent zzUr()' in program class com.google.firebase.iid.FirebaseInstanceIdInternalReceiver
Warning:com.google.firebase.messaging.FirebaseMessagingService: can't find referenced method 'int zzA(android.content.Intent)' in program class com.google.firebase.iid.zzb
Warning:com.google.firebase.messaging.FirebaseMessagingService: can't find referenced method 'void zzBL()' in program class com.google.firebase.messaging.FirebaseMessagingService
Warning:com.google.firebase.messaging.zzb: can't find referenced method 'void zza(java.lang.String,java.lang.String,java.lang.Object)' in program class com.google.android.gms.measurement.AppMeasurement
Warning:com.google.firebase.messaging.zzc: can't find referenced method 'int zzap(android.os.Parcel)' in program class com.google.android.gms.common.internal.safeparcel.zza
Warning:com.google.firebase.messaging.zzc: can't find referenced method 'int zzaq(android.os.Parcel)' in program class com.google.android.gms.common.internal.safeparcel.zza
Warning:com.google.firebase.messaging.zzc: can't find referenced method 'int zzcj(int)' in program class com.google.android.gms.common.internal.safeparcel.zza
Warning:com.google.firebase.messaging.zzc: can't find referenced method 'void zzJ(android.os.Parcel,int)' in program class com.google.android.gms.common.internal.safeparcel.zzb
Warning:com.google.firebase.messaging.zzc: can't find referenced method 'int zzar(android.os.Parcel)' in program class com.google.android.gms.common.internal.safeparcel.zzb
Warning:com.vividsolutions.jts.awt.FontGlyphReader: can't find referenced class java.awt.Font
Warning:com.vividsolutions.jts.awt.FontGlyphReader: can't find referenced class java.awt.font.FontRenderContext
Warning:com.vividsolutions.jts.awt.FontGlyphReader: can't find referenced class java.awt.Font
Warning:com.vividsolutions.jts.awt.FontGlyphReader: can't find referenced class java.awt.font.GlyphVector
Warning:com.vividsolutions.jts.awt.FontGlyphReader: can't find referenced class java.awt.Font
Warning:com.vividsolutions.jts.awt.FontGlyphReader: can't find referenced class java.awt.font.FontRenderContext
Warning:com.vividsolutions.jts.awt.FontGlyphReader: can't find referenced class java.awt.font.GlyphVector
Warning:com.vividsolutions.jts.awt.GeometryCollectionShape: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.GeometryCollectionShape: can't find referenced class java.awt.geom.Rectangle2D
Warning:com.vividsolutions.jts.awt.GeometryCollectionShape: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.GeometryCollectionShape: can't find referenced class java.awt.Rectangle
Warning:com.vividsolutions.jts.awt.GeometryCollectionShape: can't find referenced class java.awt.geom.Rectangle2D
Warning:com.vividsolutions.jts.awt.GeometryCollectionShape: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.GeometryCollectionShape: can't find referenced class java.awt.geom.Rectangle2D
Warning:com.vividsolutions.jts.awt.GeometryCollectionShape: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.GeometryCollectionShape: can't find referenced class java.awt.geom.Rectangle2D
Warning:com.vividsolutions.jts.awt.GeometryCollectionShape: can't find referenced class java.awt.geom.AffineTransform
Warning:com.vividsolutions.jts.awt.GeometryCollectionShape: can't find referenced class java.awt.geom.PathIterator
Warning:com.vividsolutions.jts.awt.GeometryCollectionShape: can't find referenced class java.awt.geom.AffineTransform
Warning:com.vividsolutions.jts.awt.GeometryCollectionShape: can't find referenced class java.awt.geom.PathIterator
Warning:com.vividsolutions.jts.awt.GeometryCollectionShape: can't find referenced class java.awt.geom.AffineTransform
Warning:com.vividsolutions.jts.awt.IdentityPointTransformation: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.PointShapeFactory$BasePointShapeFactory: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$BasePointShapeFactory: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Circle: can't find referenced class java.awt.geom.Ellipse2D$Double
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Circle: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Circle: can't find referenced class java.awt.geom.Ellipse2D$Double
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Circle: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Circle: can't find referenced class java.awt.geom.Ellipse2D$Double
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Circle: can't find referenced class java.awt.geom.Ellipse2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Circle: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Circle: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Circle: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Circle: can't find referenced class java.awt.geom.Ellipse2D$Double
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Cross: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Cross: can't find referenced class java.awt.geom.GeneralPath
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Cross: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Cross: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Cross: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Cross: can't find referenced class java.awt.geom.GeneralPath
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Point: can't find referenced class java.awt.geom.Line2D$Double
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Point: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Point: can't find referenced class java.awt.geom.Line2D$Double
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Point: can't find referenced class java.awt.geom.Line2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Point: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Point: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Point: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Point: can't find referenced class java.awt.geom.Line2D$Double
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Square: can't find referenced class java.awt.geom.Rectangle2D$Double
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Square: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Square: can't find referenced class java.awt.geom.Rectangle2D$Double
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Square: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Square: can't find referenced class java.awt.geom.Rectangle2D$Double
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Square: can't find referenced class java.awt.geom.Rectangle2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Square: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Square: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Square: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Square: can't find referenced class java.awt.geom.Rectangle2D$Double
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Star: can't find referenced class java.awt.geom.GeneralPath
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Star: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Star: can't find referenced class java.awt.geom.GeneralPath
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Star: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Star: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Star: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Star: can't find referenced class java.awt.geom.GeneralPath
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Triangle: can't find referenced class java.awt.geom.GeneralPath
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Triangle: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Triangle: can't find referenced class java.awt.geom.GeneralPath
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Triangle: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Triangle: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Triangle: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$Triangle: can't find referenced class java.awt.geom.GeneralPath
Warning:com.vividsolutions.jts.awt.PointShapeFactory$X: can't find referenced class java.awt.geom.GeneralPath
Warning:com.vividsolutions.jts.awt.PointShapeFactory$X: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$X: can't find referenced class java.awt.geom.GeneralPath
Warning:com.vividsolutions.jts.awt.PointShapeFactory$X: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$X: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.PointShapeFactory$X: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PointShapeFactory$X: can't find referenced class java.awt.geom.GeneralPath
Warning:com.vividsolutions.jts.awt.PointTransformation: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PolygonShape: can't find referenced class java.awt.geom.GeneralPath
Warning:com.vividsolutions.jts.awt.PolygonShape: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PolygonShape: can't find referenced class java.awt.geom.GeneralPath
Warning:com.vividsolutions.jts.awt.PolygonShape: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.PolygonShape: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PolygonShape: can't find referenced class java.awt.geom.GeneralPath
Warning:com.vividsolutions.jts.awt.PolygonShape: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PolygonShape: can't find referenced class java.awt.geom.GeneralPath
Warning:com.vividsolutions.jts.awt.PolygonShape: can't find referenced class java.awt.Rectangle
Warning:com.vividsolutions.jts.awt.PolygonShape: can't find referenced class java.awt.geom.Rectangle2D
Warning:com.vividsolutions.jts.awt.PolygonShape: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.PolygonShape: can't find referenced class java.awt.geom.Rectangle2D
Warning:com.vividsolutions.jts.awt.PolygonShape: can't find referenced class java.awt.geom.AffineTransform
Warning:com.vividsolutions.jts.awt.PolygonShape: can't find referenced class java.awt.geom.PathIterator
Warning:com.vividsolutions.jts.awt.PolygonShape: can't find referenced class java.awt.geom.AffineTransform
Warning:com.vividsolutions.jts.awt.PolygonShape: can't find referenced class java.awt.geom.PathIterator
Warning:com.vividsolutions.jts.awt.PolygonShape: can't find referenced class java.awt.geom.AffineTransform
Warning:com.vividsolutions.jts.awt.ShapeCollectionPathIterator: can't find referenced class java.awt.geom.PathIterator
Warning:com.vividsolutions.jts.awt.ShapeCollectionPathIterator: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.ShapeCollectionPathIterator: can't find referenced class java.awt.geom.PathIterator
Warning:com.vividsolutions.jts.awt.ShapeCollectionPathIterator: can't find referenced class java.awt.geom.AffineTransform
Warning:com.vividsolutions.jts.awt.ShapeCollectionPathIterator$1: can't find referenced class java.awt.geom.PathIterator
Warning:com.vividsolutions.jts.awt.ShapeReader: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.ShapeReader: can't find referenced class java.awt.geom.PathIterator
Warning:com.vividsolutions.jts.awt.ShapeReader: can't find referenced class java.awt.geom.AffineTransform
Warning:com.vividsolutions.jts.awt.ShapeReader: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.ShapeReader: can't find referenced class java.awt.geom.PathIterator
Warning:com.vividsolutions.jts.awt.ShapeReader: can't find referenced class java.awt.geom.AffineTransform
Warning:com.vividsolutions.jts.awt.ShapeReader: can't find referenced class java.awt.geom.PathIterator
Warning:com.vividsolutions.jts.awt.ShapeReader: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.ShapeReader: can't find referenced class java.awt.geom.PathIterator
Warning:com.vividsolutions.jts.awt.ShapeWriter: can't find referenced class java.awt.geom.Point2D$Double
Warning:com.vividsolutions.jts.awt.ShapeWriter: can't find referenced class java.awt.geom.GeneralPath
Warning:com.vividsolutions.jts.awt.ShapeWriter: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.ShapeWriter: can't find referenced class java.awt.geom.GeneralPath
Warning:com.vividsolutions.jts.awt.ShapeWriter: can't find referenced class java.awt.geom.Point2D
Warning:com.vividsolutions.jts.awt.ShapeWriter: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.ShapeWriter: can't find referenced class java.awt.geom.GeneralPath
Warning:com.vividsolutions.jts.awt.ShapeWriter: can't find referenced class java.awt.Shape
Warning:com.vividsolutions.jts.awt.ShapeWriter: can't find referenced class java.awt.geom.Point2D
Warning:okio.DeflaterSink: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning:okio.Okio: can't find referenced class java.nio.file.Files
Warning:okio.Okio: can't find referenced class java.nio.file.Path
Warning:okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning:okio.Okio: can't find referenced class java.nio.file.Path
Warning:okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning:okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning:okio.Okio: can't find referenced class java.nio.file.Path
Warning:okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning:okio.Okio: can't find referenced class java.nio.file.Path
Warning:okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning:okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandles$Lookup
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandle
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandles
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandle
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandles$Lookup
Warning:retrofit2.Platform$Java8: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning:library class android.content.Intent depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.content.IntentFilter depends on program class org.xmlpull.v1.XmlSerializer
Warning:library class android.content.IntentFilter depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.content.res.ColorStateList depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.AnimatedVectorDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.AnimationDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.BitmapDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.ClipDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.ColorDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.DrawableWrapper depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.GradientDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.InsetDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.LayerDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.RippleDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.ScaleDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.ShapeDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.StateListDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.VectorDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.util.Xml depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.util.Xml depends on program class org.xmlpull.v1.XmlSerializer
Warning:library class android.util.Xml depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.view.LayoutInflater depends on program class org.xmlpull.v1.XmlPullParser
proguard-rules.pro
我尝试了很多方法来消除这些警告,但没有找到任何有效的解决方案。我的 proguard 规则定义如下:
-printconfiguration config.txt
#-keep class * extends android.app.Activity
#-keep class * extends android.support.v4.app.Fragment
#-keep class * extends Application
-assumenosideeffects class android.util.Log
public static *** d(...);
public static *** v(...);
public static *** i(...);
public static *** e(...);
-keepattributes Signature
-keepattributes InnerClasses
#-keepattributes *Annotation*
-dontnote org.xmlpull.v1.**
-dontnote org.apache.http.**
-dontnote android.net.http.**
-keepclasseswithmembers,includedescriptorclasses class * *;
#-keep class com.vividsolutions.jts.awt.** *;
#-keep class android.content.XMLResourceParser *;
#-keep class com.google.firebase.messaging.** *;
#-keep class okio.** *;
#-keep class retrofit2.** *;
-keep class java.awt.** *;
-keep class com.google.firebase.iid.** *;
-keep class com.google.firebase.messaging.FirebaseMessagingService *;
-keep class com.google.android.gms.measurement.AppMeasurement *;
-keep class com.google.android.gms.common.internal.safeparcel.** *;
-keep class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement *;
-keep class java.nio.file.**
-keep class java.lang.invoke.**
-keep class org.xmlpull.v1.XmlPullParser *;
build.gradle [应用]
packagingOptions
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
【问题讨论】:
【参考方案1】:您遇到的错误是因为缺少 ProGuard 的输入类集中不存在的类。
示例:jts 库使用 Android 中不存在的 AWT 类。
您需要使用-dontwarn
规则,而不是使用-keep
规则(指示ProGuard 防止现有类被混淆/缩小/优化)。
对于 jts 库:-dontwarn java.awt.**
将隐藏 AWT 类的警告
您还可以使用-ignorewarnings
快速测试是否可以忽略所有警告并构建您的应用程序。如果之后一切正常,应该没问题。
【讨论】:
-ignorewarnings 以后可能会带来问题以上是关于Gradle 在使用 Proguard 编译发布版本时无法找到一些引用和库类的主要内容,如果未能解决你的问题,请参考以下文章
升级 gradle 后 Proguard 行为发生变化,从构建的 apk 中省略类
Android Build 使用 Proguard 和 Gradle 失败