Androidã«çµ±åãããProGuardã«é¢ããæ¹åç¹(ADT17)
ã¯ããã«
前回の記事ã§ã¯ãADT8ã§æ¨æºæè¼ãããProGuardã®é©ç¨æ¹æ³ã«ã¤ãã¦è§£èª¬ãã¾ãããä»åãADT17ã§ProGuardã®ããã¤ãã®æ¹åãè¡ãããããããããæ¹åç¹ã«ã¤ãã¦è§£èª¬ãã¾ããå°ãæ¬è¨äºã¯ProGuard Improvementsãå ã«ç¿»è¨³ãããã®ã§ãã
ProGuardã¨ã¯
詳細ã¯前々回の記事ãåç
§é ãããã®ã§ãããProGuardãåãã¦ã®æ¹ã®çºã«ç°¡åã«èª¬æãã¾ãã
ProGuardã¯ã½ã¼ã¹ã³ã¼ããã³ã³ãã¤ã«ããéã«å¦çãæé©åããããããã°ã©ã ä¸ã®å¤æ°ãã¡ã½ãããæå³ã®ãªãæååã«ç½®ãæããéã³ã³ãã¤ã«ãããéã«å¦çã®ä¸èº«ããããã«ããããããããããé£èªåããè¡ããã¼ã«ã§ãããã«ããã¼ã«ã§ããAntãEclipseä¸ããç°¡åã«ProGuardã使ããããã«ãªãã¾ããã
ProGuardã®æ¹è¯ç¹
ãã³ãã«ãããã¼ã¸ã§ã³ã4.4ãã4.7ã«ã¢ãããã¼ã
ãã³ãã«ããã¦ãããã¼ã¸ã§ã³ã4.4ãã4.7ã«ãªã£ããã¨ã§ãæ°å¤ãã®ä¸å ·åä¿®æ£åã³æ¡å¼µããªããã¾ãããããã¤ãã®ã¦ã¼ã¶ã¼ãç´é¢ãã¦ãããâerror 1ã§Dalvikãã©ã¼ãããã¸ã®ã³ã³ãã¼ã¸ã§ã³ã«å¤±æãã" ä¸å ·åãä¿®æ£ããã¦ãã¾ããã¾ããå¤ãã® "ãã¹ä¸ã®ã¹ãã¼ã¹" åé¡ã«å¯¾å¿ãã¹ããProGuardã®èµ·åã«é¢ããã³ã¼ãã®æ´æ°ãè¡ãã¾ããã
è¨å®ãã¡ã¤ã«ã®åãæ±ãæ¹æ³ãå¤æ´
ååã®ãªãªã¼ã¹ã¾ã§ã¯ãADT㧠"new Android project" ãä½æãããã¨ãããã¸ã§ã¯ãå ã«ããã©ã«ãã® "proguard.cfg" ãã³ãã¼ããã¦ãã¾ããããã®ãã¡ã¤ã«ã¯Androidã®ProGuardã§ä½¿ç¨ããããã«å¿ è¦ãªæ°ã ã®ã«ã¼ã«ï¼ãAndroidã¨äºææ§ãæããªãæé©åãè¡ããªãããã«ããããã¨ããXMLããåç §ãããã¡ã½ããã®ã¿å§ç¸®ãããªãããã«"keep"ã«ã¼ã«ã追å ããããã¨ãªã©ï¼ãå«ã¾ãã¦ãã¾ãã
ãããæéã¨å ±ã«ãããã©ã«ãã®è¨å®ã¨Android APIã®è¿½å ã«ãã£ã¦çºå±ãã¦ããå¿ è¦ãªã«ã¼ã«ã®åæ¹ã«ãã°ãè¦ã¤ããã¾ãããåé¡ã¯ãä»ãããã¸ã§ã¯ãä¸ã«ã¦ã¼ã¶ãæã®proguard.cfgãã¡ã¤ã«ã®ã³ãã¼ãæã£ã¦ããã¨ãããã¨ã§ããããã¤ãã®æ¢ç¥ã®æªããã¿ã¼ã³ãæ¤ç¥ããlintã«ã¼ã«ãæ°ãã«å ãã¾ããã -- ããããã¦ã¼ã¶ãèªèº«ã®proguardã®è¨å®ãã¡ã¤ã«ãç·¨éãããåç·¨æããå ´åã«ããã®ãã¡ã¤ã«ãç¾å¨ã®æ¨å¥¨ãæºãããææ°ãã©ããããå¤æãããã¨ã¯é常ã«å°é£ã«ãªãã¾ãã
ããã«ãå¤ãã®ã¦ã¼ã¶ã¼ã¯ProGuardã®ããã¥ã¡ã³ããèªãã ããè¨å®ãããã£ãããããã¨ãæã¿ã¾ãã -- å½¼ãã¯ãã¼ã±ããã«ã¢ãããã¼ãããåã«ã¢ããªãå§ç¸®ãããé£èªåããããã ããªã®ã§ãã
ãããã£ã¦ãADT17ã§ã¯è¨å®ãã¡ã¤ã«ãäºã¤ã«åå²ãã¾ããï¼
- Androidã®ããã®"ããã©ã«ã"è¨å®
- Projectç¹æã®ãã©ã°
éè¦ãªãã¤ã³ãã¯ããã«ã¼ã«ã®ããã©ã«ãã»ããã¯ãããããã¸ã§ã¯ãå ã«ã³ãã¼ããå¿ è¦ã¯ãªããã¨ãããã¨ã§ããããã©ã«ãã®ã«ã¼ã«ã»ããã¯ãã¼ã«ã®ä¸ã«ã¤ã³ã¹ãã¼ã«ããï¼ç¹ã« tools/proguard/proguard-android.txtï¼ããããã¯ãã¼ã«ã¨å ±ã«ã¢ãããã¼ãããã¾ãã
èªèº«ã®ã½ã¼ã¹ã³ã¼ãä¸ã«ç¹å®ã®-keepãã©ã°ã追å ããããããªå ´åãããã¸ã§ã¯ãã®ç¹å®ãã©ã°ãProGuardã®è¨å®ã®ãããã¼ã«ã«ã«è¿½å ãããã¨ãå¯è½ã§ããããã©ã«ãã§ã¯ãããã¸ã§ã¯ãã®ã«ã¼ãã«"proguard-project.txt"ã¨ããååã§ä¿åããã¦ãã¾ãããã¡ã¤ã«ã®æ¡å¼µåã.cfgãã.txtã«å¤æ´ããçç±ã¯ãåç´ã«ããããããã¹ããã¡ã¤ã«ã§ãããã¨ãEclipseããã¡ã¤ã«ã¨ãã£ã¿ããããã«ã¯ãªãã¯ããã ãã§å¤æ´ã§ããããã§ãã
注æï¼ä¸è¨ã®å¤æ´ã¯å¿ é ã§ã¯ããã¾ãããããã¾ã§ã®ããã«ãèªèº«ã®ããã¸ã§ã¯ãä¸ã«å®å ¨ãªProGuardã®è¨å®ãè¦å®ãã¦ãããã¨ãä¾ç¶ã¨ãã¦å¯è½ã§ãã
ãããå ¨ã¦ã®ä½æ¥ãè¡ãããã«ãproject.propertiesãã¡ã¤ã«ã®proguard.configããããã£ã®æå³ãå¤æ´ãã¾ãããå¤ããã¼ã¸ã§ã³ã§ã¯ãProGuardã®å§ç¸®ã¨é£èªåãæå¹åããããã«ãproguard.config=<è¨å®ãã¡ã¤ã«ã¾ã§ã®ãã¹ã大æµã¯åç´ã«proguard.cfg> ã¨å®ç¾©ãã¦ãã¾ããã
ADT 17ã§ã¯ãproguard.configããããã£ã¯ï¼è¨å®ãã¡ã¤ã«ã¾ã§ã®ãã¹ï¼ã®ä»£ããã«ãï¼è¨å®ãã¡ã¤ã«ãåå¨ãããã£ã¬ã¯ããªã®ãã¹ï¼ãæå®ãã¾ãããããã£ã¦ãè¨å®ãã¡ã¤ã«ãè¤æ°æå®ãããã¨ãã§ãã¾ãããããã®è¨å®ãã¡ã¤ã«ã¯ProGuardã«ãã£ã¦å ¨ã¦çµåããã¾ããããã©ã«ãã§ã¯ProGuardã¯ãªãã«ãªã£ã¦ãã¾ããã"new projects" ã§ä½æãããproject.propertiesãã¡ã¤ã«ã«ã¯ã以ä¸ã®ãããªã³ã¡ã³ãã®ãããã¯ãå«ã¾ãã¦ãã¾ãï¼
# To enable ProGuard to shrink and obfuscate your code, uncomment this #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
ï¼ããã¸ã§ã¯ããã¡ã¤ã«ä¸ã®çµ¶å¯¾ãã¹ãé¿ããããã«ã${sdk.dir}ã${user.home}ãããããã¹ä¸ã«å«ãããã¨ãã§ãã¾ããproject.propertiesãã¡ã¤ã«ã¯ããã¼ã¸ã§ã³ç®¡çã®ä¸ã§ç¹ã«ãã§ãã¯ããããããéè¦ã§ããï¼
ãã®ãããé常ã®æ¹æ³ã§ProGuardãæå¹ã«ããããã«ã¯ãä¸è¨ã®è¡ã®ã³ã¡ã³ãã解é¤ããã ãã§ããtoolsãã£ã¬ã¯ããªããå ¨ã¦ã®ããã©ã«ãã®Android ProGuardè¨å®ãã©ã°ãããã¯ã¢ããããã¾ããã¾ãããã¼ã«ã®ãã°ãã£ãã¯ã¹ãAndroidã®å¤æ´ã«ä¼´ãè¨å®ã®ä¸å ·åã®æ´æ°ã¯èªåçã«è¡ããã¾ãã
ProGuardã®è¨å®ãå®å
¨ã«ã³ã³ããã¼ã«ãããå ´åã代ããã«ãã¡ã¤ã«ã«èªèº«ã®è¨å®ãåç´ã«å®ç¾©ããã ãã§è¯ãã§ããProGuardã¯ä¸è¬çã«ãã©ã°ãæ¸ããªããããããã©ã«ãã®ãã©ã°ã®ä¸ã¤ãç¡å¹ã«ãããå ´åã¯ãèªèº«ã®ãã¡ã¤ã«ä¸ã«ã°ãã¼ãã«ãªè¨å®ãã³ãã¼ããç¡å¹ã«ãããè¡ãåãé¤ãå¿
è¦ããããã¨ã«æ³¨æãã¦ãã ããã
ãã®ãããªãã©ã°ã®ä¸ã¤ã¨ãã¦èæ
®ããæ¹ãè¯ããã©ã°ã¯ã-dontoptimizeãã©ã°ã§ãã主ãªçç±ã¨ãã¦ãéçºè
ãå§ç¸®ã¨é£èªåã®é¢ã§ProGuardã使ç¨ããããã§ãï¼ãã¦ã³ãã¼ãã¨å®è¡æéã®ãµã¤ãºãå°ããããã³ã¼ãã®ããã¤ãããã©ã¤ãã¼ãã«ããã·ã³ãã«ã«ããã©ã¼ãã³ã¹ã®ã¡ãªãããããï¼ãDalvikã¯èªèº«ã®æé©åã«å¤ãã®å¦çãè¡ããããã¤ãã¯ProGuardã«ããæé©åã¨äºææ§ãããã¾ããããã®ãããåç¾ãé£ãããã°ï¼ã¨ãããã©ã¼ãã³ã¹å¹æã大æµã¯å°ãããªã£ã¦ãã¾ããã¨ï¼ãé¿ããããã«ãããã©ã«ãã®è¨å®ã§ã¯æé©åãOFFã«ãã¦ãã¾ãã
ããã¦æé©åãå®æ½ãããå ´åã¯ãããã©ã«ãã®ãã¡ã¤ã«ã§ã³ã¡ã³ãã¢ã¦ããããæé©åãã©ã°ããã¼ã«ã«è¨å®ãã¡ã¤ã«ã«ã³ãã¼ãã¦ã注æãã¦ãã¹ããè¡ãããã«ãã¦ä¸ãããã¾ãããã¼ã«ã«ã®è¨å®ã¯å®æçã«ææ°ãã©ããããã§ãã¯ãããã¨ãå¿ããªãããã«ãã¦ä¸ããã
ADT17ä¸ã®ããã©ã«ãè¨å®ãã¡ã¤ã«ãæ´æ°ããããããç´æ¥ãããã使ç¨ãã¦ããªãå ´åãèªèº«ã®ã³ãã¼ã¨æ°ããã³ãã¼ã¨ã®éã§ãèªèº«ã®ã³ãã¼ã«ä½ããã¹ããªããã©ãããæ¯è¼ãããã¨æãããããã¾ãããããã§ãããã¤ãã®ãã©ã°ã説æããããã«ã³ã¡ã³ãã追å ãã¾ããã
æ¢ã«ããããã¸ã§ã¯ãã¸ã®å½±é¿ã¯ï¼
ä¸è¨ã®èª¬æã¯ãå ¨ã¦æ°ããããã¸ã§ã¯ããä½æããå ´åã«ã¤ãã¦ã®ãã®ã§ãããæ¢åã®ããã¸ã§ã¯ãã«å½±é¿ã¯ããã®ã§ããããï¼
å¿é
ã«ã¯åã³ã¾ãããæ¢åã®ããã¸ã§ã¯ãã«ã¯ä¸åæãã¤ãã¦ãã¾ãããå
¨ã¦ã¯ä»æ¥ãä½åãã¤ã¥ãã¾ããèªåçã«ããªãã®ãã©ã°ãå¤æ´ãããã¯ãã¦ãã¾ãããããããå¤ãã®éçºè
ã¯çèãã¦è¨å®ã使ç¨ãã¦ããªãã¨æãã¾ããããã¸ã§ã¯ããä½æããæã«å¾ããã®ããã®ã¾ã¾ä½¿ç¨ãã¦ããããããã¯ææ°ã®è¨å®ã§ã¯ç¡ããã¨ã«æ°ã¥ãã¦ããªãããããã¾ããããã®å
¨ä½çãªåé¡ã«ã¦ã¼ã¶ã¼ãæ°ã¥ãããã«ããã®ã·ããªãªãæ¤ç¥ããæ°ããlintã®ã«ã¼ã«ã追å ãã¾ããï¼
ããããããã¯ãããã©ã«ãã®Androidè¨å®ãã¡ã¤ã«ã¨ãã¼ã«ã«ã®ããã¤ãã®ãã©ã°ã¸ãªã³ã¯ããããã®projetct.propertiesãã¡ã¤ã«ã®ç·¨éæ¹æ³ãåãããããããååãªæ å ±ãå«ãã§ãããããã®lintã«ã¼ã«ã¯è½åçã«ProGuardãæå¹åãã¦ããæã ãããã¯ããããããããã¸ã§ã¯ãä¸ã«ä½ããã¯ãããã使ç¨ããã¦ããªãããã©ã«ãã®proguard.cfgãã¡ã¤ã«ãæããéçºè ãæ©ã¾ãããã¨ã¯ãªãã§ãããã
æå¾ã«ãproguard.configããããã£ã¯ããã¹ãã§ãããã¨ã«æ³¨æãã¦ä¸ããããã®ããããã£ã«ã¯2ã¤ä»¥ä¸ã®ãã¡ã¤ã«ãå®ç¾©ãããã¨ãã§ãã¾ãããã¼ã ãã£ã¬ã¯ããªãåç §ããããã«${user.home}ãã©ã°ã使ç¨ãããã¨ãã§ãã¾ãããããã£ã¦ãä¸ã«ç¤ºããããããª${sdk.dir}ã«ã¯"ã°ãã¼ãã«ãª" Androidã®ããã©ã«ãã${user.home}ä¸ã«ã¯"ã¦ã¼ã¶ãã¨"ã®ãã©ã°ï¼ããã¸ã§ã¯ãéã§å ±æããããã®ï¼ã¨ãã£ãããã«ãããã¸ã§ã¯ãå ã§å®ç¾©ãããå ¨ã¦ã®ãã©ã°ãæã¤ãã¨ãå¯è½ã§ãã
æ責ï¼æè¡é¨ ç¬æ¸ ç´å