Groovy in Android - how to run Hello world -
i'm having trouble referencing groovy class i've created. here steps:
my build.gradle file has required dependencies:
apply plugin: 'com.android.application'
apply plugin: 'groovyx.grooid.groovy-android'
android { compilesdkversion 22 buildtoolsversion "21.1.2"
packagingoptions { // workaround http://stackoverflow.com/questions/20673625/android-gradle-plugin-0-7-0-duplicate-files-during-packaging-of-apk exclude 'meta-inf/license.txt' exclude 'meta-inf/groovy-release-info.properties' } defaultconfig { applicationid "com.example.uen.myrxjavaandroidproject" minsdkversion 17 targetsdkversion 22 versioncode 1 versionname "1.0" } buildtypes { release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile filetree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.2.0' compile 'com.netflix.rxjava:rxjava-android:0.20.7' compile 'com.squareup:otto:1.3.5' compile 'org.codehaus.groovy:groovy:2.4.3:grooid' }
and gradle synched successfully.
then created folder under main called 'groovy' such project structure looks following:
notice have groovy class called "hello", looks this:
public class hello { string name; public void sayhello() { system.out.println("hello "+getname()+"!"); } public void setname(string name) { this.name = name; } public string getname() { return name; }
}
now in mainactivity.java class try instantiate hello class not being recognized. doing this:
hello myhello = new hello();
what doing wrong ?
if want use groovy class java sources, java file must found in "groovy" directory. it's done way enforce joint compilation (java classes consuming groovy classes or other way).
and independently of this, sake of grooviness, hello
groovy class can reduced to:
class hello { string name void sayhello() { println "hello $name!" } }
Comments
Post a Comment