2014-11-04 53 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目錄

相關問題