ã©ãããnkzn.netã®æ´æ°ãå¿ãã¦ã¦è»¢å£²å±ã«åããã人ã§ãã
ä»æ¥ã¯Android Bazaar and Conference 2014 Springã§ãããåã¯æ¥åé½åçãªã¢ã¬ã§ä»åã®ABCã«åå ã§ããªããããå¤ã®è£ä¼ã ãè¡ãã¾ãã
ãã ãå ¨ããªã«ãããªãã®ãå¯ããã®ã§ãæ¯æ°ä»ãã«ï¼æ¬è¨äºãæ¸ããã¦ãããã¾ãããEffective Androidãã©ãã¯ã®çºè¡¨å 容ã¨ãã¿è¢«ããããããããªï¼ï¼
ãã¶ã@mhidakaã¨ã@sys1yagiããããã®è¨äºããè¯ããã¨åã£ã¦ãããã¨æãã®ã§ãã¿ãªããç§èåUDXã§èè ãã¡ã¨æ¡æï¼ï¼ï¼å®£ä¼ï¼
- ä½è : TechBooster,å°å¤ªå御ç¦,åºææå,éç°å¤§å©,西岡é代,å®®å·å¤§è¼,ææ¬åä¿,ãããããã,å «æ¨ä¿åº,æ¨æå°æµ·,å°ææ æ²»,æå±±åäº,ä¸è¥¿è¯æ,ãããã¾ãã²ã,æ°äºç¥ä¸,æ¡äºèä»,ä¹ é·éä¹,寺åèæ,shige0501,å±±ä¸æºæ¨¹,åç°ç« å,ç§èã¡ã²ã,æ«åºå°ç¾©,ä¸æ¾¤æ §,æ¥é«æ£å,å¡ç°ç¿ä¹,äºå½¢åä»,ä¸å·å¹¸å,å±±å´èª ,å±±ä¸æ¦å¿,ãªã¾ãã§,æ©çªé¦ç¹,ãã¨ãããã®ã,l_b__,ã¼ãããããã,é·æ±ç¥å
- åºç社/ã¡ã¼ã«ã¼: ã¤ã³ãã¬ã¹ã¸ã£ãã³
- çºå£²æ¥: 2014/01/17
- ã¡ãã£ã¢: åè¡æ¬ï¼ã½ããã«ãã¼ï¼
- ãã®ååãå«ãããã° (8件) ãè¦ã
ã¯ããã«
ãã¦ãããä½ã¶æãã§ããå®éAndroid Studioã©ããªããã¨ãã質åãåããæ©ä¼ãå¢ãã¦ããã®ã§ããããã§ä¸åº¦ãåãAndroid Studioã常ç¨ãã¦ãã¦å¬ããã¨æãã¦ãããã¨ãæ¸ããªãã£ã¦ã¿ã¾ããã
- ã¯ããã«
- 1. Gradleãæ¨æºãã«ããã¼ã«ã¨ãã¦æ¡ç¨ããã¦ãã
- 2. dependenciesè¨å®ã§ã©ã¤ãã©ãªåãæ¾é¡
- 3. AARãªã©ã¤ãã©ãªããã¸ã§ã¯ããdependenciesã§åã£ã¦ããã
- 4. ãã«ãã®ç¨®é¡ãå®ç¾©ãã¦ã½ã¼ã¹ãã©ã«ãåä½ã§åãæ¿ãããã
- 5. Android Studioã®ããã¸ã§ã¯ãè¨å®ãGradleä¾å
- 6. ç»åãªã½ã¼ã¹ã®å°ãããã¬ãã¥ã¼ãXMLãJavaããè¦ãã
- 7. colorãªã½ã¼ã¹ã®è²ãXMLãJavaããè¦ãã
- 8. å種ãªã½ã¼ã¹ã®åç §ãæåã¨ãã¦è¦ãã
- 9. ã¬ã¤ã¢ã¦ãXMLãããã¹ãã¨ãã£ã¿ã¢ã¼ãã§ããªã¢ã«ã¿ã¤ã ãã¬ãã¥ã¼ã§ãã
- 10. Kotlinè¨èªã使ãã
- ã¾ã¨ã
- ãããã¦èªã¿ãã
æ¨å¹´ï¼ï¼æãããæ¥åã§ç´ï¼ã¶æ使ã£ã¦ã¿ã¦ã®ææ³ã§ããæ°äººç ä¿®ã«ãï¼ã¶æã»ã©ä½¿ã£ã¦ã¿ã¦ãã¾ãã
ååã¯ã©ã¡ããã¨ããã¨Android Studioã使ããã¨ã§å©ç¨å¯è½ã«ãªãGradleãããããçãªè©±ãå¾åã¯Android Studioã¨ããIDEèªä½ã®è©±ã§ãã
IntelliJ IDEA + Android Pluginã§ãåããããªãã¨ã§ããã¨æãã®ã§ããIntelliJ IDEAã使ãã¹ãããã«èªã¿æ¿ãã¦ãããã§ããAndroid Studioãããã¦IntelliJ IDEAã使ãã¹ã10ã®çç±ãæ¸ããã人ã¯æ¯éãé¡ããã¾ãï¼ï¼ï¼
â»ããï¼ã¶æãã»ã¨ãã©Eclipse+ADTã®ç°å¢ã触ã£ã¦ããªãã®ã§ããããEclipseã§ãã§ãããï¼ï¼ï¼ï¼ããªãã¨ããã£ããããããªããï¼ãç¥ãããã ãã
1. Gradleãæ¨æºãã«ããã¼ã«ã¨ãã¦æ¡ç¨ããã¦ãã
ãã®è¨äºãæ¸ãå§ããã¢ããã¼ã·ã§ã³ã¯ãããï¼å²ã§ããã§ãæ¸ãçµãã¦ã¿ããæç´ã°ããã§ããã¾ãé¢ç½ããªãã£ãã®ã§ãèªã¿é£ã°ãã¦æ¬¡ã¸è¡ã£ãã»ããããæ°ããã¾ãã
èªã¿é£ã°ãæ¹ã®ããã®ï¼è¡ã¾ã¨ãï¼Android Studioãæ¨æºå¯¾å¿ãã¦ããGradleã¯ãAndroidã¢ããªåãã®ãã«ããã¼ã«ã¨ãã¦AntãMavenããæè»ã§ä½¿ããããã®ã§è¯ããï¼ï¼
ååã®æ代ï¼Ant
Eclipseï¼ã¨ããããã¯ãæ§æ¥ã®Android App Projectã®æ§é ï¼ã§ã¯ãã³ãã³ãã©ã¤ã³åãã®æ¨æºãã«ããã¼ã«ãAntã§ãããã§ãEclipseãããªããµã¯ãã¨ã§ããæ¹æ³ããã³ãã³ãã©ã¤ã³ããã ã¨ã¯ã½é¢åãããã£ãå°è±¡ãããã¾ãã
模索ã®æ代ï¼Maven
ãã«ãããã»ã¹ãã©ã¤ãã©ãªä¾åæ§ããã£ã¨æè»ã«ç®¡çãããã£ã人ã ã次ã«æãåºããã®ãMavenã§ãããMavenã«ã¯Maven Central Repositoryã¨ããã©ã¤ãã©ãªç½®ãå ´ããããè¨å®ãã¡ã¤ã«ã«ã©ã¤ãã©ãªåã¨ãã¼ã¸ã§ã³ãè¨è¿°ãããã¨ã§ãã©ã¤ãã©ãªããã¦ã³ãã¼ããã¦ãã¦ããã¸ã§ã¯ãå ã§å©ç¨ã§ããã¨ããããã¼ã¸ã§ã³ç®¡çã·ã¹ãã ã«åªããæãã®ä»çµã¿ããããææãã¨æããã¾ãããå°ãªãã¨ããã³ãã³ãã©ã¤ã³ãããã«ãããã¹ããå®è¡ã§ããã¨ããç¹ã§ãCIã®ããããã¨ããæ¡ä»¶ã¯æºããã¦ãã¾ããã
ããããããMavenã®è¨å®ãã¡ã¤ã«ã§ããpom.xmlã¯ã¡ãã£ã¨éãæ·±ãç³»ã®ã¢ã¬ã§ãã£ããã¨ããå ¬å¼ãã¼ã«ã§ã¯ãªããã¨ã«ããä¸å®å®ãï¼ç°å¢ãå®å®ãããããã«çç·´ã®æ¥ãè¦ããï¼ãç°å¢æ§ç¯ã®åº¦ã«maven-android-sdk-deployerãå®è¡ããã®ããã«ãããªã©ã®çç±ã«ããã使ãããããã¨è¨ãããã¨ã¨ã¦ãé ·ãããã®ã§ã¯ãªãã£ãã¨æãã¾ãã
æ°ããªãæ¯å¹ï¼Gradle
ããã«Googleãå ¬å¼ã«ã¶ã£è¾¼ãã§ããã®ãGroovyãã¼ã¹ã®DSLã§ããGradleã¨ãªãã¾ããæç¶ãåãªæãã®ã¹ã¯ãªããã§ãå人çã«ã¯Mavenã®XMLãããä½ãæ¸ãã¦ããã®ãèªã¿ãããã¨æãã¾ãããã¾ããMaven Central Repositoryãå©ç¨ã§ãããããã©ã¤ãã©ãªã®åå¾ã容æã§ããGroovyããã®ã¾ã¾æ¸ãããããããã¨ãªãã°æè»ãªå¦çãæ¸ããã®ãããã¤ã³ããé«ãã¨ããã§ãã
Gradle Wrapper(gradlew, gradlew.bat)ã®ä»çµã¿ã«ããããããããã¼ã®æå ã«ã·ã§ã«ãbatã®å®è¡ç°å¢ï¼ã¨ãAndroid SDKã¸ã®ãã¹ï¼ãããã°ãããã ãã§ããã¸ã§ã¯ãã®ãã«ããã§ãã¦ãã¾ãç¹ãããã¼ã éçºããªã¼ãã³ã½ã¼ã¹éçºãè¡ãä¸ã§ã¯å¬ããç¹ã§ãã
ããã¦ãAndroid Studioå´ã§ãã«ããªãã¿ã³ãæ¼ããæã®æåã¯ãã³ãã³ãã©ã¤ã³ãã ./gradlew assembleDebug
ãããã¨ãã¨åãããããIDEããã¯åãã®ã«ãã³ãã³ãã©ã¤ã³ããã ã¨åããªãããªãã¦è¬ç¾è±¡ã«æ©ã¾ãããå¿
è¦ã¯ããã¾ããã*1
ä½ãè¨ãããã£ããã¨ããã¨
Mavenã§ããã¸ã§ã¯ã管çããã®åãè¦ããã£ãããGradleã§ç®¡çã§ããããã«ãªã£ã¦å¬ããã£ããï¼ç§æ¨ && å°ä¸¦æï¼
2. dependenciesè¨å®ã§ã©ã¤ãã©ãªåãæ¾é¡
ãã¦ãEclipse+Mavenã ã¨pomåï¼ã½ããããï¼ã磨ããªãã¨ãããªãã¦ãã¸ãã¡ãã¯ã§ããããAndroid Studio + Gradleã§ã¯ãâã®ãããªã³ã¼ããbuild.gradleã®ä¸ã«æ¸ãã ãã§ã©ã¤ãã©ãªã®ãã¦ã³ãã¼ããè¡ããAndroidã¢ããªã®ä¸ã§ä½¿ããããã«ãã¦ããã¾ãã
dependencies { compile "com.nineoldandroids:library:2.4.0" }
compile "group_id:artifact_id:version"
ãªæãã§ãããMavenã®æ çµã¿ã§é
å¸ããã¦ããã©ã¤ãã©ãªã¯ããã§åã£ã¦ããã¾ããDaggerã ã£ã¦Picassoã ã£ã¦ããã«ä½¿ããããã«ãªãã¾ãã
GradleãAndroid Studioã¯ã¾ã ã¾ã 浸éãã¦ããã¨ã¯è¨ããããã§ãããMaven Central Repositoryã§JARã©ã¤ãã©ãªãå ¬éããã®ã¯Javaçéã§æ¢ã«åºã浸éãã¦ããæåã§ãã®ã§ããã®ä»çµã¿ã«ãã£ã¦å¾ãããæ©æµã¯è¨ãç¥ããªãã¨è¨ã£ã¦ãããã§ãããã
ã©ã¤ãã©ãªå°å ¥ã®ã³ã¹ããæ» è¶è¦è¶ä¸ããã¾ããããã£ããï¼ï¼ï¼
3. AARãªã©ã¤ãã©ãªããã¸ã§ã¯ããdependenciesã§åã£ã¦ããã
AARã¯Android ARchiveã®ç¥ãããã§ããJARã®Androidçã ã¨ããèªèã§ããã©ãããããªããã©ãããã©ã¤ãã©ãªããã¸ã§ã¯ãããã«ãããã¨ãã«çã¾ããããã¡ã¤ã«ã¨ãã¦ã®å®ä½ã¿ããã§ãããï¼ããããæå³ã§ã¯ãAPKãã¡ã¤ã«ã«é¡ããåå¨ãªã®ããï¼
ãã¦ããã®å½¢å¼ã®ã©ã¤ãã©ãªããã¸ã§ã¯ãã¯ãä½è ãé å¼µã£ã¦ããã¦ããå ´åãgradleã®dependenciesã§åã£ã¦ããã¾ãã
詳ããã¯ãã¼ãã¡å çã®è¨äºã御覧ãã ããã
å®éã«ãã®å½¢å¼ã§é å¸ããã¦ããã©ã¤ãã©ãªã¨ãã¦ã¯ã@sys1yagiããã®IndirectInjectorãªã©ãããã¾ãã
4. ãã«ãã®ç¨®é¡ãå®ç¾©ãã¦ã½ã¼ã¹ãã©ã«ãåä½ã§åãæ¿ãããã
社å åããããã°ç¨ãã¢ãã¿ã¼ã¦ã¼ã¶ã¼åããªãªã¼ã¹ç¨ãPlayã¹ãã¢åãç¡æçãªãªã¼ã¹ç¨ãPlayã¹ãã¢åãææçãªãªã¼ã¹ç¨ããªã©ã®åãæ¿ããããã«ãæã«ã³ãã³ãã«ãã£ã¦åãæ¿ããããæ©è½ãããã¾ããBuild Typeã¯Debugã¨Releaseã®2種é¡ã§ãããProduct Flavorã¯ä»»æã®æ°ã ãç¨æã§ããã®ã§ãè²ããªãã¿ã¼ã³ã®ã¢ããªãä½ããªãã¨ãããªãå ´åã«ã¯ä¾¿å©ãªæ©è½ã§ããã
ä¸è¨ã®è¨äºã詳ããã§ãã
Build Variants によって別バージョンの Android アプリを同じプロジェクトからビルドする (Gradle 使用) - ひだまりソケットは壊れない
5. Android Studioã®ããã¸ã§ã¯ãè¨å®ãGradleä¾å
ããã¸ã§ã¯ããã©ã«ãã®æ§é ãå°ãè¤éã«ãªã£ã¦ãããããã¨ãã½ã¼ã¹ãå ¥ã£ããã©ã«ãããã«ããã¹ã«è¿½å ãå¿ããå¡ãã¹ã«ãããä¸æããã«ãã§ããªãã£ããããçµé¨ã¯ãªãã§ããããã
Android Studio + Gradleã®ç°å¢ã§ã¯ãsettings.gradleãbuild.gradleã«è¨è¿°ããå 容ãAndroid Studioã®ããã¸ã§ã¯ãè¨å®ã«ç´æ¥åæ ãããããããããã£ããã¹ãèµ·ãã¥ãããªã£ã¦ãã¾ãã
ã¾ãããã¼ã éçºæã«ããIDEã®åæè¨å®ã«å²ãæéãæ¸ããããã§ãã
Intellij IDEAã¿ããã« Mark Directory As > Test Source Root
ã¿ãããªæãã§IDEããã½ã¼ã¹ãã©ã«ããæå®ããããªãã¨ããããã¾ããã©ãã¼ã
6. ç»åãªã½ã¼ã¹ã®å°ãããã¬ãã¥ã¼ãXMLãJavaããè¦ãã
JavaãXMLã§ãdrawableãªã½ã¼ã¹ã®ä¸èº«ãã¨ãã£ã¿ã®å·¦ç«¯ã«åºã¦ãã¾ãã
Javaã®ã»ãã¯å¼ã¨ãã¦æãç«ã£ã¦ããªãã¦ãåºã¦ããã®ã§ãå¤æåºæºãçµæ§é©å½ã¿ããã§ãã
7. colorãªã½ã¼ã¹ã®è²ãXMLãJavaããè¦ãã
JavaãXMLã§ãcolorãªã½ã¼ã¹ã®è²ãã¨ãã£ã¿ã®å·¦ç«¯ã«åºã¦ãã¾ãã
color.xmlã¯ãªããªã壮観ã§ããã
ãã¾ã©ããªè²ãç»é¢ã«åºã¦ããã®ãã³ã¼ããæ¸ããªããã¤ã¡ã¼ã¸ããããã®ã¯ãå¬ããæãããã®ã§ã¯ãªãã§ãããããï¼å®ã¯ããã¾ãå¬ããå ´é¢ãæãã¤ãã¦ããªããã©ç¶ºéºãªã®ã§æããï¼
8. å種ãªã½ã¼ã¹ã®åç §ãæåã¨ãã¦è¦ãã
XMLãã¡ã¤ã«ãJavaãã¡ã¤ã«ã®ä¸ã§ãdimenãstringã§å®ç¾©ããè¦ç´ ã®å¤ããä¸æçã«ç½®ãæãã¦è¡¨ç¤ºããã¾ããå®éã®ãã¡ã¤ã«ä¸ã§æå®ããå¤ãæ¸ãæããããã§ã¯ãªããããã¾ã§ãè¦ãç®ã ãã§ããã¦ã¹ãªã¼ãã¼ããã¨å ã®å¤ãè¦ããã¨ãã§ããããã¾ãã
å®éã«ã¯âã®ããã«ãªã£ã¦ãããã¡ã¤ã«ãã»ã»ã»
ãããªãµãã«è¦ãã¾ãã
Javaã®ä¸ã§getString(resId: int)
ã§å¼ã°ãã¦ããå¤ãåæ§ã«ç½®ãæãããã¾ãã
âãããâãããªã
ããã§ããããããã®stringãªã½ã¼ã¹ãä¸ã«æ¸ããæ¥æ¬èªãªãã ã£ãã£ãï¼ãã¨ãããã®dimenãå®éã«ã¯ä½dpã ã£ãï¼ããªãã¦æ©ã¾ãã«æ¸ã¿ã¾ããï¼
9. ã¬ã¤ã¢ã¦ãXMLãããã¹ãã¨ãã£ã¿ã¢ã¼ãã§ããªã¢ã«ã¿ã¤ã ãã¬ãã¥ã¼ã§ãã
ã¬ã¤ã¢ã¦ãã®XMLãç·¨éããã¨ãã»ã¼ãªã¢ã«ã¿ã¤ã ã§ãã¬ãã¥ã¼ã«åæ ããã¾ããAndroid Studioç»å ´ä»¥åãããIntelliJ IDEAã§Androidéçºãããéã®é åçãªæ©è½ã¨ãã¦æãããã¦ãã¾ããã
ä½ãç½®ãã¨ã©ããªãµãã«è¦ããã®ãããã©ã¤ã¢ã³ãã¨ã©ã¼ã大å¤æãã®ã§ããã¶ã¤ãã¼ãããAndroidåå¿è ãªããã°ã©ãã¼ã®äººã«ã¬ã¤ã¢ã¦ãXMLãåå¼·ãã¦ãããéã«ããå¹æããã°ã³ã§ãã
10. Kotlinè¨èªã使ãã
Android Studioã¯JetBrains製ã®IDEã§ããIntelliJ IDEAããã¼ã¹ã«ãã¦ããã®ã§ãã¡ããã¨è¨å®ããã°Kotlinè¨èªãå©ç¨ãããã¨ãã§ãã¾ããAndroidã§ä½¿ãããã¿ã¼Javaè¨èªãæ¢ãã¦ããæ¹ã«ãªã¹ã¹ã¡ã§ãã
Null-safetyæ©è½ãã£ãããããï¼ï¼ï¼ï¼
ã¾ã¨ã
ç¾ç¶ãåãEclipseã使ãçç±ã¯ï¼æ¥åä¸ãããå¾ãªãã¢ã¬ãç¡ãéãï¼ã©ãã«ãããã¾ããã*2
ã§ãåãé åãæãã¦ããã®ã¯ã©ã¡ããã¨ããã¨Gradleã®ã»ããªã®ã§ãADTãGradleã«å¯¾å¿ãããããã¯ããã§è§¦ã£ã¦ã¿ããæ°ããã¾ãã
ä»åã¯ãIntelliJ IDEAãå ã æã£ã¦ãè¯ããã¿ãããªãã®ã¯åºæ¬çã«æããªãã£ãã®ã§ãä»ã«ãAndroid StudioãIDEAãæ¢ãã¦ä½¿ãå©ç¹ã¯ããããã§ãããã®ã¸ãã¯ä»ã®æ¹ãè¨äºæ¸ãã¦ããã¦ãã¨æãã®ã§ãæ¢ãã¦ã¿ã¦ãã ããã
ããã§ã¯ãè¯ãAndroidã¢ããªéçºã©ã¤ããã