Gradle error "Execution failed for task": app: compileDebugJava "when building groovy in android studio
I got an error while building groovy code in android studio. error msg
C:\Users\Administrator\Desktop\lytest110\app\src\main\java\gzzhe\com\lytest110\MainActivity.java:41: error: can't find symbol
Log.d("lytest110", GroovyTest.getMsg());
^
symbol: parameter GroovyTest
possition: class MainActivity
1 error
FAILED
:app:compileDebugGroovy
FAILURE: Build failed with an exception.
my build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.2'
classpath 'me.champeau.gradle:gradle-groovy-android-plugin:0.3.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
build.gradle in the app directory:
apply plugin: 'com.android.application'
apply plugin: 'me.champeau.gradle.groovy-android'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "gzzhe.com.lytest110"
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile files('libs/groovy-2.4.0-beta-3-grooid.jar')
compile files('libs/android-support-v4.jar')
compile fileTree(include: ['*.jar'], dir: 'libs')
// compile 'com.android.support:support-v4:19.+'
}
- I put the groovy file in the main / groovy / package / name directory.
- groovy is annotated with @CompileStatic.
This problem puzzled me a little.
source to share
From your error, it appears that you are calling the Groovy class from Java. According to Android Groovy plugin. He says
Groovy sources must be found inside src/main/groovy. Note that the plugin follows the behavior of the Groovy plugin in Gradle, which means that if you want to be able to have Groovy classes referencing Java classes that themselves reference Groovy classes, then those Java classes must be found inside src/main/groovy too (this is called joint compilation).
So you just put your MainActivity.java in your directory ../ main / groovy / package / name
source to share