Proguard在首次发布时崩溃应用程序

时间:2018-01-03 21:16:02

标签: android-studio proguard libs

大家好我跟 proguard 有些问题。我的项目中有这个罐子库:

  • androidsvg-1.2.2-beta-1.jar
  • commons-io-2.6.jar
  • kenburnsview-1.0.7.jar
  • kxml2-2.3.0.jar
  • mapsforge-core-0.8.0.jar
  • mapsforge-MAP-0.8.0.jar
  • mapsforge-map-android-0.8.0.jar
  • mapsforge-MAP-读取器 - 0.8.0.jar
  • mapsforge-themes-0.8.0.jar
  • nineoldandroids-2.4.0.jar

当我在发布模式中构建消息窗口时显示:

Warning:library class android.content.res.XmlResourceParser extends or implements program class org.xmlpull.v1.XmlPullParser
Warning:com.caverock.androidsvg.SVGImageView: can't find referenced class com.caverock.androidsvg.R$styleable
Warning:com.caverock.androidsvg.SVGImageView: can't find referenced class com.caverock.androidsvg.R
Warning:org.apache.commons.io.FileUtils: can't find referenced method 'java.nio.file.Path toPath()' in library class java.io.File
Warning:org.apache.commons.io.FileUtils: can't find referenced class java.nio.file.Files
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
Warning:there were 5 unresolved references to classes or interfaces.
Warning:there were 32 instances of library classes depending on program classes.
Warning:there were 1 unresolved references to library class members.
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 in 1m 9s
Information:1 error
Information:32 warnings
Information:See complete output in console

然后我将其放入我的proguard-rules.pro

-dontwarn org.xmlpull.v1.**

-keep class org.xmlpull.** { *; }

-dontwarn org.apache.commons.io.**

-keep class org.apache.commons.io.** { *; }

-dontwarn com.caverock.androidsvg.**

-keep class com.caverock.androidsvg.** { *; }

我的应用程序在首次启动时崩溃了,我不知道它是什么,请一些帮助会很棒。

1 个答案:

答案 0 :(得分:0)

首先,您需要更改它们以包含库。不要使用jar,而是使用gradle依赖项。您可以查看mapsforge库integration guide。它应该是这样的:

dependencies {
   // core mapsforge
   implementation 'org.mapsforge:mapsforge-core:v0.9.1'
   implementation 'org.mapsforge:mapsforge-map:v0.9.1'
   implementation 'org.mapsforge:mapsforge-map-reader:v0.9.1'
   implementation 'org.mapsforge:mapsforge-themes:v0.9.1'
   implementation 'net.sf.kxml:kxml2:2.3.0'

   // for android
   implementation 'org.mapsforge:mapsforge-map-android:[CURRENT-VERSION]'
   implementation 'com.caverock:androidsvg:1.2.2-beta-1'

   implementation 'com.nineoldandroids:library:2.4.0'
}

第二,您不得使用此类内容作为库的proguard规则:

-keep class org.apache.commons.io.** { *; }

这意味着,告诉proguard不处理库并将整个库包含到发布应用程序中。

但是对于androidsvg库,你需要处理的是一个特殊的异常。您需要保留整个库(请在Crashes Proguard上阅读此问题):

-dontwarn com.caverock.androidsvg.**

-keep class com.caverock.androidsvg.** { *; }

第三次,检查您的图片是否可绘制。可能是您将图像放在错误的可绘制目录中。