用make编译apk过程中在proguard过程中报如下warning,造成编译失败。
Warning: com.android.datetimepicker.date.MonthAdapter: can't find referenced method 'com.android.datetimepicker.date.MonthAdapter$CalendarDay getSelectedDay()' in program class com.android.datetimepicker.date.DatePickerController
Warning: com.android.datetimepicker.date.MonthView: can't find referenced method 'java.util.Calendar getMinDate()' in program class com.android.datetimepicker.date.DatePickerController
Warning: com.android.datetimepicker.date.MonthView: can't find referenced method 'java.util.Calendar getMaxDate()' in program class com.android.datetimepicker.date.DatePickerController
Warning: there were 3 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile the code.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
Error: Please correct the above warnings first.
ninja: build stopped: subcommand failed.
15:00:02 ninja failed with: exit status 1
先说一下proguard:
因为Java代码是非常容易反编码的,况且Android开发的应用程序是用Java代码写的,为了很好的保护Java源代码,我们需要对编译好后的class文件进行混淆。
ProGuard是一个混淆代码的开源项目,它的主要作用是混淆代码,殊不知ProGuard还包括以下4个功能。
压缩(Shrink):检测并移除代码中无用的类、字段、方法和特性(Attribute)。
优化(Optimize):对字节码进行优化,移除无用的指令。
混淆(Obfuscate):使用a,b,c,d这样简短而无意义的名称,对类、字段和方法进行重命名。
预检(Preveirfy):在Java平台上对处理后的代码进行预检,确保加载的class文件是可执行的。
总而言之,根据官网的翻译:Proguard是一个Java类文件压缩器、优化器、混淆器、预校验器。压缩环节会检测以及移除没有用到的类、字段、方法以及属性。优化环节会分析以及优化方法的字节码。混淆环节会用无意义的短变量去重命名类、变量、方法。这些步骤让代码更精简,更高效,也更难被逆向(破解)。
proguard 可以在proguard.flags里面配置,对于jni调用,或者一些类,方法不要混淆。
回到这个问题,从编译报错的信息给了一个网站 http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember,到这个网站查一下对于的报错信息如下:
Warning: can't find referenced field/method '...' in library class ...
A program class is referring to a field or a method that is missing from a library class. The warning lists both the referencing class and the missing referenced class member. Your compiled class files are inconsistent with the libraries. You may need to recompile the class files, or otherwise upgrade the libraries to consistent versions.
按照建议,删除了编译包后还是报同样的错。
通过JD-jui反编译过程中生成的jar包,发现MonthAdapter这个类在源代码里面没有,凭空多出来的一个类。到mk里面确认了一下,datetimepicker这个是直接依赖框架的对应的jar包,但是apk的源代码里面又把部分框架的代码拉到了apk里面参与编译,所以可能是有冲突,删除到apk里面对于的代码,完全依赖框架的包,重新编译,通过!
网友评论