transformClassesAndResourcesWithProguardForRelease打包混淆失败错误

版权声明:本文为博主原创文章,未经博主允许不得转载。 作者:WalterZhou https://blog.csdn.net/WalterZhoukick/article/details/82585993

使用walle打包的时候出现transformClassesAndResourcesWithProguardForRelease错误,导致打包失败

分析后有以下几种原因

1.包引用重复

这种情况很常见,一般就是app依赖了一个lib项目,lib项目里面有远程依赖了另外一个库,导致库里面的某个包和lib里面的冲突,这种情况还好解决,一个一个删除就好了,难解决的是下面这种

app引用了一个远程图片处理的库,还依赖了一个远程视频处理的库,这两个库都引用了gson,这种情况下我们不能直接删除视频/图片库里面的gson引用,那就只能使用b方案

解决办法:

a.一个一个找,一个一个删除

b.在gradle里面添加忽略配置,忽略文件或者直接忽略整个项目

2.各种警告

这种情况就是我现在遇到的,一般是由于引用了其他的库但是又没按规矩添加混淆配置导致的

解决办法:

a.一种方式是在混淆文件里面添加-ignorewarning

添加完成后如果可以打包成功那就说明是警告的问题,但是添加 -ignorewarning 后打出来的包很有可能有错误

b.另外一种就是先加上-ignorewarning,运行的时候看报错的地方,一般就是gson的混淆没加。之后加上报错的混淆就行了

贴上我的混淆,只引用了gson

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\chendx\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
   public *;
}
-keep public class android.net.http.SslError
-keep public class android.webkit.WebViewClient

-dontwarn android.webkit.WebView
-dontwarn android.net.http.SslError
-dontwarn android.webkit.WebViewClient

# Uncomment this to preserve the line number information for
# debugging stack traces.
-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
-renamesourcefileattribute SourceFile

-keepattributes Exceptions, Signature, InnerClasses

# Keep - Library. Keep all public and protected classes, fields, and methods.
-keep public class * {
    public protected <fields>;
    public protected <methods>;
}

# Also keep - Enumerations. Keep the special static methods that are required in
# enumeration classes.
-keepclassmembers enum  * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

# Keep names - Native method names. Keep all native class/method names.
-keepclasseswithmembers,allowshrinking class * {
    native <methods>;
}

# 不做预校验
-dontpreverify

### 忽略警告
#-ignorewarning

#如果引用了v4或者v7包
-dontwarn android.support.**

-keepattributes EnclosingMethod

-dontwarn com.fengmap.*.**

## 注解支持
-keepclassmembers class *{
   void *(android.view.View);
}

#保护注解
-keepattributes *Annotation*
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }

-keep public class com.google.gson.**
-keep public class com.google.gson.** {public private protected *;}

-keepattributes Signature
-keep public class com.xxx.xxx.bean.** { private *; }

#这个地方就是你存放bean类的包名,我的bean类包名就是com.xxx.xxx.bean,后面加上.** ,很重要,一定要加

-ignorewarning

猜你喜欢

转载自blog.csdn.net/WalterZhoukick/article/details/82585993