Eclipseãã¤ãã£ã¦ï¼Scalaã§æ¸ããããã°ã©ã ãAndroidä¸ã§åä½ããããï¼ã¡ã¢ï¼ã¨ãããï¼ä»¥ä¸ã®ãã¤ã³ãã«æ°ãã¤ãã¦ããã°OKããã§ãï¼
ãã¤ã³ã
- Eclipseã®Scalaãã©ã°ã¤ã³ã®ãã¼ã¸ã§ã³ã«åã£ãandroidç¨ã®scalaã©ã¤ãã©ãªã使ã
- Eclipseã®Builderã®é çªãé©åã«è¨å®ãã
- Eclipseã®ã©ã¤ãã©ãªã®èªã¿è¾¼ã¿åªå 度ãé©åã«è¨å®ãã
Developing for Android | Scala IDE for Eclipse Project | Assembla ãã ãã¶åèã«ãã¾ããï¼
ã¨ãããããã£ã¦ã¿ãã¼
0. Eclipseãã¤ã³ã¹ãã¼ã«ãã
çç¥ï¼æ®éã«ããã
1. Androidéçºç°å¢ãã¨ã¨ã®ãã
- Android SDKã¨Eclipseç¨ã®Androidéçºãã©ã°ã¤ã³(ADT)ãã¤ã³ã¹ãã¼ã«ï¼
- Eclipseã®ç°å¢è¨å®ã§SDKã®å ´æãã»ãããã¦ããã°OK
2. Scalaéçºç°å¢ãæ´ãã
- EclipseåãScala ãã©ã°ã¤ã³ãã¤ã³ã¹ãã¼ã«ï¼nightlyã§ã¯ãªãã»ãï¼
- Scala IDE for Eclipse http://www.scala-lang.org/node/94
- ããã«ï¼ãã¼ãã«ã®Scalaã«ã¯ä¸é¨Androidä¸ã§åä½ããªãæ©è½ãããã®ã§ï¼ä¸é¨æ©è½ãomitããandroid-library.jarãå
¥æãã¦é©å½ãªå ´æã«ç½®ãï¼
- android-library.jar http://www.nabble.com/Re%3A-Re%3A-Scala-and-Android-1.5-p23993564.html
ãã®ã¨ãï¼Scala IDE for Eclipseã¯nightlyãããªãæ¹ãã¤ã³ã¹ãã¼ã«ãããã注æï¼android-library.jarã¨ãã¼ã¸ã§ã³ãåãããããï¼ (ã©ã£ã¡ããã¼ã¸ã§ã³7.5ã«ãªã)
3. Androidããã¸ã§ã¯ããä½æãï¼Scalaã©ã¤ãã©ãªãããã
ãããé¢å
- Package Exploreãå³ã¯ãªãã¯ã㦠New->Other ãã Android Projectãé¸æï¼ã¦ã£ã¶ã¼ãããããã¦æ°ããããã¸ã§ã¯ããä½ãï¼(ã¦ã£ã¶ã¼ãã®ä¾ f:id:hakobe932:20090706171311p)
- ããã¸ã§ã¯ãã®ååãå³ã¯ãªãã¯ã㦠Scala->Add Scala Natureãé¸ãã§Scalaç°å¢ã追å ãã
- ããã¸ã§ã¯ãã®Properties->Java Build Path ã® Libraries ã¿ã㧠Scala Library ã Remove
- åãLibraries ã¿ã㧠Add External JARs... ãé¸æãã¦å ã»ã©ç¨æããandroid-library.jarãæå®ããï¼
- ããã«Libraries ã¿ã㧠Add External Class Folder... ãé¸æãã¦ããã¸ã§ã¯ãå ã®binãã£ã¬ã¯ããªãæå®ããï¼ä»¥ä¸ã¯ï¼ããã¾ã§ã®Libraryã¿ãã®æ§åï¼
- Order and Export ã¿ãã以ä¸ã®ãããªé çªã«ä¸¦ã¹è¿ã
- ããã¸ã§ã¯ãã®Properties->Builders ã以ä¸ã®ãããªé çªã«ä¸¦ã¹æ¿ãã
4. Scalaã®ã³ã¼ããç¨æ
- Eclipseã«ãã£ã¦èªåçã«ä½æãããActivityã¯ã©ã¹ãåé¤ãã
- åãååã®scalaãã¡ã¤ã«ãã¤ããï¼ãã¨ãã¨Hoge.javaãçæããã¦ãããHoge.scalaãã¤ããï¼ã³ã¼ãã¯ä¾ãã°ä»¥ä¸ã®ããã«
package jp.hakobe.mobile import android.os.Bundle import android.app.Activity import android.widget.TextView class Hoge extends Activity { override def onCreate(savedInstanceState: Bundle) { super.onCreate(savedInstanceState) val tv = new TextView(this) tv.setText("Hello Android, it's me, Scala!") setContentView(tv) } }
5. ãã«ãã¨å®è¡
Run Configuration ãè¨å®ãã
- Androidã¿ãã§ä»ä½ã£ãããã¸ã§ã¯ããæå®ãã
- Targetã¿ãã§Android Virtual Deviceãä½ã£ã¦ãã
- Commonã¿ãã§Launch in backgroundã®ãã§ãã¯ãã¯ãã
Runã§å®è¡ï¼Androidã®ã¨ãã¥ã¬ã¼ã¿ãç«ã¡ä¸ãã£ã¦Hello, Worldçããã°ã©ã ãå®è¡ãããã¨æåã§ãï¼
ã¾ã¨ã
ãã®ããã«ï¼Eclipseã§Scalaãåä½ãããã«ã¯ï¼æã®æ°ã®ãããªããããã¦ãã¦ããããã¬ããå¿ è¦ãããï¼ãªããªãããã¸ãã§ããï¼ä¸åº¦åä½ãããã¨ããããå¿«é©ã«å©ç¨ã§ãããã§ãï¼
ããããã¦ãã¦ã®å¤ããEclipseé¢ä¿ã ã£ãã®ã§ï¼Eclipseã«æ £ããªã人ã¯ï¼ã³ãã³ãã©ã¤ã³ã§SDKãããã¦éçºããã»ããã¯ã¾ã£ãã¨ãã«èªåã§ãªãã¨ããããããããããªãã§ããï¼vimã§éçºã§ãããããã®ãããã調ã¹ã¦ã¿ããã§ãï¼
ã¨ããã§ï¼Androidã§Scalaãåä½ãããçã®ç®çã¨ãã¦ã¯actorã®å©ç¨ããã£ãã®ã§ããï¼ã¾ã ãããã¦ã¾ããï¼ãªããAndroidã ã¨Threadã®æ±ããããããç¹æ®ã£ã½ãï¼