我真的想在我的应用程序中使用这个Proguard功能,但是看到那千个警告让我想知道它是否值得…我应该添加什么才能使它成功构建?或者让我知道这是否是一个失败的原因……
这是我的Gradle文件:
(……)
buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro' } } packagingOptions { exclude 'Meta-INF/LICENSE' exclude 'Meta-INF/LICENSE-FIREBASE.txt' exclude 'Meta-INF/NOTICE' exclude 'Meta-INF/services/javax.annotation.processing.Processor' exclude 'Meta-INF/DEPENDENCIES' exclude 'Meta-INF/LICENSE.txt' exclude 'Meta-INF/NOTICE.txt' } lintOptions { disable 'InvalidPackage' disable 'LongLogTag' } dexOptions { jumboMode = true javaMaxHeapSize "4g" } productFlavors { // Define separate dev and prod product flavors. dev { // dev utilizes minSDKVersion = 21 to allow the Android gradle plugin // to pre-dex each module and produce an APK that can be tested on // Android Lollipop without time consuming dex merging processes. minSdkVersion 16 targetSdkVersion 19 } prod { // The actual minSdkVersion for the application. minSdkVersion 16 targetSdkVersion 21 } } } dependencies { compile fileTree(dir: 'libs',include: ['*.jar']) compile 'com.android.support:multidex:1.0.0' compile "com.android.support:appcompat-v7:${supportLibVersion}" compile 'com.android.support:percent:23.4.0' compile("com.android.support:design:${supportLibVersion}") { exclude module: 'support-v4' } compile("com.android.support:cardview-v7:${supportLibVersion}") { exclude module: 'support-v4' } compile 'com.google.android.gms:play-services-gcm:8.4.0' compile('com.firebase:firebase-client-android:2.4.0') { exclude module: 'jackson-databind' } compile('com.github.nkzawa:socket.io-client:0.4.1') { exclude group: 'org.json',module: 'json' } compile('com.astuetz:pagerslidingtabstrip:1.0.1') { exclude module: 'support-v4' } compile('com.google.android.gms:play-services-location:8.4.0') { exclude module: 'support-v4' } // This one use Maven : url "https://jitpack.io" compile('org.glassfish.jersey.media:jersey-media-json-jackson:2.22.2') { exclude group: 'javax.inject',module: 'javax.inject' } compile('com.github.jakob-grabner:Circle-Progress-View:v1.2.9') { exclude group: 'support-annotations' } compile('com.github.ganfra:material-spinner:1.1.1') { exclude group: 'com.android.support',module: 'appcompat-v7' exclude group: 'com.android.support',module: 'support-v4' } compile 'com.jakewharton:butterknife:7.0.1' compile 'commons-io:commons-io:2.4' compile 'info.guardianproject.iocipher:IOCipher:0.3' compile 'org.apache.commons:commons-lang3:3.4' compile ("com.squareup.retrofit2:retrofit:2.0.0"){ exclude module: 'okhttp' } compile ("com.squareup.retrofit2:converter-jackson:2.0.0"){ exclude module: 'okhttp' } compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.amazonaws:aws-android-sdk-sns:2.+' compile 'com.github.rtoshiro.securesharedpreferences:securesharedpreferences:1.0.+' compile 'de.hdodenhof:circleimageview:2.0.0' compile 'com.felipecsl.asymmetricgridview:library:1.1.0' compile 'com.joanzapata.android:android-iconify:1.0.9' compile 'com.koushikdutta.async:androidasync:2.+' compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4' compile 'com.squareup.okhttp3:logging-interceptor:3.0.1' compile 'com.github.johnpersano:supertoasts:1.3.4@aar' compile 'com.github.ybq:Android-SpinKit:1.0.3' compile 'com.timehop.stickyheadersrecyclerview:library:0.4.3@aar' compile 'com.bigkoo:pickerview:2.0.8' compile 'com.takwolf.android:lock9view:0.0.11' compile 'com.kyleduo.switchbutton:library:1.4.0' compile 'com.hanks.animatecheckBox:library:0.1' compile 'com.code-troopers.betterpickers:library:2.5.5' } apply plugin: ('com.google.gms.google-services')
这是我的proguard-rule.pro文件:
########################## # RETROFIT # ########################## # Add any project specific keep options here: -dontwarn retrofit2.** -keep class retrofit2.** { *; } -keepattributes Signature -keepattributes Exceptions -keepattributes Annotation ########################## # BUTTERKNIFE # ########################## -keep class butterknife.** { *; } -dontwarn butterknife.internal.** -keep class **$$ViewBinder { *; } -keepclasseswithmembernames class * { @butterknife.* <fields>; } -keepclasseswithmembernames class * { @butterknife.* <methods>; } ########################## # JACKSON-PARSER # ########################## -keepattributes *Annotation*,EnclosingMethod,Signature -keepnames class com.fasterxml.jackson.** { *; } -dontwarn com.fasterxml.jackson.databind.** -keep class org.codehaus.** { *; } -keepclassmembers public final enum org.codehaus.jackson.annotate.JsonAutoDetect$Visibility { public static final org.codehaus.jackson.annotate.JsonAutoDetect$Visibility *; } -keep public class your.class.** { public void set*(***); public *** get*(); } -assumenosideeffects class android.util.Log { public static *** d(...); public static *** v(...); public static *** i(...); public static *** w(...); public static *** e(...); public static *** wtf(...); }
这些是剩下的警告:
(…) Warning:com.fasterxml.jackson.module.jaxb.deser.DataHandlerJsonDeserializer$1: can't find superclass or interface javax.activation.DataSource Warning:javax.ws.rs.core.Link$JaxbAdapter: can't find superclass or interface javax.xml.bind.annotation.adapters.XmlAdapter Warning:org.glassfish.hk2.osgiresourcelocator.Activator: can't find superclass or interface org.osgi.framework.BundleActivator Warning:org.glassfish.hk2.osgiresourcelocator.ServiceLoaderImpl$BundleTracker: can't find superclass or interface org.osgi.framework.BundleListener Warning:org.glassfish.jersey.internal.OsgiRegistry: can't find superclass or interface org.osgi.framework.SynchronousBundleListener Warning:org.glassfish.jersey.message.internal.DataSourceProvider$ByteArrayDataSource: can't find superclass or interface javax.activation.DataSource Warning:com.fasterxml.jackson.module.jaxb.AdapterConverter: can't find referenced class javax.xml.bind.annotation.adapters.XmlAdapter Warning:com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector: can't find referenced class javax.xml.bind.annotation.XmlElement Warning:com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector: can't find referenced class javax.xml.bind.annotation.XmlRootElement Warning:com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector: can't find referenced class javax.xml.bind.annotation.XmlElement Warning:com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector: can't find referenced class javax.xml.bind.annotation.XmlAttribute Warning:com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector: can't find referenced class javax.xml.bind.annotation.XmlValue Warning:com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector: can't find referenced class javax.xml.bind.annotation.XmlElements Warning:com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector$1: can't find referenced class javax.xml.bind.annotation.XmlAccessType Warning:com.fasterxml.jackson.module.jaxb.deser.DataHandlerJsonDeserializer: can't find referenced class javax.activation.DataHandler Warning:com.fasterxml.jackson.module.jaxb.deser.DataHandlerJsonDeserializer$1: can't find referenced class javax.activation.DataSource Warning:com.fasterxml.jackson.module.jaxb.ser.DataHandlerJsonSerializer: can't find referenced class javax.activation.DataHandler Warning:com.felipecsl.asymmetricgridview.library.widget.AnimatorProxy: can't find referenced method 'float floor(float)' in library class android.util.FloatMath Warning:com.felipecsl.asymmetricgridview.library.widget.AnimatorProxy: can't find referenced method 'float ceil(float)' in library class android.util.FloatMath Warning:com.google.common.base.Equivalence: can't find referenced class javax.annotation.Nullable Warning:com.google.common.base.Equivalences$Impl$1: can't find referenced class javax.annotation.Nullable Warning:com.google.common.base.Equivalences$Impl$2: can't find referenced class javax.annotation.Nullable Warning:com.google.common.base.Function: can't find referenced class javax.annotation.Nullable Warning:com.google.common.base.Functions: can't find referenced class javax.annotation.Nullable Warning:com.google.common.base.Functions$ConstantFunction: can't find referenced class javax.annotation.Nullable Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.OkHttpClient Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Cache Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.OkHttpClient Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.CacheControl Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.CacheControl$Builder Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Request$Builder Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.OkHttpClient Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Call Warning:javassist.tools.rmi.ObjectImporter: can't find referenced class java.applet.Applet Warning:javassist.util.HotSwapper: can't find referenced class com.sun.jdi.connect.AttachingConnector Warning:javassist.util.HotSwapper: can't find referenced class com.sun.jdi.connect.Connector$Argument Warning:javassist.util.HotSwapper: can't find referenced class com.sun.jdi.connect.AttachingConnector Warning:javassist.util.HotSwapper: can't find referenced class com.sun.jdi.VirtualMachine Warning:javassist.util.HotSwapper: can't find referenced class com.sun.jdi.Bootstrap Warning:javassist.util.HotSwapper: can't find referenced class com.sun.jdi.VirtualMachineManager Warning:javassist.util.HotSwapper: can't find referenced class com.sun.jdi.connect.Connector Warning:javassist.util.HotSwapper: can't find referenced class com.sun.jdi.event.EventQueue Warning:javassist.util.HotSwapper: can't find referenced class com.sun.jdi.VirtualMachine Warning:javax.ws.rs.core.Link$JaxbAdapter: can't find referenced class javax.xml.bind.annotation.adapters.XmlAdapter Warning:javax.ws.rs.core.Link$JaxbLink: can't find referenced class javax.xml.bind.annotation.XmlAttribute Warning:javax.ws.rs.core.Link$JaxbLink: can't find referenced class javax.xml.bind.annotation.XmlAnyAttribute Warning:jersey.repackaged.com.google.common.base.Absent: can't find referenced class javax.annotation.Nullable Warning:jersey.repackaged.com.google.common.base.Converter: can't find referenced class javax.annotation.Nullable Warning:jersey.repackaged.com.google.common.base.Equivalence: can't find referenced class javax.annotation.Nullable Warning:jersey.repackaged.com.google.common.base.Function: can't find referenced class javax.annotation.Nullable Warning:jersey.repackaged.com.google.common.base.Joiner: can't find referenced class javax.annotation.CheckReturnValue Warning:jersey.repackaged.com.google.common.base.Joiner$1: can't find referenced class javax.annotation.Nullable Warning:jersey.repackaged.com.google.common.base.MoreObjects: can't find referenced class javax.annotation.Nullable Warning:jersey.repackaged.com.google.common.base.MoreObjects$ToStringHelper: can't find referenced class javax.annotation.Nullable Warning:jersey.repackaged.com.google.common.base.Objects: can't find referenced class javax.annotation.CheckReturnValue Warning:jersey.repackaged.com.google.common.base.Objects: can't find referenced class javax.annotation.Nullable Warning:jersey.repackaged.com.google.common.base.Predicates$ObjectPredicate$3: can't find referenced class javax.annotation.Nullable Warning:jersey.repackaged.com.google.common.base.Predicates$ObjectPredicate$4: can't find referenced class javax.annotation.Nullable Warning:jersey.repackaged.com.google.common.base.Predicates$OrPredicate: can't find referenced class javax.annotation.Nullable 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:org.glassfish.hk2.osgiresourcelocator.Activator: can't find referenced class org.osgi.framework.BundleActivator Warning:org.glassfish.hk2.osgiresourcelocator.Activator: can't find referenced class org.osgi.framework.BundleContext Warning:org.glassfish.hk2.osgiresourcelocator.ResourceFinderImpl: can't find referenced class org.osgi.framework.BundleReference Warning:org.glassfish.hk2.osgiresourcelocator.ResourceFinderImpl: can't find referenced class org.osgi.framework.Bundle Warning:org.glassfish.hk2.osgiresourcelocator.ResourceFinderImpl: can't find referenced class org.osgi.framework.BundleContext Warning:org.glassfish.hk2.osgiresourcelocator.ResourceFinderImpl: can't find referenced class org.osgi.framework.Bundle Warning:org.glassfish.hk2.osgiresourcelocator.ResourceFinderImpl: can't find referenced class org.osgi.framework.BundleContext Warning:org.glassfish.hk2.osgiresourcelocator.ResourceFinderImpl: can't find referenced class org.osgi.framework.Bundle Warning:org.glassfish.hk2.utilities.reflection.BeanReflectionHelper: can't find referenced class java.beans.Introspector Warning:org.glassfish.jersey.internal.OsgiRegistry: can't find referenced class org.osgi.framework.BundleReference Warning:org.glassfish.jersey.internal.OsgiRegistry: can't find referenced class org.osgi.framework.FrameworkUtil Warning:org.glassfish.jersey.internal.OsgiRegistry: can't find referenced class org.osgi.framework.Bundle Warning:org.glassfish.jersey.internal.OsgiRegistry: can't find referenced class org.osgi.framework.BundleEvent Warning:org.glassfish.jersey.internal.OsgiRegistry$2: can't find referenced class org.osgi.framework.Bundle Warning:org.glassfish.jersey.internal.OsgiRegistry$BundleSpiProvidersLoader: can't find referenced class org.osgi.framework.Bundle Warning:org.glassfish.jersey.internal.util.ReflectionHelper: can't find referenced class org.osgi.framework.FrameworkUtil Warning:org.glassfish.jersey.internal.util.ReflectionHelper: can't find referenced class org.osgi.framework.Bundle Warning:org.glassfish.jersey.internal.util.ReflectionHelper: can't find referenced class org.osgi.framework.FrameworkUtil Warning:org.glassfish.jersey.internal.util.ReflectionHelper: can't find referenced class org.osgi.framework.Bundle Warning:org.glassfish.jersey.internal.util.collection.ConcurrentHashMapV8: can't find referenced class sun.misc.Unsafe Warning:org.glassfish.jersey.internal.util.collection.ConcurrentHashMapV8$1: can't find referenced class sun.misc.Unsafe Warning:org.glassfish.jersey.internal.util.collection.ConcurrentHashMapV8$TreeBin: can't find referenced class sun.misc.Unsafe Warning:org.glassfish.jersey.internal.util.collection.LinkedTransferQueue: can't find referenced class sun.misc.Unsafe Warning:org.glassfish.jersey.internal.util.collection.LinkedTransferQueue$1: can't find referenced class sun.misc.Unsafe Warning:org.glassfish.jersey.internal.util.collection.LinkedTransferQueue$Node: can't find referenced class sun.misc.Unsafe Warning:org.glassfish.jersey.message.filtering.SecurityEntityFilteringFeature: can't find referenced class org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature Warning:org.glassfish.jersey.message.filtering.ServerScopeProvider: can't find referenced class org.glassfish.jersey.server.ExtendedUriInfo Warning:org.glassfish.jersey.message.filtering.ServerScopeProvider: can't find referenced class org.glassfish.jersey.server.model.ResourceMethod Warning:org.glassfish.jersey.message.filtering.ServerScopeProvider: can't find referenced class org.glassfish.jersey.server.model.Invocable Warning:org.glassfish.jersey.message.filtering.ServerScopeProvider: can't find referenced class org.glassfish.jersey.server.model.MethodHandler Warning:org.glassfish.jersey.message.filtering.ServerScopeProvider: can't find referenced class org.glassfish.jersey.server.ExtendedUriInfo Warning:org.glassfish.jersey.message.filtering.ServerScopeProvider: can't find referenced class org.glassfish.jersey.server.model.ResourceMethod Warning:org.glassfish.jersey.message.filtering.ServerScopeProvider: can't find referenced class org.glassfish.jersey.server.ExtendedUriInfo Warning:org.glassfish.jersey.message.filtering.ServerScopeProvider: can't find referenced class org.glassfish.jersey.server.model.ResourceMethod Warning:org.glassfish.jersey.message.filtering.spi.FilteringHelper: can't find referenced class javax.xml.bind.JAXBElement Warning:org.glassfish.jersey.message.internal.DataSourceProvider: can't find referenced class javax.activation.DataSource Warning:org.glassfish.jersey.message.internal.DataSourceProvider$ByteArrayDataSource: can't find referenced class javax.activation.DataSource Warning:org.glassfish.jersey.message.internal.RenderedImageProvider: can't find referenced class java.awt.image.RenderedImage Warning:org.glassfish.jersey.message.internal.RenderedImageProvider: can't find referenced class java.awt.image.BufferedImage Warning:org.glassfish.jersey.message.internal.RenderedImageProvider: can't find referenced class javax.imageio.ImageIO Warning:org.glassfish.jersey.message.internal.RenderedImageProvider: can't find referenced class javax.imageio.ImageReader Warning:org.glassfish.jersey.message.internal.RenderedImageProvider: can't find referenced class javax.imageio.ImageIO Warning:org.glassfish.jersey.message.internal.RenderedImageProvider: can't find referenced class javax.imageio.ImageReader Warning:org.glassfish.jersey.message.internal.RenderedImageProvider: can't find referenced class java.awt.image.RenderedImage Warning:org.glassfish.jersey.message.internal.RenderedImageProvider: can't find referenced class javax.imageio.ImageWriter Warning:org.glassfish.jersey.message.internal.RenderedImageProvider: can't find referenced class java.awt.image.RenderedImage (…) Note: there were 4 references to unknown classes. You should check your configuration for typos. (http://proguard.sourceforge.net/manual/troubleshooting.html#unknownclass) Note: there were 11 classes trying to access enclosing classes using reflection. You should consider keeping the inner classes attributes (using '-keepattributes InnerClasses'). (http://proguard.sourceforge.net/manual/troubleshooting.html#attributes) Note: there were 143 unkept descriptor classes in kept class members. You should consider explicitly keeping the mentioned classes (using '-keep'). (http://proguard.sourceforge.net/manual/troubleshooting.html#descriptorclass) Note: there were 30 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) Warning:there were 1911 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 2 unresolved references to library class members. You probably need to update the library versions. (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember) Warning:Exception while processing task java.io.IOException: Please correct the above warnings first. :app:transformClassesAndResourcesWithProguardForProdRelease Failed Error:Execution Failed for task ':app:transformClassesAndResourcesWithProguardForProdRelease'. > java.io.IOException: Please correct the above warnings first. Information:BUILD Failed Information:Total time: 7.152 secs Information:1 error Information:901 warnings Information:See complete output in console
解决方法
我通常需要告诉proguard保留第三方库以使其成功构建.例如,Id为Okio和fasterxml添加以下内容:
-keep class okio.** { *; } -dontwarn okio.** -keep class com.fasterxml.** { *; } -dontwarn com.fasterxml.**
为项目中包含的每个第三方库添加上述内容.从你的日志我看到glassfish,jersey,squareup,google,Okio和fasterxml.
以下是有关上面列出的proguard规则的更多信息:
Android Proguard – is it best practice to -keep all 3rd party libs?