プログラミング + アカデミック + 何か面白いこと

  1. Programming
  2. 13 view

[Android][Scala][Windows7]Develop Android App with Scala

Target

Scala is better than Java for me,
So I’ll try to develop Android app with scala.
Actually, I wanted to use Ubuntu but it doesn’t work because of USB matter with Virtual Box.
That’s why I choose Windows.

0. Install JDJ

Download “Java SE Development Kit” and istall it from following URL.
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

Add following value to environment variable “path”.

C:\Program Files\Java\jdk1.7.0_51\bin;

1. Install Scala

Install Scala from following URL.
www.scala-lang.org/files/archive/scala-2.10.3.msi

2. Install sbt

Download sbt-launch.jar from following URL,
decompress it and install it to “C:\sbt”.
http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/0.13.1/sbt-launch.jar

Make new file “C:\sbt\sbt.bat” with following content.

set SCRIPT_DIR=%~dp0
java -Dinput.encoding=Cp1252 -Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=384M -jar "%SCRIPT_DIR%sbt-launch.jar" %*

Add following value to “path” environment variable.

C:\sbt;

3. Install Android SDK

Download “Android SDK” from following URL, decompress it and install it to “C:\”.
http://developer.android.com/sdk/index.html

And then add following value to “path” environment variable.
adt-bundle-windows folder name is up to version and CPU type.

C:\Program Files (x86)\scala\\bin;C:\adt-bundle-windows-x86_64-20131030\adt-bundle-windows-x86_64-20131030\sdk\platform-tools;C:\adt-bundle-windows-x86_64-20131030\adt-bundle-windows-x86_64-20131030\sdk\tools;

4. Make project

4-a. Install Android Platform

Double click
C:\adt-bundle-windows-x86_64-20131030\adt-bundle-windows-x86_64-20131030\SDK Manager.exe
and install package.
Everything of Tools and Extras, and some versions.

4-b. Make project template

Check targets with following command.

$ android list
----------
id: 14 or "android-19"
     Name: Android 4.4.2
     Type: Platform
     API level: 19
     Revision: 2
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
     ABIs : armeabi-v7a
----------

Make project template.

$ android create project --target "android-19" --name ScalaTestApp --path "C:\Users\zuqqhi2\Desktop" --activity MainActivity --package org.example.scalatestapp

4-c. Write Scala

Make following new 3 files under scalatestapp folder.

import android.Keys._

android.Plugin.androidBuild

name := "ScalaTestApp"

platformTarget in Android := "android-18"

run <<= run in Android

install <<= install in Android
sbt.version=0.13.0
addSbtPlugin("com.hanhuy.sbt" % "android-sdk-plugin" % "1.0.6")

4-d, Make MainActivity to Scala

package org.sample.scalatestapp;

import android.app.Activity;
import android.os.Bundle;

class MainActivity extends Activity{
  override def onCreate(savedInstanceState:Bundle){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
  }
}

4-e. Compile

$ cd scalatestapp
$ sbt
> compile
> android:package-debug

5. Install real device

Do setting with USB connection with Android from following URL.
http://note.chiebukuro.yahoo.co.jp/detail/n128056

Connect PC and Android with USB.
Go “Setthing”->”Android Information”->”Build Target” and tap for 7 times.
And then,
turn “Setting”->”Development Option”->”USB Debug” on.

Check following command’s result.

$ adb devices
List of devices attached
****** device

Install .apk file to real device with following command.

adb install -r bin/ScalaTestApp-debug.apk

Finish!

Programming recent post

  1. Install sbt 1.0.0 and run sample template

  2. [Machine Learning]Created docker image includ…

  3. [Node.js]How to write batch script with Node.…

  4. [Play][Scala]Develop Request Driven Batch Usi…

  5. [OpenCV][Ruby]Auto check web page design corr…

関連記事

PAGE TOP