文件结构和ant脚本库天天改个没完。之前整理好的build.xml又不认了,必须要 "android update project --path ."一下,然后告诉我不能合并修改,faint。
想想现在ProGuard集成的很好了,就把之前直接写在build.xml里的任务趁机移出来了,然后死活都有错,一看:
[proguard] Reading program jar [bin/proguard/original.jar]
[proguard] Reading program jar [libs/AdWhirlSDK_Android.jar]
[proguard] Reading program jar [libs/GoogleAdView.jar]
[proguard] Reading program jar [libs/admob-sdk-android.jar]
倒,后三个是第三方的库嘛,各种can't find referenced。加了-libraryjars也不认,仔细一看:
~android-sdk/tools/ant/build.xml
-injars ${project.jars}
...
<path id="project.jars.ref">
<pathelement location="${preobfuscate.jar.file}" />
<path refid="jar.libs.ref" />
</path>
丫就不能不自做聪明?<!-- path refid="jar.libs.ref" / -->,自己加-libraryjars就爽了,不过改SDK系统文件,很不方便切换机器以及团队合作唉。
注:光改这一出不够,否则后面dex阶段不会把libs/*.jar打包进去。
-release-obfuscation-check 会定义 <path id="out.dex.jar.input.ref" />
而 dex-helper 则有这么一段
<if>
<condition>
<isreference refid="out.dex.jar.input.ref" />
</condition>
<else>
<path id="out.dex.jar.input.ref">
<path refid="jar.libs.ref" />
</path>
</else>
</if>
得把这个if也干掉。
从好的方面想,这样可以让库文件自动享受ProGuard的功能,不过我还是喜欢能够自己选择。
省事一点的办法,还是改proguard.cfg,不过suppress warning好有罪恶感呀。
# ProGuard in Android SDK includes these jars as program jars.
-dontwarn com.adwhirl.**
-dontnote com.adwhirl.**
-keep class com.adwhirl.** { *;}
-keep public class com.adwhirl.adapters.AdMobAdapter {*;}
-keep public class com.adwhirl.adapters.ZestAdzAdapter {*;}
-keep public class com.adwhirl.adapters.MillennialAdapter {*;}
-keep public class com.admob.android.ads.** {*;}
-keep public class com.millennialmedia.android.** {*;}
-keep public class com.zestadz.android.** {*;}
#ProGuard library jars trick over