2014-01-31 80 views
5

我試圖讓retrolambda與由gradle構建的Android一起工作。對java 8的改變導致了一些與android註釋有關的問題。Gradle with java 8 for retrolambda - Android無法找到註釋TargetApi

我已經試過幾乎所有從這些帖子:
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?

但我不斷收到這些錯誤回報(SE更新3閱讀這些鏈接前):

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]'


這是使用https://stackoverflow.com/a/16802216/860488(鏈接3最upvoted溶液)我的build.gradle文件:

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和每一件事印刷精美。爲每個構建類型構建\ 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.and[email protected]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 \調試文件夾中沒有的內容。任何線索?

更新2:
我試圖與Dodges answer它生產除了警告相同的輸出,但仍然在目錄apt_generated \調試沒有內容。

更新3:
我發現問題是不同的,鏈接的帖子是關於。這是android.annotations,它無法找到 - 不是androidannotations。 但仍然沒有解決方案..

回答

5

我已經通過直接包括來自android-sdk/tools/support/annotations.jar的annotations.jar文件解決了它。但這是一種破解。
我仍在尋找一個真正的解決方案。

0

添加到您的根依賴 類路徑「me.tatarka:gradle這個-retrolambda:3.1。0'

相關問題