Scala + Android + Eclipse â æ¸ãç´ãver
æ¨æ¥æ¸ããå 容ããã©ãã·ã¥ã¢ãããã¦ã誰ãã®å½¹ã«ç«ã¤ã¨ã³ããªã«ãªãããé å¼µãã
http://www.scala-lang.org/node/160
ä¸è¨ãåèã«é å¼µã£ã¦ã¿ãã
ç°å¢ã¯Mac OS X 10.6 + Eclipse 3.5
AndroidSDKã¨ADPã¯æ¢ã«å
¥ã£ã¦ãç¶æ
ã
Scalaã¤ã³ã¹ãã¼ã«
åã¯Mac OS X 10.6 ãªã®ã§ããã以å¤ã®ç°å¢ã®äººã¯èªåã§é å¼µã£ã¦ãã ããã
MacPortsã§Scalaãå ¥ããããã®ã¨ã³ããªå·çæ㯠scala @2.7.7_0 (active)
sudo port install scala
scala-androidã¤ã³ã¹ãã¼ã«
Scalaã«ã¯sbazã£ã¦ãããCPANã¨ãRubyGemsçãªãã®ãããã®ã... ç¥ããªãã£ãã
sbaz installed
ã§scala-androidå ¥ã£ã¦ãªãã確èªãå½ããåã ãã©å ¥ã£ã¦ãªãã
ã§ç¢ºèªããã£ããscala-android (2.7.0-final, 2.6.1-final)
ã¤ã³ã¹ãã¼ã«ã§ããã
sbaz installed
確èªãOKã
Eclipseã®Scalaãã©ã°ã¤ã³ã¤ã³ã¹ãã¼ã«
å ã«Scalaãã©ã°ã¤ã³ãå ¥ãã¦ããã
ãã£ã¡ãããã©ã°ã¤ã³çªã£è¾¼ãã§ãé¢åããããã©ç´ ã®Scala使ã£ãããã¸ã§ã¯ããã¡ããã¨åãã確èªã
Scala+Androidããã¸ã§ã¯ãä½æ
Eclipseèµ·åãã¦ãAndroidããã¸ã§ã¯ããä½æããã
以ä¸ã®ä½æ¥ãè¡ãåã«ã.projectã®ããã¯ã¢ãããä½æãã¦ããã
cp .project .project.bak
Androidããã¸ã§ã¯ããå³ã¯ãªãã¯ãã¦ScalaâScalaãã¤ãã£ã¼ã®è¿½å ããã
ããã¸ã§ã¯ãã®ãã«ãã¼ããJavaãã«ãã¼ãã½ãã£ã¡ãããã¦ãã¾ãã
ã¨ãããããã®æç¹ã§ä¸åèµ·åãã¦ã¿ããHello World, HelloJava! ã¨è¡¨ç¤ºãããã¯ãã
ãã®ã¾ã¾ã ã¨ã©ãããJavaã®ã½ã¼ã¹ããã¾ãæ±ããªãã£ã½ãã®ã§ãããã»ã©ããã¯ã¢ããã¨ã£ã¦ããã.projectãããJavaãã«ãã¼ã®è¡ãæã£ã¦ãã¦å¾©æ´»ããã¦ããã
ã§ãããã¸ã§ã¯ãã®Javaã®ãã«ããã¹ã®ã©ã¤ãã©ãªã¼ã¿ãããScala Library version 2.7.7.finalãé¤å»ãå¤é¨JARã®è¿½å ã§android-library.jarã追å ããããã ãå ´æãããããè²ã 調ã¹ã¦
port contents scala
ã§èª¿ã¹ãããèªåã®å ´å /opt/local/share/scala/lib ã«ãã£ãã
åèãµã¤ãã«æ¸ãã¦ãã android-library.jarããªã...ãã©ã調ã¹ã¦ã¿ãã¨scala-android.jarã§ããã¿ããã
ããã¸ã§ã¯ãã®Javaã®ãã«ããã¹ã®ã©ã¤ãã©ãªã¼ã¿ãã«binãã©ã«ãã追å ãããããããªãã¨ä¸æããã¨åããªãå ´åããããããã®ã§ãã¾ããªãçã«ã(GUIããã©ããããåãããªãã£ãã®ã§ç´æ¥ç·¨éããã)
ããã§ã ãããOKãªã¯ããªã®ã§ãScalaã§Activityã¨ãä½ã£ã¦ã¿ãã
package jp.ne.hatena.vvakame import _root_.android.app.Activity import _root_.android.content.Intent import _root_.android.os.Bundle import _root_.android.view.View import _root_.android.widget.Button class HelloScala extends Activity { import android.view.View.OnClickListener override def onCreate(savedInstanceState: Bundle):Unit = { super.onCreate(savedInstanceState) setContentView(R.layout.hello_scala) findViewById(R.id.changeActivityButton).asInstanceOf[Button] .setOnClickListener(()=>{ startActivity(new Intent(this, classOf[HelloJava])) }) } implicit def funcOnClick(f:View => Unit): OnClickListener = { new OnClickListener(){ def onClick(v: View) = f.apply(v) } } implicit def funcOnClick0(f:() => Unit): OnClickListener = { new OnClickListener() { def onClick(v: View) = f.apply } } }
ãããã¡ããã¨åãã¦ãJavaã§æ¸ããActivityã¸é·ç§»ã§ããã
ãã¾ã
http://github.com/vvakame/HelloScalaForAndroid
âãããä¸è¨ã®ä½æ¥ãçµãã£ãç¶æ
ã®ãå³åãããç¶æ
ã®Eclipseããã¸ã§ã¯ããå
¥æã§ããã¾ãã
ã¤ã³ãã¼ãããå¾ã«ãããã¸ã§ã¯ãâã¯ãªã¼ã³ ã¨ããã»ããããããã
Scalaã«ããActivityâJavaã«ããActivityâScal(ç¥ ã¨é·ç§»ã§ãã¾ãã
.classpath å
ã®ãscala-android.jarã®ãã¹ãèªåã®ç°å¢ç¨ã«æ´ããã®ãå¿ããªãããã«ã
ãã®ã¨ã³ããªå·çæã®ãªãã¸ã§ã³ã¯ 627c138d ã§ãã
ä½æã«ã¯ã以ä¸ã®ãµã¤ããåèã«ãã¾ããã
http://www.ibm.com/developerworks/jp/opensource/library/os-eclipse-scala/
ç¾ç¶ã®åé¡ç¹
æ¨æ¥ã®åé¡ç¹ã¯ãã«ãã¼ã«Javaãã«ãã¼ãå ãããã¨ã§ã ãã¶è§£æ±ºãã¾ãããæ®ãã¯...
- apkã®ãµã¤ãºã§ãããHelloScala.apkã700KBããããããå¥ã®æå ã®ããã¸ã§ã¯ãã¯ç»åãªã©ã®ãªã½ã¼ã¹è¾¼ã¿ã§27KBã¨ããproguardã¨ããjarãã¡ã¤ã«ã®å§ç¸®,æé©å,é£èªåãã¼ã«ã§ä¸è¦classãçããããã¦ããªãè¦é å§ç¸®ã§ããã¨èããã®ã§ä»åº¦èª¿ã¹ããScalaé¢ä¿ãªãæ©æµããã¯ãã