2014-11-04 106 views
3

在android studio中构建groovy代码时出现错误。 错误味精是gradle错误“任务执行失败”:app:compileDebugJava'“,而在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() 
    } 
} 

中的build.gradle在app目录:

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.+' 
} 
  1. 我已经把常规文件到主/ groovy/package/name目录。
  2. groovy用@CompileStatic注释。

这个问题困扰了我好几天。

回答

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目录

相关问题