Help us understand the problem. What is going on with this article?

groovyでAndroidアプリを開発

More than 5 years have passed since last update.

groovyでAndroidアプリが書けるようになったらしいので早速触ってみた。

環境

  • Android Studio 0.5.9
  • Android SDK Tools 22.6.3
  • Android SDK Platform-tools 19.0.2
  • Android SDK Build-tools 19.1
  • groovy-2.4.0-SNAPSHOT-grooid
  • gradle 1.11
  • gradle plugin 0.9.+

ビルド

参考のリポジトリにはjcenter()からgroovy-2.4.0-SNAPSHOT-grooid.jarを取得していますが、not foundになっていました。

http://jcenter.bintray.com/org/codehaus/groovy/groovy-json/2.4.0-SNAPSHOT/groovy-json-2.4.0-SNAPSHOT.jar
http://jcenter.bintray.com/org/codehaus/groovy/groovy/2.4.0-SNAPSHOT/groovy-2.4.0-SNAPSHOT-grooid.jar

groovy-coreのコードをGitHubから取得してビルドします。

$ git clone https://github.com/groovy/groovy-core
$ cd groovy-core
$ ./gradlew clean dist

...

$ ls ./target/libs/
groovy-2.4.0-SNAPSHOT-grooid.jar        groovy-all-2.4.0-SNAPSHOT-indy.jar
groovy-2.4.0-SNAPSHOT-indy.jar          groovy-all-2.4.0-SNAPSHOT.jar
groovy-2.4.0-SNAPSHOT.jar

./target/libs以下にjarが生成されます。
groovy-2.4.0-SNAPSHOT-grooid.jarlibsに入れbuild.gradleに*.groovyをコンパイルするtaskを追記してAndroidプロジェクトをビルドします。

android.applicationVariants.all {
    task "groovy${name}Compile"(type: GroovyCompile) {
        source = javaCompile.source + fileTree('src/main/java').include('**/*.groovy')
        destinationDir = javaCompile.destinationDir
        classpath = javaCompile.classpath
        groovyClasspath = classpath
        sourceCompatibility = '1.6'
        targetCompatibility = '1.6'
        doFirst {
            def runtimeJars = plugins.findPlugin(com.android.build.gradle.AppPlugin).runtimeJars
            classpath = files(runtimeJars) + classpath
        }
    }
    javaCompile.dependsOn("groovy${name}Compile")
    javaCompile.enabled = false
}

ちなみにgradle 1.11で gradle plugin 0.9.+でないとAndroidアプリのビルドが通りませんでした。

サンプルコード

https://github.com/epy0n0ff/groovy-android-sample

おまけ

Javaとgroovyで書いてdebug buildしたアプリをbaksmaliにかけてsmaliにしたものです。
https://gist.github.com/epy0n0ff/ea658a4b2b879784428d

参考

https://github.com/melix/gr8confagenda
https://speakerdeck.com/melix/groovy-on-android

epy0n0ff
へたれぷろぐらまー
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした