Androidã¨ã»ãã¥ãªãã£ï¼ããã°ã©ã é£èªåãã¼ã« - ProGuard
ã¯ããã«
ãã®ã¨ã³ããªã§ã¯ãAndroidã¢ããªã¨ããç¥ç財ç£ãå®ãæ¹æ³ã®ä¸ã¤ã¨ãã¦ãé£èªåãã¼ã«ã§ããProGuardãç´¹ä»ããå®éã«Androidã¢ããªã«çµã¿è¾¼ãæ¹æ³ã示ãã¾ãã
ã½ããã¦ã§ã¢ã®ä¾¡å¤
ã½ããã¦ã§ã¢ã§ã¯å¦çã®æµãï¼ã¢ã«ã´ãªãºã ï¼ãè¨è¿°ããã½ã¼ã¹ã³ã¼ãã大ããªä¾¡å¤ãæã¤ãããï¼ç¹ã«åç¨ã®ã½ããã¦ã§ã¢ã¯ï¼ã½ã¼ã¹ã³ã¼ããéå ¬éã¨ããã³ã³ãã¥ã¼ã¿ã§å®è¡å¯è½ãªå¿ è¦æå°éã®ä¸éã³ã¼ãããã¤ãã£ãã³ã¼ãã«éã£ã¦é å¸ãããã¨ã§ãã½ããã¦ã§ã¢ãã¸ãã¹ãæç«ããã¦ãã¾ããã¤ã¾ããå¦çã®æµãããé ãããã¨ã«ããããã®ä¼ç¤¾ï¼ãããã¯äººï¼ã«ãã解決ã§ããªãã¨ãããæ å ±ã«å¯¾ããä»å 価å¤ããä¸ããã½ããã¦ã§ã¢ãã¸ãã¹ãæç«ããã¦ããã¨è¨ãã¾ããä¸æ¹ã§ãä½ããã®å½¢ã§ãã®ãé ããé¨åããæããã«ãªãç½æ¥ã®ä¸ã«æãããã¨ãé¡ä¼¼ããã½ããã¦ã§ã¢ãæµéãããªã©ããã¯ãå¦çã®æµãã¨ããæ å ±ã¨ãã¦ã®ã価å¤ãã¯å¤±ããããã¸ãã¹ã¨ãã¦æç«ããªããªãã¾ãã
ãã¦ãAndroidã«éãããæè¿ã®ã½ããã¦ã§ã¢ã¯é«ç´è¨èªï¼Javaãªã©ï¼ãç¨ãã¦è¨è¿°ããã翻訳ï¼ã³ã³ãã¤ã«ï¼ãéãã¦æçµçã«ã¯ã³ã³ãã¥ã¼ã¿ãå¦çå¯è½ãªãä¸éã³ã¼ãããããã¤ãã£ãã³ã¼ããã«å¤æããã¾ãããã®å¤æã¯è¨èªãã¨ã«å®ãããããææ³ãã«ãã£ã¦ç¿»è¨³ãããããããã®ç¿»è¨³ã«ã¼ã«ããå¤ãã°é翻訳ï¼ãã³ã³ãã¤ã«ããã¢ã»ã³ãã«ã¨è¨ãã¾ãï¼ãå¯è½ã§ããã¤ã¾ãããä¸éã³ã¼ãããããã¤ãã£ãã³ã¼ããããé翻訳ãè¡ãã人éãç解å¯è½ãªã½ã¼ã¹ã³ã¼ããçæãããã¨ãå¯è½ã¨ãããã¨ã§ãã
ãã®ã¾ã¾ã§ã¯ãã¡ãã£ã¨ããç¥èãããã°ã½ã¼ã¹ã³ã¼ããæ¨æ¸¬ããã¦ãã¾ãã¾ãããã®çºãåç¨ã½ãããªã©ã§ã¯é£èªåãè¡ããé翻訳ãããå ´åã§ãã½ã¼ã¹ã³ã¼ããèªã¿ã«ãããããªã©ãã¦ãç°¡åã«å¦çã®æµããæããã«ãªããªãããã«å¯¾çãã¦ãã¾ãã
é£èªåã¨ã¯
å ã«è¨ããéããé£èªåã¨ã¯ãã½ã¼ã¹ã³ã¼ããèªã¿ã«ãããããã¨ãã§ããé£èªåã®ææ³ã¯æ§ã ããã¾ãããä¸è¨ã®ãããªæ¹æ³ã«ãã£ã¦ã翻訳æã«ã½ã¼ã¹ã³ã¼ããå¯è½ãªéãèªã¿ã«ãããã¾ãã
- ã¯ã©ã¹ãã¡ã½ãããå¤æ°åãçç¥ã»ç¡æå³å
- ã³ã¡ã³ãã®åé¤
- 空ç½ï¼è¡ï¼ã®åé¤
ã¾ãã翻訳æã«å¦çããã©ã¼ãã³ã¹ãè¯ããªãããã«å¦çã®æé©åï¼ç¹°ãè¿ãå¦çã®ç°¡ç¥åãé¢æ°ã»ã¡ã½ããã®ã¤ã³ã©ã¤ã³åçï¼ãè¡ããã¾ããããã®çµæã人éã«ã¨ã£ã¦ç解ãå°é£ãªã³ã¼ãã¨ãªããã¨ãããã¾ãã
Androidã®é£èªåãã¼ã«
Androidã®ãã«ãããã»ã¹ã«ãé©ç¨å¯è½ãªé£èªåãã¼ã«ãåå¨ãã¾ãããã®åããProGuardãã
ProGuardã¯ãJavaã®ã¯ã©ã¹ãã¡ã¤ã«ã®å§ç¸®ã»é£èªåã»æé©åã»åæ¤è¨¼ãè¡ããã¼ã«ã§ãã使ããã¦ããªãã¯ã©ã¹/ã¡ã½ãã/å¤æ°ãæ¤ç¥ã»åé¤ãããããã¤ãã³ã¼ããæé©åããããã¯ã©ã¹ãã¡ã½ããåãç¡æå³åããããã¾ããProGuardã¯ä¸è¬çãªAndroidã¢ããªã±ã¼ã·ã§ã³éçºã«ç¨ããããEclipseã§ã¯ãªããCUIãã¼ã¹ã®ãã«ããã¼ã«ãAntãã«çµ±åãããå½¢ã§å©ç¨ã§ãã¾ããAntã«ãã£ã¦ãAndroidã¢ããªã±ã¼ã·ã§ã³ã®ç¿»è¨³ãé£èªåã¯ãã¡ãããã¢ããªã±ã¼ã·ã§ã³ã®ç½²åã端æ«ã¸ã®ã¤ã³ã¹ãã¼ã«ãèªååãããã¨ãã§ãã¾ãã
ProGuardã®æ¦è¦
å¼ç¨ï¼http://proguard.sourceforge.net/manual/introduction.html
ProGuardã¯ãjar/war/zip/ãã£ã¬ã¯ããªãªã©ãå
¥åã¨ãã¦ã次ã®4ã¤ã®ã¹ããããçµã¦ãæçµçã«jar/war/zip/ãã£ã¬ã¯ããªã¸å¦ççµæãåºåãã¾ãã
- å§ç¸®ã¹ããã(shrink)
- æé©åã¹ããã(optimize)
- é£èªåã¹ããã(obfuscate)
- åæ¤è¨¼ã¹ããã(preverify)
å§ç¸®ã¹ãããã§ã¯ãããã°ã©ã ä¸ã®å©ç¨ããã¦ããªãã¯ã©ã¹ãã¡ã½ããçãåãé¤ãã¾ãããã®ã¹ãããã¯å帰çã«å¦çãããã®ã§ãå
¨ã¦ã®ã¯ã©ã¹ã»ã¡ã½ããã対象ã¨ãªãã¾ãã
æé©åã¹ãããã§ã¯ãã¨ã³ããªãã¤ã³ãã§ã¯ãªãã¯ã©ã¹ãã¡ã½ãããprivate/static/finalå±æ§ã«å¤æã使ããã¦ããªããã©ã¡ã¼ã¿ã¯åé¤ãããä¸é¨ã®ã¡ã½ããã¯ã¤ã³ã©ã¤ã³åããã¾ãã
é£èªåã¹ãããã§ã¯ãã¨ã³ããªãã¤ã³ãã§ã¯ãªãã¯ã©ã¹ãã¡ã½ããã®ååãå¤æ´ãã¾ããã¨ã³ããªãã¤ã³ãã¨ãªãã¯ã©ã¹ãã¡ã½ããã¯ããªãªã¸ãã«ã®ååã§ã¢ã¯ã»ã¹ã§ããããã«ããããã«å¤æ´ããã¾ããã
åæ¤è¨¼ã¹ãããã§ã¯ãå®è¡æã»ãã¼ãæã®ãã¤ãã³ã¼ãã®æ¤è¨¼è² è·ãæ¸ããããã«ããããããåæ
å ±ã調æ»ãããã®æ
å ±ãã¯ã©ã¹ãã¡ã¤ã«å
ã«æ·»ä»ãã¾ããAndroid(Java6)ã§ã¯ä½¿ç¨ãã¾ããã
éçºããããã°ã©ã ã¯å¤é¨ããæä¾ãããã©ã¤ãã©ãªã使ç¨ãããã¨ãããã¾ããããããã¯ProGuardã®å¦çã®å¯¾è±¡å¤ã¨ãªãã¾ãã
ProGuardã®é©ç¨
ããã§ã¯ã以ä¸ã§ã¯Androidã®ããã¸ã§ã¯ãã«ProGuardãé©ç¨ããé£èªåï¼æé©åãè¡ãæ¹æ³ã«ã¤ãã¦èª¬æãã¾ãããã
ã·ã¹ãã è¦ä»¶
Androidã®ããã¸ã§ã¯ãã«ProGuardãé©ç¨ããå ´åã次ã®æ¡ä»¶ãæºããã¦ããå¿ è¦ãããã¾ãï¼
- Android SDKãã¤ã³ã¹ãã¼ã«ããã¦ãããã¨
- Android SDK Toolsãã¤ã³ã¹ãã¼ã«ããã¦ãã¦ãå°ãªãã¨ããªãã¸ã§ã³7以ä¸ã§ãããã¨
- Apache Ant 1.6.5以ä¸(Linux and Mac)/1.7以ä¸(Windows)ãï¼Eclipseä»å±ã®ãã®ã使ãããææ°ã®Antãå¥éã¤ã³ã¹ãã¼ã«ãããã¨ãæã¾ããã
Android SDK Tools Rev.7ã«ã¯ãããªã³ã³ãã¤ã«ã¾ãã¯ã³ã³ãã¤ã«æã®ã¦ã¼ã¶ã¼å®ç¾©å¦çããµãã¼ãããããã¯ãå«ããAntãã«ãã«ã¼ã«ãã¡ã¤ã«ãå梱ããã¦ãã¾ãã
ãµã³ãã«ããã¸ã§ã¯ã
ä»åã®ãµã³ãã«ã¯ä¸è¨ã®ãããªæ¯è¼çã·ã³ãã«ãªå¦çãå«ã¿ã¾ããã½ã¼ã¹ã³ã¼ãä¸ã«ã¯ç¡æå³ãªå¦çãå«ã¾ãã¾ãããProGuardã®é©ç¨ç¶æ ãå¤ãããã«ããããã®ãã®ã§ããããã§ã¯å¦çã®å 容ã«æ³¨ç®ããå¿ è¦ã¯ããã¾ããã
ããã¸ã§ã¯ãã®ãã¼ã ã /HelloAndroidã¨ãã¾ãããã®ãã¼ã ã¯åèªã®ç°å¢ã«åããã¦èªã¿æ¿ãã¦ãã ããã
HelloAndroid/src/test/hello/HelloAndroid.java
package test.hello; import android.app.Activity; import android.os.Bundle; public class HelloAndroid extends Activity { public static final class testClass { testClass() { methodA(1,"str"); } private void methodA(int i, String j) { return; } } /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); testMethod1(); new testClass(); } private void testMethod1() { int i,sum; for( i = 0, sum = 0; i < 10; i++ ) { sum += i; } } }
ãªã½ã¼ã¹ãã¡ã¤ã«çã¯ããã©ã«ãã®ãã®ããã®ã¾ã¾ä½¿ç¨ãã¾ãã
ç½²åãã¼ã®ç¨æ
ProGuardã«ã¯ç´æ¥çã«é¢ä¿ç¡ãããä»åã¯Eclipseã使ç¨ãã¦ãã«ãã»ãããã¤ããªãããããã«ãå¾ã«èªåã§ãããã¤ããããã«äºãç½²åãã¼ãçæãã¦ããã¨ãå¾ã便å©ã§ããæ¢ã«ç½²åãã¼ãç¨æãã¦ããå ´åã¯ãèªã¿é£ã°ãã¦ããã£ã¦æ§ãã¾ããã
$ keytool -genkey -v -keystore release.keystore -alias testhello -keyalg RSA -keysize 4096 -validity 10000 ãã¼ã¹ãã¢ã®ãã¹ã¯ã¼ããå ¥åãã¦ãã ãã: ï¼ãã¹ã¯ã¼ããå ¥åï¼ æ°è¦ãã¹ã¯ã¼ããåå ¥åãã¦ãã ãã: ï¼ããä¸åº¦ãã¹ã¯ã¼ããå ¥åï¼ å§åãå ¥åãã¦ãã ããã [Unknown]: Seto Naoki çµç¹åä½åãå ¥åãã¦ãã ããã [Unknown]: çµç¹åãå ¥åãã¦ãã ããã [Unknown]: Brilliant Service co.,Ltd. é½å¸åã¾ãã¯å°ååãå ¥åãã¦ãã ããã [Unknown]: Tokyo å·åã¾ãã¯å°æ¹åãå ¥åãã¦ãã ããã [Unknown]: ãã®åä½ã«è©²å½ãã 2 æåã®å½çªå·ãå ¥åãã¦ãã ããã [Unknown]: jp CN=Seto Naoki, OU=Unknown, O=Brilliant Service co.,Ltd., L=Tokyo, ST=Unknown, C=jp ã§ããããã§ãã? [no]: yes 10,000 æ¥éæå¹ãª 4,096 ãããã® RSA ã®éµãã¢ã¨èªå·±ç½²åå証ææ¸ (SHA1withRSA) ãçæãã¦ãã¾ã ãã£ã¬ã¯ããªå: CN=Seto Naoki, OU=Unknown, O="Brilliant Service co.,Ltd.", L=Tokyo, ST=Unknown, C=jp <testhello> ã®éµãã¹ã¯ã¼ããå ¥åãã¦ãã ããã (ãã¼ã¹ãã¢ã®ãã¹ã¯ã¼ãã¨åãå ´å㯠RETURN ãæ¼ãã¦ãã ãã): <ãªã¿ã¼ã³ãã¼ãæ¼ã> [release.keystore ãæ ¼ç´ä¸]
ããã¸ã§ã¯ãã®æ´æ°
ä¸è¨ã®ã³ãã³ãã§Antãã«ãã§ããããã«ããã¸ã§ã¯ããæ´æ°ãã¾ãã
cd /HelloAndroid/.. ï¼ããã¸ã§ã¯ããã¼ã ã®ä¸ã¤ä¸ï¼ android update project --path ./HelloAndroid
æ´æ°ããã¨ä¸è¨ã®ãã¡ã¤ã«ãä½æããã¦ããã¯ãã§ãã
- default.properties
- local.properties
- build.properties
- build.xml
ProGuardç¨è¨å®ãã¡ã¤ã«ã®é ç½®
ä¸è¨ã®ãã¡ã¤ã«ãããã¸ã§ã¯ãã®ãã¼ã ã«é ç½®ãã¾ãããããã®ãã¡ã¤ã«ã¯オフィシャルブログããããã¦ã³ãã¼ãã§ãã¾ãã
- add-proguard-release.xml
- procfg.txt
/HelloAndroid/add-progurad-release.xml
<!-- Proguard Properties --> <property name="obfuscate.dir" value="obf" /> <property name="obfuscate.absolute.dir" location="${obfuscate.dir}" /> <property name="android-jar-preobfuscate" value="${obfuscate.absolute.dir}/original.jar" /> <property name="android-jar-postobfuscate" value="${obfuscate.absolute.dir}/postobf.jar" /> <property name="out.dex.input.absolute.dir" value="${android-jar-postobfuscate}" /> <!-- replaces the post-compile step from ant_rules_r3 --> <target name="-post-compile" depends="-dex-obfuscate,-dex-no-obfuscate"> </target> <target name="-dex-no-obfuscate" unless="build.mode.release"> <mkdir dir="${obfuscate.absolute.dir}" /> <jar basedir="${out.classes.dir}" destfile="${android-jar-postobfuscate}" /> </target> <!-- Converts this project's .class files into .dex files --> <target name="-dex-obfuscate" if="build.mode.release"> <property name="proguard-jar" value="${proguard.dir}/proguard.jar" /> <property name="proguard-conf.dir" value="" /> <property name="proguard-conf.absolute.dir" location="${proguard-conf.dir}" /> <property name="proguard-conf" value="${proguard-conf.absolute.dir}/procfg.txt" /> <path id="fullclasspath"> <path refid="android.target.classpath"/> <pathelement path="${external.libs.dir}"/> </path> <property name="libraryjarpath" refid="fullclasspath"/> <!-- Add Proguard Task --> <taskdef resource="proguard/ant/task.properties" classpath="${proguard-jar}" /> <mkdir dir="${obfuscate.absolute.dir}" /> <delete file="${android-jar-preobfuscate}"/> <delete file="${android-jar-postobfuscate}"/> <jar basedir="${out.classes.dir}" destfile="${android-jar-preobfuscate}" /> <proguard> @${proguard-conf} -injars ${android-jar-preobfuscate} -outjars ${android-jar-postobfuscate} -libraryjars ${libraryjarpath} -dump ${obfuscate.absolute.dir}/dump.txt -printseeds ${obfuscate.absolute.dir}/seeds.txt -printusage ${obfuscate.absolute.dir}/usage.txt -printmapping ${obfuscate.absolute.dir}/mapping.txt </proguard> </target>
ãã®ãã¡ã¤ã«ã§ã¯ãAntã§ProGuardã使ç¨ããéã®ãã©ã¡ã¼ã¿ï¼åºåå ãã£ã¬ã¯ããªãªã©ï¼ã®å®ç¾©ãant_rules_r3ã§å®ç¾©ãããAntã®ããªã³ã³ãã¤ã«ã«ã¼ã«ã®æ¸ãæããAntç¨ProGuardã¿ã¹ã¯ã®è¿½å ã®å®ç¾©ãªã©ãè¡ãã¾ãã
/HelloAndroid/procfg.txt
-optimizationpasses 5 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontpreverify -verbose -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* -keep public class * extends android.app.Activity -keep public class * extends android.app.Application -keep public class * extends android.app.Service -keep public class * extends android.content.BroadcastReceiver -keep public class * extends android.content.ContentProvider -keep public class com.android.vending.licensing.ILicensingService -keepclasseswithmembernames class * { native <methods>; } -keepclasseswithmembernames class * { public <init>(android.content.Context, android.util.AttributeSet); } -keepclasseswithmembernames class * { public <init>(android.content.Context, android.util.AttributeSet, int); } -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }
ããã§ã¯æé©åã®è¨å®ãé£èªåãããªãè¨å®(-keep*)ãè¡ã£ã¦ãã¾ãããã«ãã¨ã©ã¼ãçºçããå ´åãè¨å®ãå¤æ´ããå¿
è¦ãããã¾ãããã®è¾ºãã®ãã¯ããã¯ã¯ä»¥ä¸ã®ãµã¤ããåèã«ãªãã¾ãã
http://d.hatena.ne.jp/hyoromo/20101120/1290216449
ãã«ãè¨å®ãã¡ã¤ã«ã®ä¿®æ£
build.propertiesã¨build.xmlãæ¹ä¿®ãã¦ProGuardã«å¯¾å¿ããã¾ãã
/HelloAndroid/build.properties
æ¨æºã®è¨å®ãã¡ã¤ã«ã«ãä¸è¨ã®è¨å®ã追å ãã¾ãã
- èªåãããã¤ã®ãªãã·ã§ã³è¨å®(12ã16è¡ç®)
- èªåç½²åã®è¨å®(18ã26è¡ç®)
- ProGuardã®æå¹å(33è¡ç®)
01 : # This file is used to override default values used by the Ant build system. 02 : # 03 : # This file must be checked in Version Control Systems, as it is 04 : # integral to the build system of your project. 05 : 06 : # This file is only used by the Ant script. 07 : 08 : # You can use this to override default values such as 09 : # 'source.dir' for the location of your java source folder and 10 : # 'out.dir' for the location of your output folder. 11 : 12 : #-d:device/-e:emulator 13 : adb.device.arg= 14 : 15 : #adb install <option> 16 : adb.install.option=-r 17 : 18 : # You can also use it define how the release builds are signed by declaring 19 : # the following properties: 20 : # 'key.store' for the location of your keystore and 21 : # 'key.alias' for the name of the key to use. 22 : # The password will be asked during the build when you use the 'release' target. 23 : key.store=<ãã¼ã¹ãã¢ã®ãã¡ã¤ã«ãã¹ï¼ãã¡ã¤ã«åå«ãï¼> 24 : key.store.password=<ãã¼ã¹ãã¢ã®ãã¹ã¯ã¼ã> 25 : key.alias=<ãã¼çææã«æå®ããã¨ã¤ãªã¢ã¹> 26 : key.alias.password=<ã¨ã¤ãªã¢ã¹ã®ãã¹ã¯ã¼ã> 27 : 28 : # The name of your application package as defined in the manifest. 29 : # Used by the 'uninstall' rule. 30 : application.package=test.hello 31 : 32 : # For ProGuard 33 : proguard.dir=<ProGuardã®libãã£ã¬ã¯ããªã¾ã§ã®ãã¹>
proguard.dirã¯
/HelloAndroid/build.xml
æ¨æºã®è¨å®ãã¡ã¤ã«ã«ãä¸è¨ã®è¨å®ã追å ãã¾ãã
- ProGuardç¨è¨å®XMLãã¡ã¤ã«ã®èªã¿è¾¼ã¿ï¼2ã6è¡ç®ï¼
- ã¢ããªã±ã¼ã·ã§ã³ã¸ã®èªåç½²åã¨ãããã¤ã¿ã¹ã¯ã®å®ç¾©ï¼88ã103è¡ç®ï¼
01 : <?xml version="1.0" encoding="UTF-8"?> 02 : <!DOCTYPE project [ 03 : <!ENTITY add-proguard-release SYSTEM "add-proguard-release.xml"> 04 : ]> 05 : <project name="HelloAndroid" default="help"> 06 : &add-proguard-release; 07 : 08 : <!-- The local.properties file is created and updated by the 'android' 09 : tool. 10 : It contains the path to the SDK. It should *NOT* be checked into 11 : Version Control Systems. --> 12 : <property file="local.properties" /> 13 : 14 : <!-- The build.properties file can be created by you and is never touched 15 : by the 'android' tool. This is the place to change some of the 16 : default property values used by the Ant rules. 17 : Here are some properties you may want to change/update: 18 : 19 : source.dir 20 : The name of the source directory. Default is 'src'. 21 : out.dir 22 : The name of the output directory. Default is 'bin'. 23 : 24 : Properties related to the SDK location or the project target should 25 : be updated using the 'android' tool with the 'update' action. 26 : 27 : This file is an integral part of the build system for your 28 : application and should be checked into Version Control Systems. 29 : 30 : --> 31 : <property file="build.properties" /> 32 : 33 : <!-- The default.properties file is created and updated by the 'android' 34 : tool, as well as ADT. 35 : This file is an integral part of the build system for your 36 : application and should be checked into Version Control Systems. --> 37 : <property file="default.properties" /> 38 : 39 : <!-- Custom Android task to deal with the project target, and import the 40 : proper rules. 41 : This requires ant 1.6.0 or above. --> 42 : <path id="android.antlibs"> 43 : <pathelement path="${sdk.dir}/tools/lib/anttasks.jar" /> 44 : <pathelement path="${sdk.dir}/tools/lib/sdklib.jar" /> 45 : <pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" /> 46 : </path> 47 : 48 : <taskdef name="setup" 49 : classname="com.android.ant.SetupTask" 50 : classpathref="android.antlibs" /> 51 : 52 : <!-- extension targets. Uncomment the ones where you want to do custom work 53 : in between standard targets --> 54 : <!-- 55 : <target name="-pre-build"> 56 : </target> 57 : <target name="-pre-compile"> 58 : </target> 59 : 60 : [This is typically used for code obfuscation. 61 : Compiled code location: ${out.classes.absolute.dir} 62 : If this is not done in place, override ${out.dex.input.absolute.dir}] 63 : <target name="-post-compile"> 64 : </target> 65 : --> 66 : 67 : 68 : <!-- Execute the Android Setup task that will setup some properties 69 : specific to the target, and import the build rules files. 70 : 71 : The rules file is imported from 72 : <SDK>/platforms/<target_platform>/ant/ant_rules_r#.xml 73 : 74 : To customize existing targets, there are two options: 75 : - Customize only one target: 76 : - copy/paste the target into this file, *before* the 77 : <setup> task. 78 : - customize it to your needs. 79 : - Customize the whole script. 80 : - copy/paste the content of the rules files (minus the top node) 81 : into this file, *after* the <setup> task 82 : - disable the import of the rules by changing the setup task 83 : below to <setup import="false" />. 84 : - customize to your needs. 85 : --> 86 : <setup /> 87 : 88 : <!-- èªå.apkçæåã³ã¤ã³ã¹ãã¼ã« --> 89 : <macrodef name="install-release-helper"> 90 : <sequential> 91 : <echo>Installing ${out.release.file}...</echo> 92 : <exec executable="${adb}" failonerror="true"> 93 : <arg line="${adb.device.arg}" /> 94 : <arg value="install" /> 95 : <arg value="${adb.install.option}" /> 96 : <arg path="${out.release.file}" /> 97 : </exec> 98 : </sequential> 99 : </macrodef> 100: 101: <target name="deploy" depends="release"> 102: <install-release-helper /> 103: </target> 104: 105:</project>
ProGuardã®é©ç¨ï¼ãã«ãï¼ã¨ãããã¤
ãã«ãã¨ãããã¤ã¯ç°¡åã§ããã¢ããªãé ç½®ãããããã¤ã¹ãæ¥ç¶ãï¼ã¾ãã¯ãabdã³ãã³ãã§ã·ãã¥ã¬ã¼ã¿ä¸ã«ããã¤ã¹ãä½æãã¦ããã¦ï¼ãä¸è¨ã®ã³ãã³ããå®è¡ãã¾ãã
$ ant deploy
ããã¾ã§ã«ç¤ºããå®ç¾©ãã¡ã¤ã«ã®è¨è¿°ãæ£ãããã°ãProGuardãé©ç¨ãããç¶æ ã§ãã«ããããã¢ããªã¸ã®èªåç½²åãè¡ããã¦ç«¯æ«ã«ã¢ããªãã¤ã³ã¹ãã¼ã«ããã¾ãã
Buildfile: C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\build.xml [setup] Android SDK Tools Revision 7 [setup] Project Target: Google APIs [setup] Vendor: Google Inc. [setup] Platform Version: 1.5 [setup] API level: 3 [setup] [setup] ------------------ [setup] Resolving library dependencies: [setup] ------------------ [setup] Ordered libraries: [setup] ------------------ [setup] [setup] WARNING: No minSdkVersion value set. Application will install on all Android versions. [setup] [setup] Importing rules file: tools\ant\ant_rules_r3.xml -set-release-mode: -dirs: [echo] Creating output directories if needed... [mkdir] Created dir: C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\bin [mkdir] Created dir: C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\gen [mkdir] Created dir: C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\bin\classes -pre-build: -resource-src: [echo] Generating R.java / Manifest.java from the resources... -aidl: [echo] Compiling aidl files into Java classes... -pre-compile: compile: [javac] C:\android-sdk-windows\tools\ant\ant_rules_r3.xml:336: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds [javac] Compiling 2 source files to C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\bin\classes -dex-obfuscate: [mkdir] Created dir: C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\obf [jar] Building jar: C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\obf\original.jar [proguard] ProGuard, version 4.5.1 [proguard] Reading input... [proguard] Reading program jar [C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\obf\original.jar] [proguard] Reading library jar [C:\android-sdk-windows\platforms\android-3\android.jar] [proguard] Reading library jar [C:\android-sdk-windows\add-ons\addon_google_apis_google_inc_3\libs\maps.jar] [proguard] Reading library directory [C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\libs] [proguard] Initializing... [proguard] Note: the configuration refers to the unknown class 'com.android.vending.licensing.ILicensingService' [proguard] Note: there were 1 references to unknown classes. [proguard] You should check your configuration for typos. [proguard] Ignoring unused library classes... [proguard] Original number of library classes: 2398 [proguard] Final number of library classes: 92 [proguard] Printing kept classes, fields, and methods... [proguard] Shrinking... [proguard] Printing usage to [C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\obf\usage.txt]... [proguard] Removing unused program classes and class elements... [proguard] Original number of program classes: 6 [proguard] Final number of program classes: 2 [proguard] Optimizing... [proguard] Number of finalized classes: 0 [proguard] Number of vertically merged classes: 0 (disabled) [proguard] Number of horizontally merged classes: 0 (disabled) [proguard] Number of removed write-only fields: 0 (disabled) [proguard] Number of privatized fields: 0 (disabled) [proguard] Number of inlined constant fields: 0 (disabled) [proguard] Number of privatized methods: 0 [proguard] Number of staticized methods: 2 [proguard] Number of finalized methods: 0 [proguard] Number of removed method parameters: 2 [proguard] Number of inlined constant parameters: 1 [proguard] Number of inlined constant return values: 0 [proguard] Number of inlined short method calls: 0 [proguard] Number of inlined unique method calls: 0 [proguard] Number of inlined tail recursion calls: 0 [proguard] Number of merged code blocks: 0 [proguard] Number of variable peephole optimizations: 0 [proguard] Number of arithmetic peephole optimizations: 0 (disabled) [proguard] Number of cast peephole optimizations: 0 [proguard] Number of field peephole optimizations: 0 [proguard] Number of branch peephole optimizations: 0 [proguard] Number of simplified instructions: 0 [proguard] Number of removed instructions: 21 [proguard] Number of removed local variables: 0 [proguard] Number of removed exception blocks: 0 [proguard] Number of optimized local variable frames: 0 [proguard] Shrinking... [proguard] Removing unused program classes and class elements... [proguard] Original number of program classes: 2 [proguard] Final number of program classes: 2 [proguard] Optimizing... [proguard] Number of finalized classes: 0 [proguard] Number of vertically merged classes: 0 (disabled) [proguard] Number of horizontally merged classes: 0 (disabled) [proguard] Number of removed write-only fields: 0 (disabled) [proguard] Number of privatized fields: 0 (disabled) [proguard] Number of inlined constant fields: 0 (disabled) [proguard] Number of privatized methods: 0 [proguard] Number of staticized methods: 0 [proguard] Number of finalized methods: 0 [proguard] Number of removed method parameters: 0 [proguard] Number of inlined constant parameters: 0 [proguard] Number of inlined constant return values: 0 [proguard] Number of inlined short method calls: 0 [proguard] Number of inlined unique method calls: 0 [proguard] Number of inlined tail recursion calls: 0 [proguard] Number of merged code blocks: 0 [proguard] Number of variable peephole optimizations: 0 [proguard] Number of arithmetic peephole optimizations: 0 (disabled) [proguard] Number of cast peephole optimizations: 0 [proguard] Number of field peephole optimizations: 0 [proguard] Number of branch peephole optimizations: 0 [proguard] Number of simplified instructions: 0 [proguard] Number of removed instructions: 0 [proguard] Number of removed local variables: 0 [proguard] Number of removed exception blocks: 0 [proguard] Number of optimized local variable frames: 0 [proguard] Obfuscating... [proguard] Printing mapping to [C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\obf\mapping.txt]... [proguard] Writing output... [proguard] Preparing output jar [C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\obf\postobf.jar] [proguard] Copying resources from program jar [C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\obf\original.jar] [proguard] Printing classes to [C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\obf\dump.txt]... -dex-no-obfuscate: -post-compile: -dex: [echo] Converting compiled files and external libraries into C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\bin\classes.dex... -package-resources: [echo] Packaging resources [aapt] Creating full resource package... -package-release: [apkbuilder] Creating HelloAndroid-unsigned.apk for release... -release-prompt-for-password: -release-nosign: release: [echo] Signing final apk... [signjar] Signing JAR: C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\bin\HelloAndroid-unsigned.apk to C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\bin\HelloAndroid-unaligned.apk as ky [signjar] ãã¼ã¹ãã¢ã®ãã¹ã¯ã¼ããå ¥åãã¦ãã ãã: [echo] Running zip align on final apk... [echo] Release Package: C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\bin\HelloAndroid-release.apk deploy: [echo] Installing C:\Users\brilliantservice.brilliant_vaio\anttest\HelloAndroid\bin\HelloAndroid-release.apk... [exec] pkg: /data/local/tmp/HelloAndroid-release.apk [exec] Success [exec] 72 KB/s (4211 bytes in 0.057s) BUILD SUCCESSFUL Total time: 8 seconds
-dex-obfuscate:ã®ãã§ã¼ãºã§[proguard]ã®ãã°ãåºåããã¦ããã°ãProGuardãé©ç¨ããã¦ãã¾ãããã°ã詳ããè¦ãã¨ãä¸è¨ã®ããã«å§ç¸®ãæé©åãé£èªåãè¡ããã¦ãããã¨ãåããã¾ãã
- [proguard] Shrinking...
- [proguard] Optimizing...
- [proguard] Obfuscating...
ProGuardé©ç¨åã¨é©ç¨å¾ãæ¯è¼ãã¦ã¿ã
å®éã«ProGuardã®å¦ççµæãæ¯è¼ãã¦ç¢ºèªãã¦ã¿ã¾ãããã
apktoolã«ãããã³ã³ãã¤ã«
ãªã¨ã³ã¸ãã¢ãªã³ã°ãã¼ã«ã§ããandroid-apktoolã使ã£ã¦ã.apkãã¡ã¤ã«ããã³ã³ãã¤ã«ããã¢ããªå
ã®ã¯ã©ã¹æ§æãå¦çå
容ãå¯è¦åãã¾ãã
apktoolã®ã·ã¹ãã è¦ä»¶
apktoolã®ãã¦ã³ãã¼ã
apktoolのダウンロードページãããOSã«å¯¾å¿ãããã¡ã¤ã«ããã¦ã³ãã¼ããã¦ä¸ããã
apktoolã®ã¤ã³ã¹ãã¼ã«
- apktool-install-windows-* ãã¡ã¤ã«ã®ãã¦ã³ãã¼ãï¼Windowsã®å ´åï¼
- apktool-* ãã¡ã¤ã«ã®ãã¦ã³ãã¼ã
- 以ä¸ã®2ã¤ã®ãã¡ã¤ã«ãé©å½ãªãã£ã¬ã¯ããªã«å±éãã¾ãã
ãã³ã³ãã¤ã«ã®å®è¡
$ cd ï¼ããã¸ã§ã¯ããã£ã¬ã¯ããªï¼/bin/ $ apktool d HelloAndroid-release.apk
ãã³ã³ãã¤ã«ã®çµæãHelloAndroid-release.apkã®ãã£ã¬ã¯ããªä»¥ä¸ã«ãHelloAndroid-releaseãã£ã¬ã¯ããªãçæãããä¸è¨ã®ãããªãã¡ã¤ã«ãçæããã¾ãã
- AndroidManifest.xmlï¼ã¢ããªã®ãããã§ã¹ããã¡ã¤ã«
- apktool.ymlï¼apktoolã®å¦ççµæ
- resãã£ã¬ã¯ããªï¼ã¢ããªã«å«ã¾ãããªã½ã¼ã¹ãã¡ã¤ã«
- smaliãã£ã¬ã¯ããªï¼ã¢ããªã®å¦çæé ã®è§£æçµæ
smaliãã¡ã¤ã«ã®æ¯è¼
æé©åãé£èªåããªããã¦ãããã©ããã¯ãsmaliãã£ã¬ã¯ããªãProGuardãé©ç¨ããªãå ´åã¨é©ç¨ããå ´åã¨ã§è¦æ¯ã¹ã¦ã¿ããã¨ã§å¤ãã¾ãã
ProGuardé©ç¨å
ãã¡ã¤ã«æ§æï¼
- HelloAndroid.smali
- HelloAndroid$testClass.smali
- R.smali
- R$attr.smali
- R$layout.smali
- R$string.smali
HelloAndroid.smaliã®å 容ï¼
.class public Ltest/hello/HelloAndroid; .super Landroid/app/Activity; .source "HelloAndroid.java" # annotations .annotation system Ldalvik/annotation/MemberClasses; value = { Ltest/hello/HelloAndroid$testClass; } .end annotation # direct methods .method public constructor <init>()V .locals 0 .prologue .line 6 invoke-direct {p0}, Landroid/app/Activity;-><init>()V .line 8 return-void .end method .method private testMethod1()V .locals 3 .prologue .line 32 const/4 v0, 0x0 .local v0, i:I const/4 v1, 0x0 .local v1, sum:I :goto_0 const/16 v2, 0xa if-ge v0, v2, :cond_0 .line 33 add-int/2addr v1, v0 .line 32 add-int/lit8 v0, v0, 0x1 goto :goto_0 .line 35 :cond_0 return-void .end method # virtual methods .method public onCreate(Landroid/os/Bundle;)V .locals 1 .parameter "savedInstanceState" .prologue .line 23 invoke-super {p0, p1}, Landroid/app/Activity;->onCreate(Landroid/os/Bundle;)V .line 24 const/high16 v0, 0x7f02 invoke-virtual {p0, v0}, Ltest/hello/HelloAndroid;->setContentView(I)V .line 25 invoke-direct {p0}, Ltest/hello/HelloAndroid;->testMethod1()V .line 26 new-instance v0, Ltest/hello/HelloAndroid$testClass; invoke-direct {v0}, Ltest/hello/HelloAndroid$testClass;-><init>()V .line 27 return-void .end method
ProGuardé©ç¨ããªãå ´åãã¢ããªã®ãã¡ã¤ã«æ§æããã®ã¾ã¾è§£æçµæã¨ãã¦åºåãããã¯ã©ã¹ã»ã¡ã½ããã®æ§æãã³ã¼ã«ã·ã¼ã±ã³ã¹ã丸è¦ãã«ãªãã¾ããã¾ããå é¨ã§ä½¿ç¨ãã¦ããã¯ã©ã¹ï¼å é¨ã¯ã©ã¹ãå«ãï¼ãã¡ã½ããåãå¤ããããä½ã®å¦çããã¦ããã®ããäºæ¸¬ããããç¶æ ã§ãã
ProGuardé©ç¨å¾
ãã¡ã¤ã«æ§æï¼
- a.smali
- HelloAndroid.smali
HelloAndroid.smaliã®å 容ï¼
.class public Ltest/hello/HelloAndroid; .super Landroid/app/Activity; # direct methods .method public constructor <init>()V .locals 0 invoke-direct {p0}, Landroid/app/Activity;-><init>()V return-void .end method # virtual methods .method public onCreate(Landroid/os/Bundle;)V .locals 1 invoke-super {p0, p1}, Landroid/app/Activity;->onCreate(Landroid/os/Bundle;)V const/high16 v0, 0x7f02 invoke-virtual {p0, v0}, Ltest/hello/HelloAndroid;->setContentView(I)V new-instance v0, Ltest/hello/a; invoke-direct {v0}, Ltest/hello/a;-><init>()V return-void .end method
a.smaliã®å 容ï¼
.class final Ltest/hello/a; .super Ljava/lang/Object; # direct methods .method constructor <init>()V .locals 0 invoke-direct {p0}, Ljava/lang/Object;-><init>()V return-void .end method
ProGuardãé©ç¨ããã¨ããã¡ã¤ã«æ§æã¯ãã¨ã³ããªãã¤ã³ãã¨ãªãã¯ã©ã¹ãã¡ã¤ã«ãã¨ãé£èªåãããã¯ã©ã¹ãã¡ã¤ã«ãã ãã¨ãªã£ã¦ãããå®éã®ãã¡ã¤ã«æ§æã¨ã¯ç°ãªã£ã¦ãã¾ããã¾ããã¯ã©ã¹ãã¡ã½ããã®è§£æã«å¤±æãã¦ããããã®çµæããå¦çãäºæ¸¬ãããã¨ãé£ãããªã£ã¦ãã¾ãã
ã¾ã¨ã
以ä¸ã®ããã«ProGuardãå©ç¨ããã¨ç°¡åãªæé ã§å®å¹æ§ã®ããé£èªåãè¡ããAndroidã®ã¢ããªã¨ããç¥ç財ç£ãå®ããã¨ãã§ãã¾ããä¸æ¹ã§ãJNIçµç±ã§ãã¤ãã£ãã¡ã½ãããªã©ãå©ç¨ãã¦ããå ´åãProGuardã§ã®ãã«ãã«å¤±æãããªã©ãé©ç¨ã«é¢ããå·¥æ°ãèããå¢å¤§ãããã¨ãããã¾ãï¼ãããããããããå¯è½æ§ãããã¨ãããã¨ï¼ãã¨ã¯ãããã¢ããªä¸ã®ã¢ã«ã´ãªãºã ãæé ãå©ç¨ãã¦ããæè¡ãç¹æ®ã§ããã°ããã»ã©ãProGuardãé©ç¨ããæå³ã¯å¤§ããã§ããããä½ããã®å½¢ã§ã¢ããªä¸ã®ç¥ç財ç£ãå®ãå¿ è¦ãããå ´åã¯ãProGuardã®å©ç¨ãæ¤è¨ãã¦ã¿ã¦ã¯ãããã§ããããã
æ責ï¼æè¡é¨ æ¤ç©å·¥å ´ç 究G ç¬æ¸ ç´å