我正在使用ProGuard并缩小我的应用中的资源功能,如下所示:
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
当我构建应用程序时,它会显示一些警告,但构建不成功,如下所示:
Information:Gradle tasks [:app:assembleRelease]
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find superclass or interface java.awt.datatransfer.Transferable
Warning:org.apache.harmony.awt.datatransfer.NativeClipboard: can't find superclass or interface java.awt.datatransfer.Clipboard
Warning:com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.Sasl
Warning:com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
Warning:com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslException
Warning:com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
Warning:com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslException
Warning:com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.auth.callback.NameCallback
Warning:com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmCallback
Warning:com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmChoiceCallback
Warning:com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.auth.callback.NameCallback
Warning:com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmCallback
Warning:com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmChoiceCallback
Warning:javax.activation.CommandInfo: can't find referenced class java.beans.Beans
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.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit
Warning:org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment
Warning:org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit
Warning:org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment
Warning:org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.SystemFlavorMap
Warning:org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.dnd.DropTargetContext
Warning:org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.dnd.peer.DropTargetContextPeer
Warning:org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.dnd.DragGestureEvent
Warning:org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.dnd.peer.DragSourceContextPeer
Warning:org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.SystemFlavorMap
Warning:org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.SystemFlavorMap
Warning:org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.SystemFlavorMap
Warning:org.apache.harmony.awt.datatransfer.DataProvider: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.Transferable
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.SystemFlavorMap
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.UnsupportedFlavorException
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.Image
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.UnsupportedFlavorException
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.SystemFlavorMap
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.SystemFlavorMap
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.image.DirectColorModel
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.image.DataBufferInt
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.image.Raster
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.image.ComponentColorModel
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.color.ColorSpace
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.image.ComponentColorModel
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.image.DataBufferByte
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.image.Raster
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.image.DataBufferUShort
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.image.BufferedImage
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.SystemFlavorMap
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.Image
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.image.BufferedImage
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.image.ColorModel
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.image.WritableRaster
Warning:org.apache.harmony.awt.datatransfer.DataSnapshot: can't find referenced class java.awt.datatransfer.SystemFlavorMap
Warning:org.apache.harmony.awt.datatransfer.DataSnapshot: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.datatransfer.Transferable
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.datatransfer.SystemFlavorMap
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.datatransfer.Transferable
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.Image
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.image.BufferedImage
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.Image
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.image.BufferedImage
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.Graphics
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.image.BufferedImage
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.image.WritableRaster
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.image.DataBufferInt
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.datatransfer.Transferable
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.datatransfer.SystemFlavorMap
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.Image
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.image.BufferedImage
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.Graphics
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.image.BufferedImage
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.image.DataBufferInt
Warning:org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.DragSourceEventProxy: can't find referenced class java.awt.Point
Warning:org.apache.harmony.awt.datatransfer.DragSourceEventProxy: can't find referenced class java.awt.dnd.DragSourceContext
Warning:org.apache.harmony.awt.datatransfer.DragSourceEventProxy: can't find referenced class java.awt.dnd.DragSourceEvent
Warning:org.apache.harmony.awt.datatransfer.DragSourceEventProxy: can't find referenced class java.awt.dnd.DragSourceContext
Warning:org.apache.harmony.awt.datatransfer.DragSourceEventProxy: can't find referenced class java.awt.dnd.DragSourceDropEvent
Warning:org.apache.harmony.awt.datatransfer.DragSourceEventProxy: can't find referenced class java.awt.dnd.DragSourceDragEvent
Warning:org.apache.harmony.awt.datatransfer.DragSourceEventProxy: can't find referenced class java.awt.dnd.DragSourceContext
Warning:org.apache.harmony.awt.datatransfer.DragSourceEventProxy: can't find referenced class java.awt.Point
Warning:org.apache.harmony.awt.datatransfer.DragSourceEventProxy: can't find referenced class java.awt.dnd.DragSourceContext
Warning:org.apache.harmony.awt.datatransfer.DragSourceEventProxy: can't find referenced class java.awt.Point
Warning:org.apache.harmony.awt.datatransfer.DragSourceEventProxy: can't find referenced class java.awt.dnd.DragSourceContext
Warning:org.apache.harmony.awt.datatransfer.DragSourceEventProxy: can't find referenced class java.awt.Point
Warning:org.apache.harmony.awt.datatransfer.DragSourceEventProxy: can't find referenced class java.awt.dnd.DragSourceContext
Warning:org.apache.harmony.awt.datatransfer.DragSourceEventProxy: can't find referenced class java.awt.Point
Warning:org.apache.harmony.awt.datatransfer.DragSourceEventProxy: can't find referenced class java.awt.dnd.DragSourceDragEvent
Warning:org.apache.harmony.awt.datatransfer.FlavorsComparator: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.NativeClipboard: can't find referenced class java.awt.datatransfer.Clipboard
Warning:org.apache.harmony.awt.datatransfer.TextFlavor: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.TextFlavor: can't find referenced class java.awt.datatransfer.SystemFlavorMap
Warning:org.apache.harmony.awt.datatransfer.TextFlavor: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:org.apache.harmony.awt.datatransfer.TextFlavor: can't find referenced class java.awt.datatransfer.SystemFlavorMap
Warning:org.apache.harmony.awt.datatransfer.TextFlavor: can't find referenced class java.awt.datatransfer.DataFlavor
Warning:there were 261 unresolved references to classes or interfaces.
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> Job failed, see logs for details
Information:BUILD FAILED
Information:Total time: 3.68 secs
Information:1 error
Information:122 warnings
Information:See complete output in console
我尝试了一些ProGuard规则来避免这个问题,它成功构建了应用程序。但是当我在我的设备上安装应用程序并打开它时,它显示没有UI,然后设备freez然后它被迫从系统关闭。
在我的情况下,任何人都可以帮助我制定正确的ProGuard规则。
答案 0 :(得分:1)
引用的类实际上并不在您的项目或依赖项中,因此您无法保留它们。
某些库是基于新平台代码或其他库构建的,但设计为在没有它的情况下工作。如果您未在项目中包含这些依赖项,则会收到警告。所有这一切都完全没问题,你只需告诉proguard你知道这件事。
例如,你使用依赖于java.nio的Okio但是只能在普通的Java和Android O中使用.Okio可以在没有java.nio的情况下工作,但你必须告诉proguard你没关系。所以你将它添加到你的proguard规则:
# Okio
-keep class sun.misc.Unsafe { *; }
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn okio.**
您可以在此处找到其他图书馆的更多规则:https://github.com/krschultz/android-proguard-snippets/tree/master/libraries
如果您没有找到图书馆的规则,但有信心图书馆可以工作,只需要关闭程序-dontwarn
就是您的朋友。 E.g。
-dontwarn org.apache.harmony.awt.datatransfer.DataProxy
-dontwarn org.apache.harmony.awt.datatransfer.NativeClipboard
或者如果你想关闭包中的所有内容
-dontwarn org.apache.harmony.awt.**