android - Gradle with java 8 for retrolambda - Android 找不到注释 TargetApi

标签 android gradle java-8 android-gradle-plugin android-annotations

我正在尝试获取 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
How to compile AndroidAnnotations with Google Android Gradle Plugin?

但我不断收到这些错误:

Gradle: error: package android.annotation does not exist

Gradle: error: cannot find symbol class TargetApi

还有那些 gradle 警告:

Gradle: : Supported source version 'RELEASE_6' from annotation processor 'com.googlecode.androidannotations.AndroidAnnotationProcessor' less than -source '1.8'

Gradle: : The following options were not recognized by any processor: '[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 的正确路径。
但是我收到了一些警告:

Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties. Deprecated dynamic property: "aptOutput" on "com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated@4445b7e3", value: "C:\projectpath...".
****************************
variant: debug
manifest: C:\projectpath\build\manifests\debug\AndroidManifest.xml
aptOutput: C:\projectpath\build\source\apt_generated\debug
****************************
Deprecated dynamic property "aptOutput" created in multiple locations.
****************************
variant: release
manifest: C:\projectpath\build\manifests\release\AndroidManifest.xml
aptOutput: C:\projectpath\build\source\apt_generated\release
****************************
****************************
variant: testflight
manifest: 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-sdk/tools/support/annotations.jar 中的annotations.jar 文件解决了这个问题。但这是一种 hack。
我仍在寻找真正的解决方案。

关于android - Gradle with java 8 for retrolambda - Android 找不到注释 TargetApi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21479566/

相关文章:

android - 在我的工具文件夹中找不到 adb.exe

java - 无法在 Maven 本地存储库中找到自定义 Gradle 插件

java - 如何在ConcurrentHashMap(JDK1.8或更高版本)的addCount函数中实现条件(sc == rs + 1 || sc == rs + MAX_RESIZERS)

java - 被 Java8 Collectors.toMap 搞糊涂了

android - Cordova运行错误-找不到安装的生成工具。安装Android构建工具版本19.1.0或更高版本

java - 为什么这个 Java 8 流示例不能编译?

android - 从 Blobstore 获得 500

android - 在android中的 Activity 之间传递非原始类型的数据

android - 在 Android 上保存(存储)简单对象列表

java - IntelliJ IDEA 中通过 Gradle 的 OptaPlanner 依赖项