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:

enter image description here

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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -