【问题标题】:gradle error "Execution failed for task ':app:compileDebugJava' " while build groovy in android studio在android studio中构建groovy时,gradle错误“任务':app:compileDebugJava'执行失败”
【发布时间】:2014-12-31 14:40:52
【问题描述】:

我在 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.+'
}
  1. 我已将 groovy 文件放入 main/groovy/package/name 目录。
  2. groovy 使用@CompileStatic 进行注释。

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

【问题讨论】:

    标签: groovy build gradle android-studio


    【解决方案1】:

    从您的错误来看,您似乎正在使用 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 目录中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-25
      • 1970-01-01
      • 1970-01-01
      • 2015-12-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多