Question

I am trying to get retrolambda to work with Android build by gradle. The change to java 8 has caused some problems with android annotations.

I have tried almost everything from these posts: (Se update 3 before reading all those links)
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?

But I keeps getting these erros:

Gradle: error: package android.annotation does not exist

Gradle: error: cannot find symbol class TargetApi

And those gradle warnings:

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


This is my build.gradle file using https://stackoverflow.com/a/16802216/860488(link 3 most upvoted solution):

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

I am using Intellij EDEA 13.0.2.
I don't se any output with the content of the println statements in the android.applicationVariants.all - where should I see them?

Any clue on how to fix this?

Update 1:
I have tried debugging the build.gradle with Groovy and every thing is printed fine. The correct paths to build\source\apt_generated\debug for each buildtype.
But I am getting some warnings:

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
****************************

And there is no content in the folder apt_generated\debug. Any clue?

Update 2:
I tried with Dodges answer which produced same output except the warnings, but still no content in the folder apt_generated\debug.

Update 3:
I found out that the issue is something different that the linked posts are about. It is the android.annotations that it can't find - not androidannotations. But still no solution..

Était-ce utile?

La solution

I have solved it by directly including the annotations.jar file from android-sdk/tools/support/annotations.jar. But this is kind of a hack.
I am still looking for a real solution.

Autres conseils

If you wanna try Java8 and Jack&Jill. Try this set up:

https://github.com/nickwph/annotation-processor-with-java8-jack-and-jill-android

add this to your root dependency classpath 'me.tatarka:gradle-retrolambda:3.1.0'

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top