Realm-java: android-apt plugin is incompatible with the Android Gradle plugin. Please use 'annotationProcessor' configuration instead.

Created on 1 Aug 2018  路  6Comments  路  Source: realm/realm-java

Goal

Build my android app with 'io.realm:realm-gradle-plugin:0.88.2' and android studio 3.1

Expected Results

Successful build with 'io.realm:realm-gradle-plugin:0.88.2' with android studio 3.1

Actual Results

android-apt plugin is incompatible with the Android Gradle plugin. Please use 'annotationProcessor' configuration instead.

Steps & Code to Reproduce

Version of Realm and tooling

Realm version(s): 0.88.2

Realm sync feature enabled: yes/no

Android Studio version: 3.1

Which Android version and device: Samsung Galaxy 7.x

Notes:

I can not upgrade to a newer version of realm-java. I need to do a successful build with 0.88.2. Can you please help me resolve above issue?

O-Community

Most helpful comment

@Zhuinden Thank you so much for response.

Gradle Sync finishes successfully.

I added in top level build.gradle

    ext.realm_version = '0.88.2'
    classpath "io.realm:realm-transformer:$realm_version"

I added in app level build.gradle

import io.realm.transformer.RealmTransformer
android.registerTransform(new RealmTransformer())

dependencies {
    implementation "io.realm:realm-annotations:$realm_version"
    implementation "io.realm:realm-android-library:$realm_version"
    annotationProcessor "io.realm:realm-annotations-processor:$realm_version"
}

All 6 comments

Hm, why not 0.88.3? That's more stable than 0.88.2.

Anyways, you can try

 buildscript {
    ext.realm_version = '0.88.3'

    repositories {
        jcenter()
        mavenCentral()
    }

   dependencies {
       classpath "io.realm:realm-transformer:$realm_version"
   }
 }

 apply plugin: 'com.android.application'

 import io.realm.transformer.RealmTransformer
 android.registerTransform(new RealmTransformer(project))

 dependencies {
   implementation "io.realm:realm-annotations:$realm_version"
   implementation "io.realm:realm-android-library:$realm_version"
   annotationProcessor "io.realm:realm-annotations-processor:$realm_version"
 }

I cannot guarantee that it works though

Please pardon my ignorance. I get following error.

I see this if I add it to my build.gradle (I tried both top level and app level)

Could not find matching constructor for: 
io.realm.transformer.RealmTransformer(org.gradle.api.internal.project.DefaultProject_Decorated)

Where do I need to add following two lines:

import io.realm.transformer.RealmTransformer
android.registerTransform(new RealmTransformer(project))

Is there any workaround like using aar/jar/so files directly. I have a previous build cached. Can I use that somehow?

  • I mean can I manually add all the dependencies from a build of android studio 1.x?

You definitely need a version of Android Studio below 3.1. I believe annotationProcessor replaced apt in 2.2 or something, so you need an earlier version than that. The transformer code should be added in your app module build.gradle. You can see it here: https://realm.io/docs/java/latest/#how-do-i-customize-dependecies-defined-by-the-realm-gradle-plugin

You can reference Jars directly, but it is a bit convoluted and I don't have a guide at hand, so you will have to research it yourself. It is possible though as I made it work a year or so ago.

@Zhuinden Thank you so much for response.

Gradle Sync finishes successfully.

I added in top level build.gradle

    ext.realm_version = '0.88.2'
    classpath "io.realm:realm-transformer:$realm_version"

I added in app level build.gradle

import io.realm.transformer.RealmTransformer
android.registerTransform(new RealmTransformer())

dependencies {
    implementation "io.realm:realm-annotations:$realm_version"
    implementation "io.realm:realm-android-library:$realm_version"
    annotationProcessor "io.realm:realm-annotations-processor:$realm_version"
}
Was this page helpful?
0 / 5 - 0 ratings