Realm-java: Feature Request: Native support on annotationProcessor Gradle Task (2.2.0)

Created on 18 Jun 2016  路  16Comments  路  Source: realm/realm-java

Hi Realm team - If you can have this compatible with annotationProcessor as well aside from the apt plugin, it can reduce the dependency on additional 3rd party plugin for the annotation processing natively supported on Android N. Thanks.

Here's the setup to validate the support:
parent build,gradle should be using
classpath 'com.android.tools.build:gradle:2.2.0-alpha1'

The following line is removed on the application build,gradle
apply plugin: 'com.neenbedankt.android-apt'

T-Enhancement

Most helpful comment

Hi @cmelchior and @realm/java, it has been a month and a half, and we are now at the point where the Android Gradle plugin is stable at version 2.2.2, and annotationProcessor along with it.

So it came as a surprise to me today when I discovered that the Realm plugin's continued inclusion of android-apt is actually breaking the annotationProcessor feature silently!

The problem here is that because the Realm plugin includes it, android-apt is applied _silently_ whenever you do apply 'realm-android'.
The application of android-apt, in turn, causes the built-in annotationProcessor feature to fail silently鈥攁ny lines using it are completely ignored during the build process. As a side-effect, it also allows the use of apt despite me not having explicitly included android-apt myself.

This is, quite understandably, incredibly frustrating! I feel that the Realm team needs to make fixing this issue a top priority because, again, the Realm gradle plugin _is currently overriding and breaking functionality of the Android gradle plugin through its inclusion of android-apt_.

All 16 comments

Just verified that it's working using
classpath 'com.android.tools.build:gradle:2.2.0-alpha3'
Thanks.
Edit: Crashes when using butterknife. We can close this in the meantime while Butterknife has issues. Thanks.

Hi @peterbetos
Dropping 3rd party plugins like Android APT would definitely be nice if possible, but we don't have any plans to do so while 2.2.0 is still in alpha/beta. However we will re-evaluate once it becomes stable.

The new 'com.android.tools.build:gradle:2.2.0-alpha6' version works for the latest Realm version. We can close this if preferred. Thanks.

Hi @peterbetos Thanks for the update. I think it is fine to keep this open as removing android-apt would be nice if possible. Hopefully a stable 2.2.0 isn't that far out.

We can now re-open this. 2.2.0 stable release is already available. Thanks.

Yes, we should take a 2nd look at what is required to remove APT.

Hi @cmelchior and @realm/java, it has been a month and a half, and we are now at the point where the Android Gradle plugin is stable at version 2.2.2, and annotationProcessor along with it.

So it came as a surprise to me today when I discovered that the Realm plugin's continued inclusion of android-apt is actually breaking the annotationProcessor feature silently!

The problem here is that because the Realm plugin includes it, android-apt is applied _silently_ whenever you do apply 'realm-android'.
The application of android-apt, in turn, causes the built-in annotationProcessor feature to fail silently鈥攁ny lines using it are completely ignored during the build process. As a side-effect, it also allows the use of apt despite me not having explicitly included android-apt myself.

This is, quite understandably, incredibly frustrating! I feel that the Realm team needs to make fixing this issue a top priority because, again, the Realm gradle plugin _is currently overriding and breaking functionality of the Android gradle plugin through its inclusion of android-apt_.

Hi @bkromhout You are right. With 2.2 now stable we should add support for this quickly so people can choose whatever method they want.

Ahh so that's why it ruins Butterknife when I used annotationProcessor. The task must have been discontinued after it failed on realm. Anyway I'm switching our project to DataBinding now, but we should still support this. Thanks.

@peterbetos well it would most definitely still work with apt scope instead of annotationProcessor scope

@cmelchior and @zaki50, thanks for the prompt reply and quick action. I look forward to seeing this resolved!

Hi @zaki50,

TL;DR: is plugin compatible with snapshot build ?

So, some explanations:

I've installed the latest snapshot on new Android project (just an empty one), with builds tools 2.2.2.

~/RealmTest/app/build.gradle
Error:Failed to resolve: annotationProcessor

The project level build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven {
            url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        classpath "io.realm:realm-gradle-plugin:2.2.0-SNAPSHOT"
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

The application level build.gradle

apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "testing.realm.realmtest"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.0.0'
    testCompile 'junit:junit:4.12'
}

Looking into the Gradle plugin, I understand it put dependencies automatically

So, in application level build.gradle, desactivating plugin and putting dependencies myself :

apply plugin: 'com.android.application'
//apply plugin: 'realm-android'

dependencies {
    [...]
    testCompile 'junit:junit:4.12'

    compile "io.realm:realm-annotations:2.2.0-SNAPSHOT"
    annotationProcessor "io.realm:realm-annotations:2.2.0-SNAPSHOT"
    annotationProcessor "io.realm:realm-annotations-processor:2.2.0-SNAPSHOT"
}

Without annotationProcessor "io.realm:realm-annotations-processor:2.2.0-SNAPSHOT" gradle sync correctly, but application compilation failed ; with it, sync failed (and so compilation too).

Thanks.

@Gounlaf thank you for reporting.

snapshot build of realm-annotations-processor does not seem to be uploaded to jfrog.
http://oss.jfrog.org/oss-snapshot-local/io/realm/realm-annotations-processor/
I'll investigate it.

If you can build locally, it should work.

@Gounlaf 2.2.0 that contains the fix has been released.

@zaki50 thanks :) (I was able to build snapshot myself, but haven't time to test it ...)

@Gounlaf FYI: snapshot deployment issue has been fixed in #3778 and #3782

Was this page helpful?
0 / 5 - 0 ratings