RealmTransformer not executing on with AGP 7.2.0/1
How frequently does the bug occur?
All the time
Description
Android Studio just updated their stable IDE version. I'm using the recommended Gradle tooling version that came with the IDE update. The app compiles normally, but crashes at runtime - and according to the error it seems fairly clear that the Realm plugin didn't work as expected. Let me know if you need further information.
Stacktrace & log output
java.lang.ExceptionInInitializerError: RealmTransformer doesn't seem to be applied. Please update the project configuration to use the Realm Gradle plugin. See https://docs.mongodb.com/realm/sdk/android/install/#customize-dependecies-defined-by-the-realm-gradle-plugin
at io.realm.RealmConfiguration.<clinit>(RealmConfiguration.java:80)
at io.realm.RealmConfiguration.access$000(RealmConfiguration.java:68)
at io.realm.RealmConfiguration$Builder.initializeBuilder(RealmConfiguration.java:552)
at io.realm.RealmConfiguration$Builder.<init>(RealmConfiguration.java:538)
at io.realm.Realm.initializeRealm(Realm.java:320)
at io.realm.Realm.init(Realm.java:261)
at com.patreon.android.data.manager.RealmManager.initialize(RealmManager.java:55)
### Can you reproduce the bug?
Yes, always
### Reproduction Steps
_No response_
### Version
10.10.1
### What SDK flavour are you using?
Local Database only
### Are you using encryption?
No, not using encryption
### Platform OS and version(s)
all
### Build environment
Android Studio version: Android Studio Chipmunk | 2021.2.1
Build #AI-212.5712.43.2112.8512546, built on April 28, 2022
Gradle : gradle-7.3.3-all
Realm: 10.10.1
I get same results when I update AGP from 7.1.3 to 7.2.0. I'm sticking with 7.1.3 until this gets fixed
I tried to reproduce this with our IntroExample, Chipmunk and AGP 7.2.0 and it seemed to work fine.
Can you provide more information about your project setup? If you can reproduce in a sample project it would be even better.
Also, have you tried a clean build to see if that fixes the issue?
@cmelchior The same result. After upadtaing to the Chipmunk and AGP 7.2.0 - all works as expected.
@VicMikhailau Not 100% sure if you mean it worked after upgrading or it failed with the same error that @pedronveloso is reporting?
@cmelchior It worked after upgrading without any issues.
Clean build also has the same result. It compiles just fine, but crashes at runtime. I'll try Realm's sample for comparison.
Got the same problem, I've also tried a clean build without any success
Got the same issue. I've tried clean build and Invalidate Caches too but the apk is crashing.
Also, got crashes at runtime. Maybe it's related to this breaking change in AGP 7.2: https://developer.android.com/studio/releases/gradle-plugin-api-updates#instrumentatin-apis-deprecated because AGP produces such a warning message and points out to Realm plugin:
AGPBI: {"kind":"warning","text":"API 'android.registerTransform' is obsolete.\nIt will be removed in version 8.0 of the Android Gradle plugin.\nThe Transform API is removed to improve build performance. Projects that use the\nTransform API force the Android Gradle plugin to use a less optimized flow for the\nbuild that can result in large regressions in build times. It’s also difficult to\nuse the Transform API and combine it with other Gradle features; the replacement\nAPIs aim to make it easier to extend the build without introducing performance or\ncorrectness issues.\n\nThere is no single replacement for the Transform API—there are new, targeted\nAPIs for each use case. All the replacement APIs are in the\nandroidComponents {} block.\nFor more information, see https://developer.android.com/studio/releases/gradle-plugin-api-updates#transform-api.\nTo determine what is calling android.registerTransform, use -Pandroid.debug.obsoleteApi=true on the command line to display more information.","sources":[{}]}
Hi @VadimWelldone The API's should only be removed in AGP 8.0, not 7.2. So something else must be causing it.
For anyone else seeing this. Some more details on exactly you project structure looks like would be appreciated. I have tested with AGP 7.2.0 and Gradle 7.3.3 where it did work on a simple project. So maybe it is a specific project structure triggering this, or certain grade properties being set.
@cmelchior I wasn't able to get studio to properly initialize the demos from the repo. Looking at the Realm docs, the main different I see in my current setup is that I'm using the "Gradle Legacy Syntax" as opposed to the newer "Gradle Plugin Syntax". Not sure if this could be the root cause, but its the first thing that stood out to me.
@cmelchior I wasn't able to get studio to properly initialize the demos from the repo. Looking at the Realm docs, the main different I see in my current setup is that I'm using the "Gradle Legacy Syntax" as opposed to the newer "Gradle Plugin Syntax". Not sure if this could be the root cause, but its the first thing that stood out to me.
I just tried to change my project gradle setup to the newer gradle plugin sintax and I get the same issue. Still crashes at runtime
Same problem here, my debug build works though not using proguard/minify so could it be something in the code optimisation step which brakes the build? Using Dagger only...
Butterknife And Realm both got errors
Same problem here. In our case, it works in a branch without Hilt and the one with Dagger Hilt crashes. Going to 7.1.3 works.
I get same results when I update AGP from 7.1.3 to 7.2.0. I'm sticking with 7.1.3 until this gets fixed
going back to 7.1.3 worked for me as well.
Same problem here. In our case, it works in a branch without Hilt and the one with Dagger Hilt crash
@clementetb - if it helps, I am using hilt in my project..
I got the same error stack trace with gradle plugin 7.2.0. Also using Hilt.
The same error here. Back to 7.1.3 works fine.
Hi everyone. We still have issues reproducing this. We have a suspicion it might be related to Hilt, but so far we haven't been able to reproduce it. So if anyone have a sample project where this can be reproduced it would be highly appreciated.
I have the same problem (not working in 7.2, working in 7.1.3 I'm not using HILT and, looking at the dependency tree, no library is using it either
Hi @vernazza Thank you for the information 👍
@cmelchior I'm not using hilt either.
@cmelchior
I too get crashes at runtime on Gradle version 7.2.0. There are no problems on 7.1.3. The errors are also strange. It almost seems that the proxy objects are null when access. Although the objects are filled when looking at them with the debugger. Writing to the DB doesn't seem to be a problem. My project also doesn't use hilt but dagger. I could not reproduce it on the fly with a fresh project. I don't know where the differences are. In the new project I used the same Realm and Dagger version. The only difference, the new project was in Kotlin and the other one in Java.
I can confirm I started having this issue after installing hilt and adding @HiltAndroidApp to my application class. Unfortunately I cannot share my project as the code is not open sourced.
I created a sample project using the latest Realm-Java with Dagger and AGP 7.2 https://github.com/nhachicha/realm_java_7685 (and it's working) could you please use it as a baseline to reproduce the issue so we can investigate cc @GriffinJBC @bobekos @ewnu @vernazza @pedronveloso
I am using Hilt+Realm in my android project and i am facing this issue as well after upgrading to 7.2.0 after downgrading to 7.1.3 as suggested by the users worked, but it's not a permanent solution.
@nhachicha No chance i can't reproduce it. That's super weird. In my project I can't really understand it either. I know why it crashes. It is simply a null pointer to a RealmObject which is 100% filled. The funny thing is, if I copy the exact same code (to fetch a realm object) somewhere else (into an existing class) then it works. If I create a new class that is identical, it doesn't work. The realm objects and the proxies are identical in both. But in one I can read the attributes in the other there are null. I can't even tell you what the reason is. Already deleted all cashes and cleaned up the project.
@nhachicha Ok I could at least tell where the difference is. I use a multi module project. I had to move the class from the app module to my "core" module. In the "core" module the realm configuration is provided via dagger. And the class that i moved is injecting this realm over the constructor. I tried to do the same setup in the test project. Until now without success.
So I'm also getting this error but I know exactly why it's happening: For me, it's because I introduced DaggerHilt which also uses an android gradle plugin. So I think that the Dagger Hilt plugin and Realm plugin are incompatible. So there may be some incompatible plugins within some applications...
Note: I created a new project with Realm + Dagger Hilt and confirmed this is the case. These are my configurations:
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:10.11.0"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.42'
}
}
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
id "org.jetbrains.kotlin.kapt" version "1.6.21" apply false
}
build.gradle(app)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.kapt'
}
apply plugin: 'dagger.hilt.android.plugin'
apply plugin: "realm-android"
Gradle: Gradle : gradle-7.3.3-all
Edit: Setting id 'com.android.application' version '7.2.1' apply false in the plugins to 7.1.3 worked as described by @ahmedsiddique-cb
Apologies I didn't see your comment when I initially created the post.