用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開發(fā)的應用程序是用Java代碼寫的运翼,為了很好的保護Java源代碼,我們需要對編譯好后的class文件進行混淆掠械。
ProGuard是一個混淆代碼的開源項目,它的主要作用是混淆代碼,殊不知ProGuard還包括以下4個功能猾蒂。
壓縮(Shrink):檢測并移除代碼中無用的類均唉、字段、方法和特性(Attribute)肚菠。
優(yōu)化(Optimize):對字節(jié)碼進行優(yōu)化舔箭,移除無用的指令。
混淆(Obfuscate):使用a蚊逢,b层扶,c,d這樣簡短而無意義的名稱烙荷,對類镜会、字段和方法進行重命名。
預檢(Preveirfy):在Java平臺上對處理后的代碼進行預檢终抽,確保加載的class文件是可執(zhí)行的戳表。
總而言之,根據(jù)官網(wǎng)的翻譯:Proguard是一個Java類文件壓縮器昼伴、優(yōu)化器匾旭、混淆器、預校驗器圃郊。壓縮環(huán)節(jié)會檢測以及移除沒有用到的類价涝、字段、方法以及屬性描沟。優(yōu)化環(huán)節(jié)會分析以及優(yōu)化方法的字節(jié)碼飒泻。混淆環(huán)節(jié)會用無意義的短變量去重命名類吏廉、變量泞遗、方法。這些步驟讓代碼更精簡席覆,更高效史辙,也更難被逆向(破解)。
proguard 可以在proguard.flags里面配置佩伤,對于jni調(diào)用聊倔,或者一些類,方法不要混淆生巡。
回到這個問題耙蔑,從編譯報錯的信息給了一個網(wǎng)站 http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember,到這個網(wǎng)站查一下對于的報錯信息如下:
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包须揣,發(fā)現(xiàn)MonthAdapter這個類在源代碼里面沒有,憑空多出來的一個類钱豁。到mk里面確認了一下耻卡,datetimepicker這個是直接依賴框架的對應的jar包,但是apk的源代碼里面又把部分框架的代碼拉到了apk里面參與編譯牲尺,所以可能是有沖突卵酪,刪除到apk里面對于的代碼,完全依賴框架的包谤碳,重新編譯溃卡,通過!