public
Created

Sample config for android-plugin/library pull request

  • Download Gist
main.sbt
Scala
1 2 3 4 5 6 7 8
import sbt._
import Keys._
import AndroidKeys._
 
libraryDependencies ++= Seq(
"com.actionbarsherlock" % "library" % "4.0.0-SNAPSHOT" artifacts(Artifact("library", "apklib", "apklib")),
"android" % "compatibility-v4" % "r3-SNAPSHOT"
)
project/build.scala
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
import sbt._
 
import Keys._
import AndroidKeys._
 
object General {
val settings = Defaults.defaultSettings ++ Seq (
name := "Apklib Sample",
version := "0.1",
versionCode := 0,
scalaVersion := "2.9.1",
platformName in Android := "android-15",
resolvers += "ActionBarSherlock snapshots" at "http://r.jakewharton.com/maven/snapshot/"
)
 
val proguardSettings = Seq (
useProguard in Android := true
)
 
lazy val fullAndroidSettings =
General.settings ++
AndroidProject.androidSettings ++
TypedResources.settings ++
proguardSettings ++
AndroidManifestGenerator.settings ++
AndroidMarketPublish.settings ++ Seq (
keyalias in Android := "change-me",
libraryDependencies += "org.scalatest" %% "scalatest" % "1.7.RC1" % "test"
)
}
 
object AndroidBuild extends Build {
lazy val main = Project (
"Apklib Sample",
file("."),
settings = General.fullAndroidSettings
)
 
lazy val tests = Project (
"tests",
file("tests"),
settings = General.settings ++
AndroidTest.settings ++
General.proguardSettings ++ Seq (
name := "Apklib SampleTests"
)
) dependsOn main
}
project/plugins.sbt
Scala
1 2 3 4 5 6 7
resolvers += "nexus snapshots" at "http://nexus.scala-tools.org/content/repositories/snapshots"
 
addSbtPlugin("org.scala-tools.sbt" % "sbt-android-plugin" % "0.6.1-SNAPSHOT")
 
resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"
 
addSbtPlugin("com.github.mpeltonen" %% "sbt-idea" % "1.0.0")
src/main/AndroidManifest.xml
XML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.gist.apklibsample">
 
<application
android:icon="@drawable/android:star_big_on"
android:label="@string/app_name"
android:debuggable="true">
 
<activity android:label="@string/app_name" android:name=".MainActivity" android:theme="@style/Theme.Sherlock">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
 
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15"/>
</manifest>
src/main/res/layout/main.xml
XML
1 2 3 4 5 6 7 8 9 10 11
<?xml version="1.0" encoding="utf-8"?>
 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
 
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
src/main/res/values/strings.xml
XML
1 2 3
<resources>
<string name="app_name">Apklib Sample</string>
</resources>
src/main/scala/MainActivity.scala
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
package com.github.gist.apklibsample
 
import _root_.android.app.Activity
import _root_.android.os.Bundle
 
import com.actionbarsherlock.app.SherlockActivity
 
class MainActivity extends SherlockActivity with TypedActivity {
override def onCreate(bundle: Bundle) {
super.onCreate(bundle)
setContentView(R.layout.main)
 
findView(TR.textview).setText("hello, world!")
}
}
src/test/scala/Specs.scala
Scala
1 2 3 4 5 6 7 8 9 10
import com.github.gist.apklibsample
import org.scalatest.matchers.ShouldMatchers
import org.scalatest.FunSpec
 
class Specs extends FunSpec with ShouldMatchers {
describe("a spec") {
it("should do something") {
}
}
}
tests/src/main/AndroidManifest.xml
XML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.github.gist.apklibsample.tests">
<application>
<activity android:name=".MainActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
 
<uses-library android:name="android.test.runner"/>
</application>
 
<instrumentation android:label="Tests"
android:targetPackage="com.github.gist.apklibsample"
android:name="android.test.InstrumentationTestRunner"/>
 
<uses-sdk android:minSdkVersion="15"/>
</manifest>
tests/src/main/res/values/strings.xml
XML
1 2 3
<resources>
<string name="app_name">Apklib Sample</string>
</resources>
tests/src/main/scala/Tests.scala
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
package com.github.gist.apklibsample.tests
 
import com.github.gist.apklibsample._
import junit.framework.Assert._
import _root_.android.test.AndroidTestCase
import _root_.android.test.ActivityInstrumentationTestCase2
 
class AndroidTests extends AndroidTestCase {
def testPackageIsCorrect() {
assertEquals("com.github.gist.apklibsample", getContext.getPackageName)
}
}
 
class ActivityTests extends ActivityInstrumentationTestCase2(classOf[MainActivity]) {
def testHelloWorldIsShown() {
val activity = getActivity
val textview = activity.findView(TR.textview)
assertEquals(textview.getText, "hello, world!")
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.