有关于Android多个module混淆的问题

前些天做功能的时候 添加了fastjson包然后编译后就发生了各种空指针异常 ,但是明明 明明已经根据gson 加了-keep 命令 但是还是各种不对 T . T
首先看下第一个错误

arning: com.alibaba.fastjson.support.jaxrs.FastJsonFeature: can't find superclass or interface javax.ws.rs.core.Feature
Warning: com.alibaba.fastjson.support.jaxrs.FastJsonProvider: can't find superclass or interface javax.ws.rs.ext.MessageBodyReader
Warning: com.alibaba.fastjson.support.jaxrs.FastJsonProvider: can't find superclass or interface javax.ws.rs.ext.MessageBodyWriter
Warning: com.alibaba.fastjson.support.retrofit.Retrofit2ConverterFactory: can't find superclass or interface retrofit2.Converter$Factory
Warning: com.alibaba.fastjson.support.retrofit.Retrofit2ConverterFactory$RequestBodyConverter: can't find superclass or interface retrofit2.Converter
Warning: okhttp3.internal.cache.DiskLruCache$Snapshot: can't find referenced class javax.annotation.Nullable
Warning: okhttp3.internal.connection.RealConnection: can't find referenced class javax.annotation.Nullable
Warning: okhttp3.internal.http.RealResponseBody: can't find referenced class javax.annotation.Nullable
Warning: okhttp3.internal.http.RealResponseBody: can't find referenced class javax.annotation.Nullable
Warning: okhttp3.internal.platform.AndroidPlatform: can't find referenced class javax.annotation.Nullable
Warning: okhttp3.internal.platform.ConscryptPlatform: can't find referenced class org.conscrypt.OpenSSLProvider
Warning: okhttp3.internal.platform.ConscryptPlatform: can't find referenced class org.conscrypt.OpenSSLProvider
Warning: okhttp3.internal.platform.ConscryptPlatform: can't find referenced class org.conscrypt.Conscrypt
Warning: okhttp3.internal.platform.ConscryptPlatform: can't find referenced class org.conscrypt.Conscrypt
Warning: okhttp3.internal.platform.ConscryptPlatform: can't find referenced class org.conscrypt.Conscrypt
Warning: okhttp3.internal.platform.ConscryptPlatform: can't find referenced class org.conscrypt.Conscrypt
Warning: okhttp3.internal.platform.ConscryptPlatform: can't find referenced class org.conscrypt.Conscrypt
Warning: okhttp3.internal.platform.ConscryptPlatform: can't find referenced class org.conscrypt.Conscrypt
Warning: okhttp3.internal.platform.ConscryptPlatform: can't find referenced class org.conscrypt.Conscrypt
Warning: okhttp3.internal.platform.ConscryptPlatform: can't find referenced class org.conscrypt.Conscrypt
Warning: okhttp3.internal.platform.ConscryptPlatform: can't find referenced class org.conscrypt.Conscrypt
Warning: okhttp3.internal.platform.ConscryptPlatform: can't find referenced class javax.annotation.Nullable
Warning: okhttp3.internal.platform.Jdk9Platform: can't find referenced class javax.annotation.Nullable
Warning: okhttp3.internal.platform.JdkWithJettyBootPlatform: can't find referenced class javax.annotation.Nullable
Warning: okhttp3.internal.platform.Platform: can't find referenced class javax.annotation.Nullable
Warning: okhttp3.internal.ws.RealWebSocket: can't find referenced class javax.annotation.Nullable
Warning: okhttp3.package-info: can't find referenced class javax.annotation.ParametersAreNonnullByDefault
Warning: okio.AsyncTimeout: can't find referenced class javax.annotation.Nullable
Warning: okio.AsyncTimeout: can't find referenced class javax.annotation.Nullable
Warning: okio.AsyncTimeout: can't find referenced class javax.annotation.Nullable
Warning: okio.AsyncTimeout: can't find referenced class javax.annotation.Nullable
Warning: okio.Buffer: can't find referenced class javax.annotation.Nullable

amazing

what fuck
什么鬼,这是在编译reslese版本的时候出现的警告错误,于是就开始填坑了。首先我怀疑的是我的混淆-keep代码没有加入 but

