我在android studio中构建groovy代码时遇到错误。 错误消息是
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.
我的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()
}
}
app目录中的build.gradle:
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.+'
}
这个问题困扰了我好几天。
答案 0 :(得分:0)
从您的错误看来,您似乎正在使用Java调用Groovy类。根据Android Groovy插件自述文件。它说
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).
所以你只需将MainActivity.java放到../main/groovy/package/name目录