Gradle在使用java 8进行retrolambda时-Android找不到注释TargetApi。

5
我正在尝试使用gradle构建Android时使retrolambda起作用。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: 错误:找不到android.annotation包

Gradle: 错误:找不到符号类TargetApi

并且还有这些Gradle警告:

Gradle: :来自注解处理器'com.googlecode.androidannotations.AndroidAnnotationProcessor'的支持源版本'RELEASE_6'低于-source '1.8'

Gradle: :以下选项未被任何处理器识别:'[androidManifestFile]'


这是我的build.gradle文件,使用https://dev59.com/9mQn5IYBdhLWcg3woIUF#16802216(链接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://dev59.com/4eo6XIcBkEYKwwoYKRHd#20675331
        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,每个buildtype的build\source\apt_generated\debug路径都正确打印出来了。
但我收到了一些警告:
动态属性(即按需创建属性)已被弃用,并计划在Gradle 2.0中删除。请阅读http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html以获取有关动态属性替代方案的信息。已弃用的动态属性:“com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated@4445b7e3”上的“aptOutput”,值为“C:\ projectpath ...”。
****************************
变体:debug
清单:C:\ projectpath \ build \ manifests \ debug \ AndroidManifest.xml
aptOutput:C:\ projectpath \ build \ source \ apt_generated \ debug
****************************
在多个位置创建了已弃用的动态属性“aptOutput”。
****************************
变体:release
清单: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。 但仍然没有解决方案...

3个回答

5

我通过直接包含来自android-sdk/tools/support/annotations.jar的annotations.jar文件解决了它。但这有点像是一个hack。
我仍在寻找真正的解决方案。


0

0
将以下代码添加到您的根依赖中 classpath 'me.tatarka:gradle-retrolambda:3.1.0'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接