äž»ãªãã®ã«ã€ããŠç°¡åã«
- Gradleãã«ãã·ã¹ãã ãšæšæºãããžã§ã¯ãæ§é ã䜿çšãã
- gradle.propertiesãã¡ã€ã«ã«ãã¹ã¯ãŒããšãã®ä»ã®éèŠãªããŒã¿ãä¿åããŸã
- ç¬èªã®HTTPã¯ã©ã€ã¢ã³ããäœæããªãã§ãã ãããVolleyãŸãã¯OkHttpã©ã€ãã©ãªã䜿çšããŠãã ããã
- JacksonããŒã¿ã䜿çšããŠJSONããŒã¿ã解æãã
- Guavaã®äœ¿çšãé¿ããéåžžã¯ç¯çŽããŸã-65kã¡ãœããã®å¶éãè¶ ããªãããã«ããŠãã ãã
- ã¹ããããã䜿çšããŠããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã衚瀺ããŸãã
- ã¢ã¯ãã£ããã£ã䜿çšããŠãã©ã°ã¡ã³ãã®ã¿ã管çãã
- XMLããŒã¯ã¢ããã¯ã³ãŒãã§ãããããæ éã«èšè¿°ããŠãã ãã
- ã¹ã¿ã€ã«ã䜿çšããŠãXMLããŒã¯ã¢ããã§å±æ§ãéè€ããªãããã«ããŸã
- èªã¿ã«ãã1ã€ã®å€§ããªãã¡ã€ã«ãããè€æ°ã®ã¹ã¿ã€ã«ãã¡ã€ã«ã®æ¹ãåªããŠããŸãã
- colors.xmlã®éè€ãé¿ããçãããããã«ããŠãã ãã-äž»ã«ã«ã©ãŒãã¬ãããä¿åãããã
- diameter.xmlã«ã€ããŠãåãããšãèšããããã§åºæ¬çãªå®æ°ã®ã¿ãå®çŸ©ããŸã
- ViewGroupèŠçŽ ã®éå±€ãæ·±ãããããªãã§ãã ãã
- WebViewã®äœ¿çšæã«ã¯ã©ã€ã¢ã³ãåŽã®ãã€ãã³ã°ãé¿ããæŒãã®å¯èœæ§ã«æ³šæããŠãã ãã
- ãŠããããã¹ãã«ã¯RobolectricããUIã®ãã¹ãã«ã¯Robotiumã䜿çšããŸã
- Genymotionããšãã¥ã¬ãŒã¿ãŒãšããŠäœ¿çšãã
- åžžã«ProGuardãŸãã¯DexGuardã䜿çšããŸã
Android SDK
Android SDKãããŒã ãã£ã¬ã¯ããªãŸãã¯ã¢ããªã±ãŒã·ã§ã³ã«é¢ä¿ã®ãªãä»ã®å Žæã«é 眮ããŸãã äžéšã®IDEã¯SDKã«ãã³ãã«ãããŠããããã£ã¬ã¯ããªã«ã€ã³ã¹ããŒã«ã§ããŸãã ããã«ãããIDEãæŽæ°ïŒãŸãã¯åã€ã³ã¹ããŒã«ïŒããããå¥ã®IDEã«åãæ¿ãããããããšãã§ããªããªããŸãã IDEã管çè ã§ã¯ãªããŠãŒã¶ãŒãšããŠå®è¡ããå Žåã管çè ç¹æš©ãå¿ èŠã«ãªãå¯èœæ§ããããããSDKãå¥ã®ã·ã¹ãã ãã£ã¬ã¯ããªã«ã€ã³ã¹ããŒã«ããªãã§ãã ããã
ãã«ãã·ã¹ãã
ããã©ã«ãã®éžæã¯Gradleã§ãã Antã¯æ©èœãã¯ããã«æ§ããã§ããããã®æ瀺ãã³ã³ãã¯ãã§ã¯ãããŸããã Gradleã䜿çšãããšã次ã®ããšãç°¡åã«ã§ããŸãã
- ã¢ããªã±ãŒã·ã§ã³ã®ããŸããŸãªããªãšãŒã·ã§ã³ãšãã«ããäœæãã
- ã¹ã¯ãªãããšããŠç°¡åãªã¿ã¹ã¯ãäœæãã
- äŸåé¢ä¿ã管çããŠèªåçã«ããŠã³ããŒããã
- ããŒã¹ãã¢ãæ§æãã
- ãããŠãä»ã®å€ãã®æçšãªãã®ã
ãŸããAndroidã®Gradleãã©ã°ã€ã³ã¯ããã«ãã·ã¹ãã ã®æ°ããæšæºãšããŠGoogleã«ãã£ãŠç©æ¥µçã«éçºãããŠããããšã«ã泚æããŠãã ããã
ãããžã§ã¯ãæ§é
2ã€ã®äžè¬çãªãªãã·ã§ã³ããããŸãïŒå€ãAntãšEclipse ADTãããžã§ã¯ãæ§é -ãŸãã¯æ°ããGradleãšAndroid Studioã 2çªç®ã®ãªãã·ã§ã³ãéžæããããšããå§ãããŸãã ãããžã§ã¯ãã§å€ãæ§é ã䜿çšããŠããå Žåã¯ã移æ€ããããšããå§ãããŸãã
å€ãæ§é
old-structure ââ assets ââ libs ââ res ââ src â ââ com/futurice/project ââ AndroidManifest.xml ââ build.gradle ââ project.properties ââ proguard-rules.pro
æ°ããæ§é
new-structure ââ library-foobar ââ app â ââ libs â ââ src â â ââ androidTest â â â ââ java â â â ââ com/futurice/project â â ââ main â â ââ java â â â ââ com/futurice/project â â ââ res â â ââ AndroidManifest.xml â ââ build.gradle â ââ proguard-rules.pro ââ build.gradle ââ settings.gradle
äž»ãªéãã¯ãæ°ããæ§é ãæ瀺çã«ããªãœãŒã¹ã»ãããïŒ
main
ã
androidTest
ïŒãå ±æããŠããããšã§ããããã¯Gradleã®æŠå¿µã®1ã€ã§ãã ããšãã°ããã©ã«ããsrcãã«ãã©ã«ããpaidããšãfreeããè¿œå ãããšãã¢ããªã±ãŒã·ã§ã³ã®ææçãšç¡æçã®ãœãŒã¹ã³ãŒããå«ãŸããŸãã
éå±€ã®æäžäœã«
app
ã¢ããªã±ãŒã·ã§ã³ãã©ã«ããŒããããšãã¢ããªã±ãŒã·ã§ã³ã䜿çšããã©ã€ãã©ãªãŒïŒ
library-foobar
ïŒããåé¢ããã®ã«åœ¹ç«ã¡ãŸãã 次ã«ã
settings.gradle
ãã¡ã€ã«ã«ã¯ã
app/build.gradle
ãåç §ã§ãããããã®ã©ã€ãã©ãªãããžã§ã¯ãã®ãªã¹ããæ ŒçŽãããŸãã
Gradleèšå®
äžè¬çãªæ§é ã Googleã®Gradle for Androidã®æ瀺ã«åŸã£ãŠãã ããã
å°èŠæš¡ãªãã«ãã¿ã¹ã¯ã ä»ã®ã¹ã¯ãªããèšèªïŒã·ã§ã«ãPythonãPerlãªã©ïŒãšã¯ç°ãªããGradleã§ãã«ãã¿ã¹ã¯ãäœæã§ããŸãã 詳现ã«ã€ããŠã¯ã Gradleã®ããã¥ã¡ã³ããåç §ããŠãã ããã
ãã¹ã¯ãŒã
build.gradle
ã¢ããªã±ãŒã·ã§ã³
build.gradle
ããªãªãŒã¹ãã«ãã®çœ²åãã©ã¡ãŒã¿ãŒïŒ
signingConfigs
ïŒãå®çŸ©ããå¿ èŠããããŸãã 次ã®ãšã©ãŒã¯åé¿ããå¿ èŠããããŸãã
ããããªãã§ãã ããã ãã®æ å ±ã¯ããŒãžã§ã³ç®¡çã·ã¹ãã ã«è¡šç€ºãããŸãã
signingConfigs { release { storeFile file("myapp.keystore") storePassword "password123" keyAlias "thekey" keyPassword "password789" } }
gradle.properties
ãã¡ã€ã«ãäœæãããšãããŒãžã§ã³ç®¡çã·ã¹ãã ã®å¶åŸ¡äžã§è¿œå ãããªããªããŸãã
KEYSTORE_PASSWORD=password123 KEY_PASSWORD=password789
ãã®ããŒã¿ã¯èªåçã«gradleã«ã€ã³ããŒãããã次ã®ããã«
build.gradle
䜿çšã§ããŸãã
signingConfigs { release { try { storeFile file("myapp.keystore") storePassword KEYSTORE_PASSWORD keyAlias "thekey" keyPassword KEY_PASSWORD } catch (ex) { throw new InvalidUserDataException("You should define KEYSTORE_PASSWORD and KEY_PASSWORD in gradle.properties.") } } }
jarãã¡ã€ã«ãã€ã³ããŒãããã®ã§ã¯ãªããMavenã®äŸåé¢ä¿ã䜿çšããŠãã ããã ãããžã§ã¯ãã«å€éšjarãã¡ã€ã«ãå«ãããšãã€ã³ããŒããçºçããããŒãžã§ã³ïŒ2.1.1ãªã©ïŒã§ä¿æãããŸãã jarãã¡ã€ã«ãæåã§ããŠã³ããŒãããŠæŽæ°ããã®ã¯æéã®ãããæäœã§ãããMavenã¯çµæãã¢ã»ã³ããªã«å«ããããšã§ãã®åé¡ãå®å šã«è§£æ±ºã§ããŸãã äŸïŒ
dependencies { compile 'com.squareup.okhttp:okhttp:2.2.0' compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0' }
åçãªMavenäŸåé¢ä¿ã®äœ¿çšãé¿ããåçã«çæãããããŒãžã§ã³ïŒ
2.1.+
ãªã©ïŒã®æå®ãé¿ãã
2.1.1
ãªã©ã®éçããŒãžã§ã³çªå·ã䜿çšãããšãäºæž¬å¯èœãªåäœã§ããå®å®ãããã«ããäœæã§ããŸãã
éçºç°å¢ïŒIDEïŒããã³ããã¹ããšãã£ã¿ãŒ
奜ã¿ã®ãšãã£ã¿ãŒã䜿çšããŸããããããžã§ã¯ãæ§é ãšã®äºææ§ãååã§ãªããã°ãªããŸããã ãšãã£ã¿ãŒã¯å人çãªéžæã§ããããããžã§ã¯ãæ§é ããã³ãã«ãã·ã¹ãã ã®äžéšãšããŠäœæ¥ããã®ã«äŸ¿å©ãªãšãã£ã¿ãŒãéžæããå¿ èŠããããŸãã
çŸæç¹ã§æã人æ°ã®ããIDEã¯Android Studioã§ããGoogleã«ãã£ãŠéçºãããGradleãšçµ±åãããããã©ã«ãã§æ°ãããããžã§ã¯ãæ§é ã䜿çšããå®å®ããã¢ã»ã³ããªç¶æ ã«ãããAndroidéçºçšã«èª¿æŽãããŠããããã§ãã
Eclipse ADTã¯å¿ èŠã«å¿ããŠäœ¿çšã§ããŸãããå€ããããžã§ã¯ãæ§é ãšAntãã«ãã·ã¹ãã ã§ããã©ã«ãã§æ©èœãããããæ§æããå¿ èŠããããŸãã VimãSublime TextããŸãã¯Emacsããã¹ããšãã£ã¿ãŒã䜿çšããããšãã§ããŸãã ãã®å Žåãã³ãã³ãã©ã€ã³ããGradleãšadbã䜿çšããå¿ èŠããããŸãã Eclipse Gradleãšåéã«ãªããªãå Žåã¯ãã³ãã³ãã©ã€ã³ã䜿çšããŠãã«ãããå¿ èŠããããŸãã ADTãã©ã°ã€ã³ãæè¿å»æ¢ãããããšãèãããšãAndroid Studioã«ã¢ããã°ã¬ãŒãããããšããå§ãããŸãã
䜿çšãããã®ã¯äœã§ããGradleãšæ°ãããããžã§ã¯ãæ§é ã¯å ¬åŒã«æšå¥šãããã¢ããªã±ãŒã·ã§ã³æ§ç¯æ¹æ³ã§ããããšãã£ã¿ãŒäŸåã®æ§æãã¡ã€ã«ãããŒãžã§ã³ç®¡çã·ã¹ãã ã«è¿œå ããªãããšã«æ³šæããŠãã ããã ããšãã°ãAnt
build.xml
ãã¡ã€ã«ãè¿œå ããªãã§ãã ããã ãŸããAntã§ãã«ãæ§æãå€æŽãããšãã¯ã
build.gradle
ãæŽæ°ããããšãå¿ããªãã§ãã ããã äžè¬ã«ãä»ã®éçºè ã«ç°åžžãªããŒã«ã®äœ¿çšã匷å¶ããªãã§ãã ããã
å³æžé€š
Jacksonã¯ããªããžã§ã¯ããJSONã«ããŸãã¯ãã®éã«å€æããããã®Javaã©ã€ãã©ãªã§ãã Gsonã¯ãã®åé¡ã解決ããæãäžè¬çãªæ¹æ³ã§ãããç§ãã¡ã®èŠ³å¯ã«ãããšãJacksonãJSONãåŠçãã代æ¿æ¹æ³ïŒ ã¹ããªãŒãã³ã° ãRAMã®ããªãŒã¢ãã«ãããã³åŸæ¥ã®JSON-POJO圢åŒã®éä¿¡ïŒããµããŒããããããçç£æ§ãåäžããŸãã ãã ãããžã£ã¯ãœã³ã®ãµã€ãºã¯GSONããã倧ãããããGSONã䜿çšããŠ65kã®å¶éãåé¿ããããšããå§ãããŸãã ä»ã®ãªãã·ã§ã³ã¯Json-smartãšBoon JSONã§ãã
ãããã¯ãŒãã³ã°ããã£ãã·ã¥ãããã³ç»åã ç¬èªã®ã¯ã©ã€ã¢ã³ããéçºããåã«èæ ®ããå¿ èŠãããããã¯ãšã³ããµãŒããŒãžã®çç£çãªã¯ãšãªã®ããã®å®èšŒæžã¿ã®ãœãªã¥ãŒã·ã§ã³ãããã€ããããŸãã ãã¬ãŒãŸãã¯ã¬ãããã£ããã䜿çšããŸãã Volleyã¯ãã€ã¡ãŒãžãããŒãããã³ãã£ãã·ã¥ããããã®ããŒã«ãæäŸããŸãã Retrofitãéžæããå Žåãç»åãã¢ããããŒããŸãã¯ãã£ãã·ã¥ããã«ã¯Picassoã䜿çšããå¹ççãªHTTPèŠæ±ãååŸããã«ã¯OkHttpã䜿çšããŸãã ãããã®ã©ã€ãã©ãªïŒRetrofitãPicassoãOkHttpïŒã¯ãã¹ãŠ1ã€ã®äŒç€Ÿã«ãã£ãŠéçºãããŠãããããäºãã«å®å šã«è£å®ãããŸãã OkHttpã¯Volleyã§ã䜿çšã§ããŸãã
RxJavaã¯ããªã¢ã¯ãã£ãããã°ã©ãã³ã°ãã€ãŸãéåæã€ãã³ããåŠçããããã®ã©ã€ãã©ãªã§ãã ããã¯ããã®ç°åžžæ§ãšæ··åãããå¯èœæ§ããã匷åã§ææãªæŠå¿µã§ãã ãã®ã©ã€ãã©ãªãã¢ããªã±ãŒã·ã§ã³å šäœã®ã¢ãŒããã¯ãã£ã®åºç€ãšããŠäœ¿çšããåã«ãæ éã«æ€èšããããšããå§ãããŸãã RxJavaã䜿çšããŠäœæããããããžã§ã¯ãããããTimo TuominenãOlli SalonenãAndre MedeirosãMark VoitãAntti LammiãVera IzrailitãJuha Ristolainenã®ããããããæ¯æŽãæ±ããããšãã§ããŸãã ãã®ããšã«ã€ããŠãããã°ã§ããã€ãã®èšäºãæžããŸããïŒ [1] ã [2] ã [3] ã [4] ã
Rxã䜿çšããããšããªãå Žåã¯ãAPIã䜿çšããŠéå§ããŠãã ããã ãŸãã¯ãã¯ãªãã¯ããŠæ€çŽ¢ãã£ãŒã«ãã«å ¥åãããªã©ã®åçŽãªãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã€ãã³ããåŠçããããã«äœ¿çšããããšããéå§ã§ããŸãã Rxã䜿çšããã¹ãã«ã«èªä¿¡ããããRxãã¢ãŒããã¯ãã£å šäœã§äœ¿çšãããå Žåã¯ãæãé£ããç¹ã«é¢ããJavadocãäœæããŠãã ããã RxJavaã䜿çšããçµéšã®ãªãããã°ã©ããŒã¯
Retrolambdaã¯ãAndroidããã³ãã®ä»ã®ãã©ãããã©ãŒã ã§ã©ã ãåŒã䜿çšããããã®Javaã©ã€ãã©ãªã§ãããŒãžã§ã³8以äžã®JDKã䜿çšããŸãã ç¹ã«RxJavaãªã©ã®æ©èœçãªã¹ã¿ã€ã«ã䜿çšããå Žåãã³ãŒããã³ã³ãã¯ãã§èªã¿ãããããã®ã«åœ¹ç«ã¡ãŸãã 䜿çšããã«ã¯ãJDK8ãã€ã³ã¹ããŒã«ãããããžã§ã¯ãæ§é ã説æãããã€ã¢ãã°ã®Android Studioã®SDKãžã®ãã¹ã§æå®ããç°å¢å€æ°
JAVA8_HOME
ããã³
JAVA7_HOME
ãèšå®ããŠ
build.gradle
ãããžã§ã¯ãã®ã«ãŒã
build.gradle
æžã蟌ã¿ãŸãã
dependencies { classpath 'me.tatarka:gradle-retrolambda:2.4.1' }
åã¢ãžã¥ãŒã«ã®
build.gradle
ãã¡ã€ã«ã«è¿œå ããŸã
apply plugin: 'retrolambda' android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } retrolambda { jdk System.getenv("JAVA8_HOME") oldJdk System.getenv("JAVA7_HOME") javaVersion JavaVersion.VERSION_1_7 }
Android Studioã¯ã©ã ãåŒã®æ§æã®ãµããŒããéå§ããŸãã 以åã«ãããã䜿çšããããšããªãå Žåã¯ã次ã®ã¹ããŒãã¡ã³ããç解ããããšããéå§ã§ããŸãã
- 1ã€ã®ã¡ãœãããæã€ã€ã³ã¿ãŒãã§ã€ã¹ã¯ã©ã ãåŒãšäºææ§ããããèšè¿°ãç°¡çŽ åã§ããŸã
- ãã©ã¡ãŒã¿ãŒã®èšè¿°æ¹æ³ãããããªãå Žåã¯ãéåžžã®å éšã¯ã©ã¹ãäœæããAndroid Studioã§ã©ã ãåŒã«å€æããŸãã
dexãã¡ã€ã«ãã¡ãœããã®æ°ã«å¶éããå€æ°ã®ã©ã€ãã©ãªã䜿çšããªãããã«ããŠãã ããã Androidã¢ããªã±ãŒã·ã§ã³ã¯ãdexãã¡ã€ã«ã«ããã±ãŒãžåãããŠããå Žåã65,536åã®åç §ã¡ãœãã[1] [2] [3]ã®å³å¯ãªå¶éããããŸãã å¶éãè¶ ãããšãèŽåœçãªã³ã³ãã€ã«ãšã©ãŒãçºçããŸãã ãã®ãããå¯èœãªéãæå°éã®ã©ã€ãã©ãªã䜿çšããããšããå§ãããŸã ããŸããdexãã¡ã€ã«å ã®ã¡ãœããã®æ°ãèšç®ãããŠãŒãã£ãªãã£ã«æ³šæããŠãã ããã å¶éãè¶ ããã«äœ¿çšã§ããã©ã€ãã©ãªã®ã»ããã決å®ããã®ã«åœ¹ç«ã¡ãŸãã 13kãè¶ ããã¡ãœãããå«ãGuavaã©ã€ãã©ãªã䜿çšããå Žåã¯ç¹ã«æ³šæããŠãã ããã
ã¢ã¯ãã£ããã£ãšãã©ã°ã¡ã³ã
Androidéçºè ã³ãã¥ããã£ïŒFuturiceãªã©ïŒã§ã¯ããã©ã°ã¡ã³ããšã¢ã¯ãã£ããã£ã®äœ¿çšã«é¢ããŠAndroidã¢ããªã±ãŒã·ã§ã³ã®ã¢ãŒããã¯ãã£ãã©ã®ããã«æ§ç¯ããã®ãæé©ã§ãããã«ã€ããŠã®ã³ã³ã»ã³ãµã¹ã¯ãããŸããã Squareã¯ãäž»ã«ãã¥ãŒã䜿çšããŠã¢ãŒããã¯ãã£ãæ§ç¯ããããã®ã©ã€ãã©ãªããªãªãŒã¹ãããã©ã°ã¡ã³ãã®å¿ èŠæ§ãæå°éã«æããŸãããããã®æ¹æ³ã¯ãŸã äžè¬çã«åãå ¥ããããŠããŸããã
Android APIã®éçºå±¥æŽã«åºã¥ããŠãç»é¢ã®ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã®äžéšãšããŠãã©ã°ã¡ã³ããæ€èšã§ããŸãã ã€ãŸãããã©ã°ã¡ã³ãã¯éåžžUIãæããŸãã ã¢ã¯ãã£ããã£ã¯éåžžãã³ã³ãããŒã©ãŒãšèŠãªãããŸããã©ã€ããµã€ã¯ã«ã®èŠ³ç¹ãããããã³ç¶æ 管çã«ãšã£ãŠç¹ã«éèŠã§ãã ãã ããå¥ã®æ¹æ³ããããŸããã¢ã¯ãã£ããã£ã¯UIïŒç»é¢éã®ç¶æ é·ç§»ïŒã«é¢é£ããæ©èœãå®è¡ã§ãããã©ã°ã¡ã³ãã¯ã³ã³ãããŒã©ãŒãšããŠã®ã¿äœ¿çšã§ããŸãã ãã©ã°ã¡ã³ãã®ã¿ããŸãã¯ã¢ã¯ãã£ããã£ã®ã¿ããŸãã¯ãã¥ãŒã®ã¿ã®äœ¿çšã«åºã¥ãã¢ãŒããã¯ãã£ã«ã¯ãå€ãã®æ¬ ç¹ãããããšã«çæããŠããã©ã³ã¹ã®åãã決å®ãè¡ãããšããå§ãããŸãã 以äžã«ã泚æãæãã¹ãããã€ãã®ãã³ãã瀺ããŸãããéèŠãªããšã§ãã
- ã ãã¹ãããã 人圢ããªã©ã®ãšã©ãŒã衚瀺ãããå¯èœæ§ãããããããã¹ãããããã©ã°ã¡ã³ãã®éäžçãªäœ¿çšã¯é¿ããŠãã ããã ãã¹ãããããã©ã°ã¡ã³ãã¯ãæå³ãããå ŽåïŒããšãã°ãç»é¢ã®ãã©ã°ã¡ã³ãå ã§æ°Žå¹³ã«ã¹ã¯ããŒã«ããViewPagerã®ãã©ã°ã¡ã³ãïŒããŸãã¯äœãããŠããã®ããããç解ããŠããå Žåã«ã®ã¿äœ¿çšããŠãã ããã
- ã¢ã¯ãã£ããã£ã«ã³ãŒããå ¥ããããªãã§ãã ããã å¯èœã§ããã°ãäž»ã«Android APIã®ã©ã€ããµã€ã¯ã«ããã®ä»ã®éèŠãªæ©èœã管çããããã«ãã¢ããªã±ãŒã·ã§ã³ã«ååšãã軜éã³ã³ãããšããŠäœ¿çšããŸãã ãã©ã°ã¡ã³ãã1ã€ã ãã®ã¢ã¯ãã£ããã£ã¯ãåãªãã¢ã¯ãã£ããã£ãããåªããŠããŸã-ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã«é¢é£ããã³ãŒãããã©ã°ã¡ã³ãã«é 眮ããŸãã ããã«ãããã¿ãã䜿çšããŠã¬ã€ã¢ãŠãã«é 眮ããããè€æ°ã®ãã©ã°ã¡ã³ãã䜿çšããŠã¿ãã¬ããç»é¢ã«é 眮ããå¿ èŠãããå Žåã«ãåå©çšã§ããŸãã æå³çã«è¡ããªãéããé¢é£ãããã©ã°ã¡ã³ããªãã§ã¢ã¯ãã£ããã£ãäœæããªãã§ãã ããã
- ããšãã°ãã¢ããªã±ãŒã·ã§ã³ã®å éšæäœãæå³çã«Intentã¡ã«ããºã ã«äŸåãããªã©ãAndroidã¬ãã«ã®APIãæªçšããªãã§ãã ããã Androidãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãŸãã¯ä»ã®ã¢ããªã±ãŒã·ã§ã³ã«åœ±é¿ãäžãããšã©ãŒãããªãŒãºãåŒãèµ·ããå¯èœæ§ããããŸãã ããšãã°ãã¢ããªã±ãŒã·ã§ã³ãã¢ããªã±ãŒã·ã§ã³ããã±ãŒãžéã®å éšéä¿¡ã«ã€ã³ãã³ãã¡ã«ããºã ã䜿çšããŠããå Žåããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãããŒãããçŽåŸã«ã¢ããªã±ãŒã·ã§ã³ãéããå Žåãæ°ç§ã§ããªãŒãºããå¯èœæ§ãããããšãç¥ãããŠããŸãã
Javaããã±ãŒãžã¢ãŒããã¯ãã£
Androidã¢ããªã±ãŒã·ã§ã³ã®Javaã¢ãŒããã¯ãã£ã¯ã Model-View-Controllerãã¿ãŒã³ã«äŒŒãŠããŸã ã Androidã§ã¯ã ãã©ã°ã¡ã³ããšã¢ã¯ãã£ããã£ã¯Conrollerã®ã¯ã©ã¹ãè¡šããŸã ã äžæ¹ããããã¯ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã®äžéšã§ããããããã¥ãŒã®äžéšã§ããããŸãã
ãã®ããããã©ã°ã¡ã³ãïŒãŸãã¯ã¢ã¯ãã£ããã£ïŒãã³ã³ãããŒã©ãŒãŸãã¯ãã¥ãŒã«äžæã«é¢é£ä»ããããšã¯å°é£ã§ãã ç¬èªã®
fragments
ããã±ãŒãžã«å ¥ããæ¹ãè¯ãã§ãããã ãã®å Žåã®ã¢ã¯ãã£ããã£ã¯ãæäžäœããã±ãŒãžã«æ®ãããšãã§ããŸãã 2ã€ãŸãã¯3ã€ä»¥äžã®ã¢ã¯ãã£ããã£ãããå Žåã¯ãããããå¥ã®ããã±ãŒãžã«å ¥ããããšãã§ããŸãã
äžæ¹ãã¢ãŒããã¯ãã£ã¯éåžžã®MVCã®ããã«èŠãã
models
ããã±ãŒãžã«ã¯APIå¿çããJSONããŒãµãŒã«ãã£ãŠçæãããPOJOãå«ãŸãã
views
ããã±ãŒãžã«ã¯äœæè ã®ãã¥ãŒãéç¥ãã¢ã¯ã·ã§ã³ããŒã«é¢é£ä»ãããããã¥ãŒã¯ã©ã¹ããŠã£ãžã§ãããªã©ãå«ãŸããŸãdã ã¢ããã¿ã¯ãããŒã¿ãšãã¥ãŒã®éã®ãªã³ã¯ã§ãã éåžžã¯
getView()
ã¡ãœãããä»ããŠãšã¯ã¹ããŒããããViewã䜿çšããããããã¥ãŒã®ã¢ããã¿ãŒã®åãšããŠã¢ããã¿ãŒãå«ããããšãã§ã
views
ã
äžéšã®ã³ã³ãããŒã©ãŒã¯ã©ã¹ã¯ã¢ããªã±ãŒã·ã§ã³å šäœã§äœ¿çšãããAndroidãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã§çŽæ¥åäœããŸãã ãããã¯ã
managers
ããã±ãŒãžã«é 眮ã§ããŸãã DateUtilsãªã©ãããŒã¿ãåŠçããããã®ããŸããŸãªã¯ã©ã¹ã
utils
ããã±ãŒãžã«æ ŒçŽã§ããŸãã ããã¯ãšã³ããšã®ããåããæ åœããã¯ã©ã¹ã¯ã
network
ããã±ãŒãžã«ãããŸãã
äžèšã®ãã¹ãŠã®ããã±ãŒãžãããã¯ãšã³ããããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãžã®é åºïŒ
com.futurice.project ââ network ââ models ââ managers ââ utils ââ fragments ââ views ââ adapters ââ actionbar ââ widgets ââ notifications
è³æº
åœåã
type_foo_bar.xml
ããã«ããªããžã§ã¯ãåããã¡ã€ã«åã®ãã¬ãã£ãã¯ã¹ãšããŠäœ¿çšããèŠåã«åŸã£ãŠãã ããã äŸïŒ
fragment_contact_details.xml
ã
view_primary_button.xml
ã
activity_main.xml
ã
XMLããŒã¯ã¢ããæ§é ã XMLããŒã¯ã¢ããããã©ãŒãããããæ¹æ³ãããããªãå Žåã¯ã次ã®ãã³ãã圹ç«ã€å ŽåããããŸãã
- 1è¡ã«1ã€ã®å±æ§ã4ã€ã®ã¹ããŒã¹ã§ã€ã³ãã³ã
-
android:id
åžžã«æåã«æ¥ã -
android:layout_****
åé ã®å±æ§ - æåŸã®
style
å±æ§ - å±æ§ã®é åºä»ããšè¿œå ã容æã«ããããã«ãçµäºã¿ã°
/>
ããã®è¡ã«ãããŸãã -
android:text
ãæåã§android:text
代ããã«ãAndroid Studioã®èŠèŠå±æ§ãšãã£ã¿ãŒã䜿çšã§ããŸãã
äŸ
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/name" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:text="@string/name" style="@style/FancyText" /> <include layout="@layout/reusable_part" /> </LinearLayout>
çµéšãããããããã«ã
android:layout_****
å±æ§ã¯XMLããŒã¯ã¢ããã§å®çŸ©ããå¿ èŠããããä»ã®
android:****
å±æ§ã¯XMLã¹ã¿ã€ã«ã§å®çŸ©ããå¿ èŠããããŸãã ãã®èŠåã«ã¯äŸå€ããããŸãããå šäœçã«ã¯ããŸãæ©èœããŸãã ãã€ã³ãã¯ãããŒã¯ã¢ããå±æ§ïŒäœçœ®ãããŒãžã³ããµã€ãºïŒãšã³ã³ãã³ãå±æ§ã®ã¿ãããŒã¯ã¢ãããã¡ã€ã«ã«ä¿åããããšã§ãããããžã¥ã¢ã«ã³ã³ããŒãã³ãã®è¡šç€ºè©³çŽ°ïŒè²ãã€ã³ãã³ãããã©ã³ãïŒã¯ã¹ã¿ã€ã«ãã¡ã€ã«ã«ããå¿ èŠããããŸãã
äŸå€ïŒ
-
android:id
ãã¡ããandroid:id
ããŒã¯ã¢ãããã¡ã€ã«ã«ããã¹ãã§ã -
android:orientation
LinearLayoutãªããžã§ã¯ãã®android:orientation
ã¯éåžžãããŒã¯ã¢ãããã¡ã€ã«ã§æå³ããããŸã -
android:text
ã³ã³ãã³ãã説æãããããandroid:text
ã¯ããŒã¯ã¢ãããã¡ã€ã«ã«å«ãŸããŠããå¿ èŠããããŸã - äžè¬çãªã¹ã¿ã€ã«ã®
android:layout_width
andandroid:layout_height
ã§å®çŸ©ããã®ãçã«android:layout_height
å ŽåããããŸãããããã©ã«ãã§ã¯ãããã®å±æ§ã¯ããŒã¯ã¢ãããã¡ã€ã«ã«ããå¿ èŠããããŸã
ã¹ã¿ã€ã«ã䜿çšããŸãã éåžžããã¥ãŒã®è¡šç€ºå±æ§ã¯éè€ããŠãããããã»ãšãã©ãã¹ãŠã®ãããžã§ã¯ãã§ã¹ã¿ã€ã«ãæ£ãã䜿çšããå¿ èŠããããŸãã å°ãªããšããã¢ããªã±ãŒã·ã§ã³ã®ã»ãšãã©ã®ããã¹ãã³ã³ãã³ãã«å ±éã®ã¹ã¿ã€ã«ãå¿ èŠã§ããããšãã°ã次ã®ãšããã§ãã
<style name="ContentText"> <item name="android:textSize">@dimen/font_normal</item> <item name="android:textColor">@color/basic_black</item> </style>
TextViewã«é©çšïŒ
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/price" style="@style/ContentText" />
ãããããã¿ã³ã«ã€ããŠãåãããšãããå¿ èŠããããŸãããããã§æ¢ãŸããªãã§ãã ããã ãã®ã³ã³ã»ãããéçºããç¹å®ã®çš®é¡ã®èŠèŠã³ã³ããŒãã³ãã«é¢é£ãã
android:****
å±æ§ãç¹°ãè¿ã
android:****
ãã¹ãŠã®ã°ã«ãŒããã¹ã¿ã€ã«ã«å ¥ããŸãã
ã¹ã¿ã€ã«ã®ãã倧ããªãã¡ã€ã«ãããã€ãã®å°ããªãã¡ã€ã«ã«åããŸãã ãã¹ãŠã®ã¹ã¿ã€ã«ã1ã€ã®
styles.xml
ã«ä¿åããå¿ èŠã¯ãããŸããã Android SDKã¯ããã©ã«ãã§ããŸããŸãªãã¡ã€ã«åããµããŒãããŠãããããã¹ã¿ã€ã«ä»ãã®ãã¡ã€ã«ã®åœåã«åé¡ã¯ãããŸãããXMLãstyleãã¿ã°ãå«ããã ãã§åé¡ãããŸããã ãããã£ãŠã
styles_home.xml
ã
styles_item_details.xml
ã
styles_forms.xml
ã
styles_forms.xml
ã ãã«ãã·ã¹ãã ã«ãšã£ãŠéèŠãªãã£ã¬ã¯ããªåãšã¯ç°ãªãã
res/values
ãã¡ã€ã«åã¯ä»»æã§ãã
colors.xml
ã¯ã«ã©ãŒãã¬ããã§ãã
colors.xml
ã¯ãè²åãšRGBAå€ãé¢é£ä»ãã以å€ã®ãã®ãå ¥ããªãã§ãã ããã ããŸããŸãªã¿ã€ãã®ãã¿ã³ã®RGBAå€ã決å®ããããã«äœ¿çšããªãã§ãã ããã
ãšãŠãééã£ãŠãã
<resources> <color name="button_foreground">#FFFFFF</color> <color name="button_background">#2A91BD</color> <color name="comment_background_inactive">#5F5F5F</color> <color name="comment_background_active">#939393</color> <color name="comment_foreground">#FFFFFF</color> <color name="comment_foreground_important">#FF9D2F</color> ... <color name="comment_shadow">#323232</color>
ãã®ã¢ãããŒãã§ã¯ãéè€ããRGBAå€ãäœæããã®ã¯éåžžã«ç°¡åã§ãè²ã®å€æŽã¯ã¯ããã«å°é£ã§ãã ããã«ããããã®è²ã¯ç¹å®ã®ã³ã³ãã³ããããã¿ã³ããŸãã¯ãã³ã¡ã³ããã
colors.xml
ã
colors.xml
ã§ã¯ãªãããã¿ã³ã®ã¹ã¿ã€ã«ã§èšè¿°ããå¿ èŠããããŸãã
ãããŠãã-å³
<resources> <!-- grayscale --> <color name="white" >#FFFFFF</color> <color name="gray_light">#DBDBDB</color> <color name="gray" >#939393</color> <color name="gray_dark" >#5F5F5F</color> <color name="black" >#323232</color> <!-- basic colors --> <color name="green">#27D34D</color> <color name="blue">#2A91BD</color> <color name="orange">#FF9D2F</color> <color name="red">#FF432F</color> </resources>
ã«ã©ãŒãã¬ããã¯ãã¢ããªã±ãŒã·ã§ã³èšèšè ã決å®ããŸãã è²ã¯ç·ãéãªã©ãšåŒã°ããå¿ èŠã¯ãããŸããã ãbrand_primaryãããbrand_secondaryãããbrand_negativeããªã©ã®ååãããªãåãå ¥ããããŸãã ãã®è²ã®æžåŒèšå®ã«ãããè²ã®å€æŽããªãã¡ã¯ã¿ãªã³ã°ãç°¡åã«ãªãã䜿çšãããŠããè²ã®æ°ãç°¡åã«ç解ã§ããããã«ãªããŸãã çŸãããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãäœæããã«ã¯ãå¯èœãªéã䜿çšããè²ã®æ°ãæžããããšãéèŠã§ãã
variable.xmlãcolors.xmlãšããŠã¹ã¿ã€ã«ããŸã ã åãçç±ã§ããªããžã§ã¯ããšãã©ã³ãã®å žåçãªãµã€ãºã®ããã¬ããããå®çŸ©ãã䟡å€ããããŸãã
è¯ãæ§é ã®äŸ
<resources> <!-- font sizes --> <dimen name="font_larger">22sp</dimen> <dimen name="font_large">18sp</dimen> <dimen name="font_normal">15sp</dimen> <dimen name="font_small">12sp</dimen> <!-- typical spacing between two views --> <dimen name="spacing_huge">40dp</dimen> <dimen name="spacing_large">24dp</dimen> <dimen name="spacing_normal">14dp</dimen> <dimen name="spacing_small">10dp</dimen> <dimen name="spacing_tiny">4dp</dimen> <!-- typical sizes of views --> <dimen name="button_height_tall">60dp</dimen> <dimen name="button_height_normal">40dp</dimen> <dimen name="button_height_short">32dp</dimen> </resources>
ç¹°ãè¿ãããŒã¯ã¢ããå±æ§ïŒããŒãžã³ãšã€ã³ãã³ãïŒã«æ°å€ãæžã蟌ãŸãããã©ãŒã
spacing_****
å®æ°ã䜿çšããããšããå§ãããŸãïŒéåžžãæååå€ãããŒã«ã©ã€ãºããå Žåãšã»ãŒåãã§ãïŒã
ããã«ãããããŒã¯ã¢ãããããæ確ã«ãªããå€æŽãããããªããŸãã
strings.xml
ããã±ãŒãžã®åœåã®ããã«ãè¡ã®åœåã§ããŒã䜿çšããŸã-ããã«ãããåãå®æ°åã§åé¡ã解決ãããããã®äœ¿çšã®ã³ã³ããã¹ããããããç解ã§ããŸãã
æªãäŸ
<string name="network_error">Network error</string> <string name="call_failed">Call failed</string> <string name="map_failed">Map loading failed</string>
è¯ãäŸ
<string name="error.message.network">Network error</string> <string name="error.message.call">Call failed</string> <string name="error.message.map">Map loading failed</string>
æååå€ãå°æåã§æžã蟌ãŸãªãã§ãã ããã éåžžã®ããã¹ãå€æïŒæåã®æåã倧æåã«å€æããããšãå«ãïŒã䜿çšã§ããŸãã æååå šäœãå°æåã§æžãããå Žåã¯ã TextViewãªããžã§ã¯ãã®textAllCapså±æ§ã䜿çšããŸãã
æªãäŸ
<string name="error.message.call">CALL FAILED</string>
è¯ãäŸ
<string name="error.message.call">Call failed</string>
æ·±ããã¥ãŒéå±€ãé¿ããŠãã ãã ã ãã¥ãŒã®èª¬æã®åé¡ã解決ããããã«ãå¥ã®LinearLayoutãè¿œå ããããªãããšããããŸãã
çµæã¯æ¬¡ã®ãããªãã®ã«ãªããããããŸãã
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <RelativeLayout ... > <LinearLayout ... > <LinearLayout ... > <LinearLayout ... > </LinearLayout> </LinearLayout> </LinearLayout> </RelativeLayout> </LinearLayout>
ããŒã¯ã¢ãããã¡ã€ã«ã§ãã¹ããæããã«å¢å ããŠããªããŠããïŒJavaã§ïŒãã¥ãŒãä»ã®ãã¥ãŒã«å«ãããšããã¹ããçºçããå¯èœæ§ããããŸãã
ããã€ãã®åé¡ããããããããŸãããããã»ããµããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã³ã³ããŒãã³ãããªãŒã®è€éãªèšè¿°ãåŠçããããšãäœåãªãããããããããã©ãŒãã³ã¹ã®åé¡ãçºçããå¯èœæ§ããããŸããå¥ã®ããæ·±å»ãªåé¡ã¯ãStackOverflowErrorãšã©ãŒã®å¯èœæ§ã§ãã
ã ãããå¯èœãªéããã©ãããšããŠãããªãã®ãã¥ãŒéå±€ãäœã£ãŠã¿ãïŒäœ¿çšæ¹æ³ãåç §ããŠãã ããRelativeLayoutãããæ¹æ³ããããªãã®ã¬ã€ã¢ãŠããæé©åãã䜿çšã¿ã°ãã
WebViewã䜿çšãããšãã¯æ³šæããŠãã ããã web-, , HTML, backend- «» HTML. WebView Activity, ApplicationContext. WebView , TextView Button.
Android SDKãã¹ããã¬ãŒã ã¯ãŒã¯ã¯æªå®æã®ç¶æ ã®ãŸãŸã§ãïŒEspresso 2.1 ã«ã€ããŠã§ããïŒïŒ -çŽPerãïŒãç¹ã«ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãã¹ãã«é¢ããŠã¯ã Android Gradleã«ã¯ãããã©ã«ãã§ãJUnitæ¡åŒµæ©èœãšAndroidãŠãŒãã£ãªãã£ã䜿çšããŠäœæããJUnitãã¹ããå®è¡ããconnectedAndroidTestã¿ã¹ã¯ãå«ãŸããŠããŸããã€ãŸããããã€ã¹ãŸãã¯ãšãã¥ã¬ãŒã¿ãŒã§ãã¹ããå®è¡ããå¿ èŠããããŸãããã¹ãã«ã¯å ¬åŒã®æ瀺[1] [2]ã䜿çšããŠãã ãããRobolectricã¯ãUIã§ã¯ãªããåäœãã¹ãã«ã®ã¿
䜿çšããŠãã ããããã®ãã¬ãŒã ã¯ãŒã¯ã¯ãããã€ã¹ãªãã§ãã¹ããå®è¡ããå®è¡é床ãåäžãããæ©èœãæäŸããããŒã¿ã¢ãã«ãšãã¥ãŒã®åäœãã¹ãã«æé©ã§ãããã ããRobolectricãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã¯å®å šã§ã¯ãªããäžæ£ç¢ºã§ã¯ãããŸãããã¢ãã¡ãŒã·ã§ã³ããã€ã¢ãã°ãªã©ã«é¢é£ãããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹èŠçŽ ããã¹ããããšåé¡ãçºçãããã¹ãããã»ã¹ã¯ïŒç»é¢ãèŠãã«ïŒãç²ç®çã«ãé²ã¿ãŸãã
Robotiumã¯ããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã®ãã¹ããç°¡åã«ããŸããRobotiumãªãã§UIãã¹ããå®è¡ã§ããŸããããã¥ãŒã®åæãšç»é¢ã®å¶åŸ¡ã®ããã®ãŠãŒãã£ãªãã£ããããããéåžžã«äŸ¿å©ã§ãããã¹ãã¹ã¯ãªããã¯éåžžã«åçŽã«èŠããŸãã
solo.sendKey(Solo.MENU); solo.clickOnText("More"); // searches for the first occurence of "More" and clicks on it solo.clickOnText("Preferences"); solo.clickOnText("Edit File Extensions"); Assert.assertTrue(solo.searchText("rtf"));
ãšãã¥ã¬ãŒã¿ãŒ
ããã®Androidéçºè ã§ããå Žåã¯ãGenymotionãšãã¥ã¬ãŒã¿ãŒã®ã©ã€ã»ã³ã¹ãè³Œå ¥ããŠãã ãããéåžžã®AVDãšãã¥ã¬ãŒã¿ãããé«éã«åäœããŸããGenymotionãšãã¥ã¬ãŒã¿ãŒã䜿çšãããšãã¢ããªã±ãŒã·ã§ã³ã®åäœã瀺ããããªãé²ç»ããããããŸããŸãªå質ã®ãããã¯ãŒã¯æ¥ç¶ãGPSä¿¡å·ãªã©ããšãã¥ã¬ãŒãã§ããŸãããã¹ãã®å®è¡ã«æé©ã§ããAndroidããã€ã¹ã®å€ãã®ïŒãã¹ãŠã§ã¯ãããŸãããïŒã€ã¡ãŒãžã«ã¢ã¯ã»ã¹ã§ãããããGenymotionã©ã€ã»ã³ã¹ã®ã³ã¹ãã¯ãå€ãã®ããã€ã¹ãè³Œå ¥ãããããã¯ããã«å®ããªããŸãã
èœãšãç©ŽïŒGenymotionã§ã¯ãã¢ããªã±ãŒã·ã§ã³ã§Google Playã¹ãã¢ãããããªã©ã®GoogleãµãŒãã¹ã䜿çšã§ããŸããããŸããSamsung APIæ©èœããã¹ãããå¿ èŠãããå Žåã¯ãå®éã®ããã€ã¹ãè³Œå ¥ããå¿ èŠããããŸãã
Proguardã®æ§æ
ProGuardã¯äžè¬çã«Androidãããžã§ã¯ãã§ã³ãŒãã®å§çž®ãšé£èªåã«äœ¿çšãããŸãã
ProGuardã䜿çšããããã®æ¡ä»¶ã¯ããããžã§ã¯ãã®èšå®ã«ãã£ãŠç°ãªããŸããéåžžãProGuardã䜿çšããŠãªãªãŒã¹ããŒãžã§ã³ããã«ãããããã«gradleãæ§æããŸãã
buildTypes { debug { minifyEnabled false } release { signingConfig signingConfigs.release minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }
ã³ãŒãã®ã©ã®éšåãåŠçããå¿ èŠããããã瀺ãã«ã¯ã1ã€ä»¥äžã®ãšã³ããªãã€ã³ããããŒã¯ããå¿ èŠããããŸããéåžžããããã¯åºæ¬çãªã¡ãœãããã¢ãã¬ããããããã¬ãããã¢ã¯ãã£ããã£ãªã©ãæã€ã¯ã©ã¹ã§ããAndroidãã¬ãŒã ã¯ãŒã¯ã䜿çšããããã©ã«ãã®æ§æã¯ã«ãã
SDK_HOME/tools/proguard/proguard-android.txt
ãŸããProGuardã®æ§æã«ç¬èªã®ã«ãŒã«ãå®çŸ©ããã«ã¯ããããããã¡ã€ã«ã«é 眮ã
my-project/app/proguard-rules.pro
ãŸãããããã®ã«ãŒã«ã¯ããã©ã«ãã®æ§æãè£å®ããŸãã
ProGuardã«é¢é£ããæãäžè¬çãªåé¡ã¯ãèµ·åæã«ãšã©ãŒãçºçã
ClassNotFoundException
ãã
NoSuchFieldException
ããããžã§ã¯ããã«ãããŒã ïŒããšãã°
assembleRelease
ïŒããšã©ãŒãªãã§åäœããå Žåã§ããã¢ããªã±ãŒã·ã§ã³ãã¯ã©ãã·ã¥ããããšã§ããããã¯ã次ã®2ã€ã®ãããããæå³ããŸãã
- ProGuardã¯ãã¯ã©ã¹ãåæåãã¡ãœããããã£ãŒã«ãããŸãã¯æ³šéãåé€ããŸãããããããã¯å¿ èŠãªããšèããŠããŸããã
- ProGuardã¯ã¯ã©ã¹ãåæåããŸãã¯ãã£ãŒã«ãã®ååãå€æŽããŸããããJavaãªãã¬ã¯ã·ã§ã³ã¡ã«ããºã ãå«ããå€ãååã䜿çšããŠåŒã³åºãããŸãã
app/build/outputs/proguard/release/usage.txt
ãªã¢ãŒããªããžã§ã¯ãã®èšåã«ã€ããŠã¯ããã¡ã€ã«ã確èªããŠãã ãããååãå€æŽãããŠããå Žåããã®ååã¯ãã¡ã€ã«ã«ãããŸã
app/build/outputs/proguard/release/mapping.txt
ãProGuard ã«ãã£ãŠ
å¿ èŠãªã¯ã©ã¹ãšã¡ãœãããåé€ãããªãããã«ä¿è·ããããã«ãæ§æã«ãªãã·ã§ã³ãè¿œå ããŸã
keep
ã
-keep class com.futurice.project.MyClass { *; }
ååã®å€æŽãé²ãã«ã¯ããªãã·ã§ã³ã䜿çšããŸã
keepnames
ïŒ
-keepnames class com.futurice.project.MyClass { *; }
ãã®äŸã§ã¯ãProGuardæ§æã«å¯Ÿããä»ã®å¯èœãªå€æŽãèŠã€ããããšãã§ããŸãããã®ä»ã®Proguardæ§æã®äŸã¯ãã¡ãã
ãããžã§ã¯ãã®éå§æã«ããªãªãŒã¹ãã«ããäœæããŠã ProGuardã®ã«ãŒã«ãæ£ããèšè¿°ãããŠããããšã確èªããŸããæ°ããã©ã€ãã©ãªãæ¥ç¶ãããšãããªãªãŒã¹ãã«ããäœæããããã€ã¹äžã®å®è¡å¯èœãã¡ã€ã«ã確èªããŸããããŒãžã§ã³â 1.0âããªãªãŒã¹ãã«ããäœæããã®ãåŸ ããªãã§ãã ãããããããªããšãä¿®æ£ããæéããªãããã«äžæå¿«ãªé©ããæãããããããŸããã
ãã³ããåãªãªãŒã¹ã®mapping.txtãã¡ã€ã«ãä¿åããŸããåã¢ã»ã³ããªã®mapping.txtãã¡ã€ã«ã®ã³ããŒãããã°ãåé¡ã確å®ã«èŠã€ããããšãã§ããŸãããŠãŒã¶ãŒã¯ãã°ããã£ããããé£èªåããããšã©ãŒãã°ãéä¿¡ããŸãã
DexGuardãã³ãŒããçªç¶æé©åããç¹å¥ãªæ¹æ³ã§é£èªåããå Žåã¯ãProGuardã®åçšã¢ããã°ã§ããDexGuardã䜿çšããŠã¿ãŠãã ãããDexãã¡ã€ã«ãããã€ãã«ç°¡åã«åå²ããŠã65kã¡ãœããã®å¶éãåé¿ã§ããŸãã
è¬èŸ
Antti LammiãJoni KarppinenãPeter TackageãTimo TuominenãVera IzrailitãVhitoriMÀntylÀãMark VoitãAndre MedeirosãPaul Houghtonãããã³ãã®ä»ã®Futuriceéçºè ãAndroidã®ç¥èãå ±æããŠããŸãã
å èš±
Futurice Oy Creative Commons Attribution 4.0 InternationalïŒCC BY 4.0ïŒ