-keepattributes *Annotation*
-keepattributes Signature
-dontwarn com.alibaba.fastjson.**
-keep class com.alibaba.fastjson.**{*; }

-keep class com.squareup.okhttp.** { *;}
-dontwarn com.squareup.okhttp.**
-dontwarn okio.**

-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**

黑人问号脸????????
难道是引入第三方jar 包时冲突了???不应该呀。。。。。于是开始填坑
首先划重点 can’t find superclass or interface 于是我去Google了一下在官网看到了如下描述大意就是缺失的类对应用运行是否存在影响如果没有影响可以直接忽略警告。。。。 这。。。说了和没说一样 。

Warning: can’t find superclass or interface
Warning: can’t find referenced class
A class in one of your program jars or library jars is referring to a class or interface that is missing from the input. The warning lists both the referencing class(es) and the missing referenced class(es). There can be a few reasons, with their own solutions:

If the missing class is referenced from your own code, you may have forgotten to specify an essential library. Just like when compiling all code from scratch, you must specify all libraries that the code is referencing, directly or indirectly. If the library should be processed and included in the output, you should specify it with -injars, otherwise you should specify it with -libraryjars.

For example, if ProGuard complains that it can’t find a java.lang class, you have to make sure that you are specifying the runtime library of your platform. For JSE, these are typically packaged in lib/rt.jar (vm.jar for IBM’s JVM, and classes.jar in MacOS X). Other platforms like JME and Android have their own runtime libraries. The examples section provides more details for the various platforms.

If ProGuard still complains that it can’t find a javax.crypto class, you probably still have to specify jce.jar, next to the more common rt.jar.
If the missing class is referenced from a pre-compiled third-party library, and your original code runs fine without it, then the missing dependency doesn’t seem to hurt. The cleanest solution is to filter out the referencing class or classes from the input, with a filter like “-libraryjars mylibrary.jar(!somepackage/SomeUnusedReferencingClass.class)”. ProGuard will then skip this class entirely in the input, and it will not bump into the problem of its missing reference. However, you may then have to filter out other classes that are in turn referencing the removed class. In practice, this works best if you can filter out entire unused packages at once, with a wildcard filter like “-libraryjars mylibrary.jar(!someunusedpackage/**)”.

If you don’t feel like filtering out the problematic classes, you can try your luck with the -ignorewarnings option, or even the -dontwarn option. Only use these options if you really know what you’re doing though.
android The standard Android build process automatically specifies the input jars for you. Unfortunately, many pre-compiled third-party libraries refer to other libraries that are not actually used and therefore not present. This works fine in debug builds, but in release builds, ProGuard expects all libraries, so it can perform a proper static analysis. For example, if ProGuard complains that it can’t find a java.awt class, then some library that you are using is referring to java.awt. This is a bit shady, since Android doesn’t have this package at all, but if your application works anyway, you can let ProGuard accept it with “-dontwarn java.awt.**”, for instance.

If the missing class is an Android runtime class, you should make sure that you are building against an Android runtime that is sufficiently recent. You may need to change the build target in your project.properties file or build.gradle file to that recent version. You can still specify a different minSdkVersion and a different targetSdkVersion in your AndroidManifest.xml file.

左想右想还是没想明白,代码也没有搞错,程序debug模式下也是正常运行的,难道我混淆文件没有生效???说干就干撸起袖子加油干。。。。
我把子module的所以混淆代码全部情况,打包!!!!
竟然 ,竟然 除了新功能以外其他功能一切正常,哦滴神那。。。。
⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇

//这行代码 表示获得混淆文件的默认路径,前面的proguard-android.txt 是系统默认的不需要管,
//后面的就是咱们自己定义的混淆规则,but 这行代码应该是在主module中添加是生效的子module 
//是不起作用的下
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
so 
子module模块下的应该 用这句话 consumerProguardFiles 'proguard-rules.pro'

参考官网给出的提示: https://developer.android.com/studio/projects/android-library

至此结束战斗,因为项目之前是外包的所以没出问题就一直没有去看 表示很难受。。。。。

你可能感兴趣的:(android)