Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial

  • Loading branch information...
commit fb9f02a1e05edc79e8e509df70b80e2c16fc7356 0 parents
@elight authored
2  .gitignore
@@ -0,0 +1,2 @@
+gen
+bin
15 AndroidManifest.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.myproject"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <application android:label="@string/app_name">
+ <activity android:name=".MyActivity"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
10 README.md
@@ -0,0 +1,10 @@
+
+# Hello World, Android (rake)
+
+A small sample Hello World App for use with Android SDK 1.5 + Rake. This is a
+quick&dirty proof-of-concept hack to build android projects using Rake instead
+of ant. You need to have the various command line build tools (aapt, javac, ...)
+in your PATH.
+
+ $ emulator -avd 1.5 &
+ $ rake install ANDROID_SDK=</path/to/sdk>
169 Rakefile
@@ -0,0 +1,169 @@
+require 'rubygems'
+require 'rake'
+require 'rexml/document'
+require 'rake/clean'
+
+fail "need SCALA_HOME set" unless ENV['SCALA_HOME']
+fail "need ANDROID_SDK set" unless ENV['ANDROID_SDK']
+
+def manifest
+ @parsed ||= begin
+ doc = REXML::Document.new(File.read('AndroidManifest.xml'))
+ {
+ :package => doc.root.attribute('package').to_s
+ }
+ end
+end
+
+app_pkg = manifest[:package]
+project = app_pkg.gsub(/\./, '_')
+
+sdk_location = ENV['ANDROID_SDK']
+src = 'src'
+gen = 'gen'
+res = 'res'
+bin = 'bin'
+libs = 'libs'
+assets = 'assets'
+classes = "#{bin}/classes"
+classes_jar = "/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/classes.jar"
+scala_jars = %w(scala-compiler.jar scala-library.jar).map { |l| File.join(ENV['SCALA_HOME'], 'lib', l) }
+
+ap_ = "#{bin}/#{project}.ap_"
+apk = "#{bin}/#{project}.apk"
+
+android_jar = "#{sdk_location}/platforms/android-2.0/android.jar"
+android_aidl = "#{sdk_location}/platforms/android-2.0/framework.aidl"
+intermediate_dex_location = "#{bin}/classes.dex"
+
+directory gen
+directory bin
+directory classes
+dirs = [gen, bin, classes]
+
+CLEAN.include(gen, bin)
+CLASSPATH = FileList["#{libs}/**/*.jar"] + scala_jars
+BOOTCLASSPATH = FileList[android_jar, classes_jar]
+
+# Extensions for standard rake classes.
+module Rake
+ class FileList
+ def to_cp(sep = File::PATH_SEPARATOR)
+ self.join(sep)
+ end
+ end
+end
+
+def compile_java(dest, *srcdirs)
+ files = FileList.new
+ srcdirs.each do |d|
+ files.include("#{d}/**/*.java")
+ end
+
+ sh "javac", "-target", "1.5", "-g", "-bootclasspath", BOOTCLASSPATH.to_cp, "-nowarn", "-Xlint:none",
+ "-sourcepath", srcdirs.join(File::PATH_SEPARATOR), "-d", dest ,"-classpath", CLASSPATH.to_cp, *files
+end
+
+def compile_scala(dest, *srcdirs)
+ files = FileList.new
+ srcdirs.each do |d|
+ files.include("#{d}/**/*.scala")
+ end
+
+ sh "scalac", "-g", "-bootclasspath", BOOTCLASSPATH.to_cp, "-nowarn",
+ "-sourcepath", srcdirs.join(File::PATH_SEPARATOR), "-d", dest ,"-classpath", CLASSPATH.to_cp, *files
+end
+
+task :default => :debug
+
+task :resource_src => dirs do
+ sh "aapt package -m -J #{gen} -M AndroidManifest.xml -S #{res} -I #{android_jar}"
+end
+
+
+task :aidl => dirs do
+ FileList["#{src}/**/*.aidl"].each do |f|
+ sh "aidl -p #{android_aidl} -I #{src} -o #{gen} #{f}"
+ end
+end
+
+task :compile => [:resource_src, :aidl] do
+ #compile_java(classes, gen)
+ compile_scala(classes, src, gen)
+end
+
+task :shake => [ :compile ] do
+ sh "java", "-Xmx512M", "-jar", "proguard/proguard.jar",
+ "-injars", "#{classes}:#{scala_jars.last}(!META-INF/MANIFEST.MF,!library.properties)",
+ "-outjars", "#{bin}/out.min.jar",
+ "-libraryjars", android_jar,
+ "-dontwarn",
+ "-dontoptimize",
+ "-dontobfuscate",
+ "-keep", "public class * extends android.app.Activity"
+end
+
+task :dex => :shake do
+ sh "dx", *["-JXmx512M", "--dex", "--output=#{intermediate_dex_location}", "#{bin}/out.min.jar"]
+end
+
+task :package_resources do
+ opts = ["package", "-f", "-M", "AndroidManifest.xml", "-I", android_jar, "-S", res, "-F", ap_]
+ opts += ["-A", assets] if File.directory?(assets)
+ sh "aapt", *opts
+end
+
+apkbuilder = Proc.new do |signed|
+ args = [apk, "-f", intermediate_dex_location, "-rf", src, "-z", ap_]
+ args += [ "-rj", libs] if File.directory?(libs)
+ args += ["-u" ] unless signed
+
+ sh "apkbuilder", *args
+end
+
+desc "Builds the application and sign it with a debug key."
+task :debug => [:dex, :package_resources] do
+ apkbuilder.call(true)
+end
+
+desc "Builds the application and sign it with a release key."
+task :release => [:dex, :package_resources] do
+ apkbuilder.call(false)
+ Rake::Task['package:sign'].invoke
+end
+
+def adb(*args)
+ args.unshift '-s', ENV['DEVICE'] if ENV['DEVICE']
+ sh "adb", *args
+end
+
+desc "Installs the debug package onto a running emulator or device (DEVICE=<serialno>)."
+task :install => :debug do
+ adb 'install', apk
+end
+
+desc "Installs the debug package on a running emulator or device that already has the application (DEVICE=<serialno>)."
+task :reinstall => :debug do
+ adb 'install', '-r', apk
+end
+
+desc "uninstall the application from a running emulator or device (DEVICE=<serialno>)."
+task :uninstall do
+ adb 'uninstall', app_pkg
+end
+
+namespace :package do
+ desc "verify signature of the package."
+ task :verify do
+ sh "jarsigner", "-verify", "-certs", "-verbose", apk
+ end
+
+ desc "sign the package."
+ task :sign do
+ alias_name = "alias"
+ keystore = "keystore"
+ sh "jarsigner", "-verbose", "-keystore", keystore, apk, alias_name
+ end
+end
+
+
BIN  proguard/proguard.jar
Binary file not shown
13 res/layout/main.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ >
+<TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="Hello World, MyActivity!"
+ />
+</LinearLayout>
+
4 res/values/strings.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">MyActivity</string>
+</resources>
16 src/scala/com/example/myproject/MyActivity.scala
@@ -0,0 +1,16 @@
+package com.example.myproject
+
+import _root_.android.app.Activity
+import _root_.android.os.Bundle
+import _root_.android.widget.TextView
+
+class MyActivity extends Activity {
+
+ override def onCreate(savedInstanceState: Bundle) {
+ super.onCreate(savedInstanceState)
+ val tv = new TextView(this)
+ tv.setText("Hello Android, I'm Scala!")
+ setContentView(tv)
+ // setContentView(R.layout.main)
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.