【发布时间】:2014-01-31 11:57:46
【问题描述】:
我正在尝试让retrolambda 使用 gradle 构建的 Android。对 java 8 的更改导致 android 注解出现了一些问题。
我已经尝试了这些帖子中的几乎所有内容:(在阅读所有这些链接之前先更新 3)
http://code.google.com/p/android/issues/detail?id=55764
https://bitbucket.org/hvisser/android-apt
AndroidAnnotations Nothing Generated, Empty Activity
Android studio + Gradle + Android Annotations
@ 987654326@
但我不断收到这些错误:
Gradle:错误:包 android.annotation 不存在
Gradle:错误:找不到符号类 TargetApi
还有那些 gradle 警告:
Gradle: : 来自注释处理器“com.googlecode.androidannotations.AndroidAnnotationProcessor”的支持源版本“RELEASE_6”低于 -source '1.8'
Gradle: : 以下选项未被任何处理器识别:'[androidManifestFile]'
这是我的 build.gradle 文件,使用 https://stackoverflow.com/a/16802216/860488(链接 3 最受好评的解决方案):
buildscript {
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
classpath 'com.google.guava:guava:14.0.1'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
classpath 'me.tatarka:gradle-retrolambda:1.1.1'
}
}
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
apply plugin: 'android'
apply plugin: 'crashlytics'
apply plugin: 'retrolambda'
ext.daggerVersion = '1.0.0'
ext.androidAnnotationsVersion = '2.7.1'
configurations {
apt
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.google.guava:guava:14.0.1'
compile 'com.crashlytics.android:crashlytics:1.+'
apt "com.googlecode.androidannotations:androidannotations:${androidAnnotationsVersion}"
compile "com.googlecode.androidannotations:androidannotations-api:${androidAnnotationsVersion}"
apt "com.squareup.dagger:dagger-compiler:${daggerVersion}"
compile "com.squareup.dagger:dagger:${daggerVersion}"
}
android {
packagingOptions { //Fix: https://stackoverflow.com/a/20675331/860488
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileSdkVersion 10
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 10
buildConfigField "boolean", "useProductionServices", "true"
}
buildTypes {
testflight.initWith(buildTypes.debug)
debug {
packageNameSuffix ".debug"
buildConfigField "boolean", "useProductionServices", "false"
}
testflight {
packageNameSuffix ".testflight"
buildConfigField "boolean", "useProductionServices", "true"
}
release {
buildConfigField "boolean", "useProductionServices", "true"
}
}
}
retrolambda {
compile "net.orfjackal.retrolambda:retrolambda:1.1.2"
jdk System.getenv("JAVA8_HOME")
}
android.applicationVariants.all { variant ->
aptOutput = file("${project.buildDir}/source/apt_generated/${variant.dirName}")
println "****************************"
println "variant: ${variant.name}"
println "manifest: ${variant.processResources.manifestFile}"
println "aptOutput: ${aptOutput}"
println "****************************"
variant.javaCompile.doFirst {
println "*** compile doFirst ${variant.name}"
aptOutput.mkdirs()
variant.javaCompile.options.compilerArgs += [
'-processorpath', configurations.apt.getAsPath(),
'-AandroidManifestFile=' + variant.processResources.manifestFile,
'-s', aptOutput
]
}
}
我正在使用 Intellij EDEA 13.0.2。
我在 android.applicationVariants.all 中没有看到 println 语句内容的任何输出 - 我应该在哪里看到它们?
关于如何解决这个问题的任何线索?
更新 1:
我已经尝试使用 Groovy 调试 build.gradle 并且每件事都打印得很好。每个构建类型的 build\source\apt_generated\debug 的正确路径。
但我收到了一些警告:
按需创建属性(也称为动态属性)已 已弃用,并计划在 Gradle 2.0 中删除。请阅读 http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html 有关替换动态属性的信息。已弃用 动态属性:“aptOutput”开启 "com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated@4445b7e3", 值:“C:\projectpath...”。
******************************
变体:调试
清单:C:\projectpath\build\manifests\debug\AndroidManifest.xml
apt输出:C:\projectpath\build\source\apt_generated\debug
******************************
在多个位置创建的已弃用动态属性“aptOutput”。
******************************
变体:发布
清单:C:\projectpath\build\manifests\release\AndroidManifest.xml
aptOutput: C:\projectpath\build\source\apt_generated\release
******************************
******************************
变体:testflight
清单:C:\projectpath\build\manifests\testflight\AndroidManifest.xml
aptOutput: C:\projectpath\build\source\apt_generated\testflight
******************************
并且文件夹 apt_generated\debug 中没有内容。有什么线索吗?
更新 2:
我尝试使用Dodges answer,它产生了相同的输出(除了警告),但文件夹 apt_generated\debug 中仍然没有内容。
更新 3:
我发现问题与链接的帖子有关。它是找不到的 android.annotations - 不是androidannotations。
但仍然没有解决方案..
【问题讨论】:
标签: android gradle java-8 android-gradle-plugin android-annotations