android-studioandroid-gradle-pluginandroid-annotationsandroid-apt

Gradle 2.0.0-beta4 makes AndroidAnnotation doesn't work


With 'com.android.tools.build:gradle:1.5.0' and 'com.neenbedankt.gradle.plugins:android-apt:1.8', AndroidAnnotation works well with processing the annotation. But after I update to 'com.android.tools.build:gradle:2.0.0-beta4' for instant run, it seems AndroidAnnotation cannot generate @EApplication. Is there any way to fix this?


Solution

  • You have to use AA 4.0-SNAPSHOT for this.

    Add repository for AA snapshots:

    repositories {
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
    }
    

    Change AA version to 4.0-SNAPSHOT

    dependencies {
       compile "org.androidannotations:androidannotations-api:4.0-SNAPSHOT"
       apt "org.androidannotations:androidannotations:4.0-SNAPSHOT"
    }
    

    Add library:true to apt argument:

    apt {
        arguments {
            androidManifestFile variant.outputs[0].processResources.manifestFile
            resourcePackageName android.defaultConfig.applicationId
    
            //only for Android Annotations 4.0-SNAPSHOT 
            library 'true'
        }
    }
    

    This way AA does not validate the presence of EApplication, EActivity etc. in your manifest, hence it will compile with Instant Run. The cause is that Instant Run changes your application class in the manifest, that is why AA cannot find the generated one in it.

    Update: AA 4.0-SNAPSHOT is modularized, that means you have to add the AA REST client module as well in your build.gradle

    org.androidannotations:rest-spring:4.0-SNAPSHOT
    org.androidannotations:rest-spring-api:4.0-SNAPSHOT
    

    And you have to change the REST annotation imports to org.androidannotations.rest.spring.annotations.*.