UnsatisfiedLinkError when trying to create RealmConfig
DmytroTols opened this issue · comments
How frequently does the bug occur?
Sometimes
Description
I'm trying to initialize realm config when app starts with and then call Realm.open(realmConfig!!) when i will need it, but on call init:
fun init(context: Context) {
realmConfig = RealmConfiguration.Builder(
schema = setOf(
TransactionEntity::class,
// more classes
TaxEntity::class
)
)
.name(DATABASE_NAME)
.schemaVersion(DATABASE_VERSION)
.encryptionKey(getOrCreateEncKey(context))
.migration(Migration())
.build()
}
I get error, i tried adding provider to manifest to remove RealmInitializer and call it manually:
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge">
<meta-data android:name="io.realm.kotlin.internal.RealmInitializer"
tools:node="remove" />
</provider>
and call
val appInitializer = AppInitializer.getInstance(this)
appInitializer.initializeComponent(RealmInitializer::class.java)
this helped a little (crashed stopped occurring as much, but the still appear most of the time), If i just restart the app after crash it works just fine. So looks like issue appears mostly after first initialize of Realm. I migrated from realm java sdk to kotlin sdk
Stacktrace & log output
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to get provider androidx.startup.InitializationProvider: androidx.startup.StartupException: java.lang.UnsatisfiedLinkError: No implementation found for void io.realm.kotlin.internal.interop.realmcJNI.set_log_callback(java.lang.Object) (tried Java_io_realm_kotlin_internal_interop_realmcJNI_set_1log_1callback and Java_io_realm_kotlin_internal_interop_realmcJNI_set_1log_1callback__Ljava_lang_Object_2)
at android.app.ActivityThread.installProvider(ActivityThread.java:7213)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6700)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6613)
at android.app.ActivityThread.access$1300(ActivityThread.java:234)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1882)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:503)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: androidx.startup.StartupException: java.lang.UnsatisfiedLinkError: No implementation found for void io.realm.kotlin.internal.interop.realmcJNI.set_log_callback(java.lang.Object) (tried Java_io_realm_kotlin_internal_interop_realmcJNI_set_1log_1callback and Java_io_realm_kotlin_internal_interop_realmcJNI_set_1log_1callback__Ljava_lang_Object_2)
at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:187)
at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:238)
at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:206)
at androidx.startup.InitializationProvider.onCreate(InitializationProvider.java:45)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2092)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2066)
at android.app.ActivityThread.installProvider(ActivityThread.java:7208)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6700)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6613)
at android.app.ActivityThread.access$1300(ActivityThread.java:234)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1882)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:503)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.UnsatisfiedLinkError: No implementation found for void io.realm.kotlin.internal.interop.realmcJNI.set_log_callback(java.lang.Object) (tried Java_io_realm_kotlin_internal_interop_realmcJNI_set_1log_1callback and Java_io_realm_kotlin_internal_interop_realmcJNI_set_1log_1callback__Ljava_lang_Object_2)
at io.realm.kotlin.internal.interop.realmcJNI.set_log_callback(Native Method)
at io.realm.kotlin.internal.interop.realmc.set_log_callback(realmc.java:1838)
at io.realm.kotlin.internal.interop.RealmInterop.realm_set_log_callback(RealmInterop.kt:1291)
at io.realm.kotlin.log.RealmLog.<clinit>(RealmLog.kt:49)
at io.realm.kotlin.Configuration$SharedBuilder.<init>(Configuration.kt:229)
at io.realm.kotlin.RealmConfiguration$Builder.<init>(RealmConfiguration.kt:53)
at gr.edps.pax.mastersdk.database.Database.init(Database.kt:50)
at gr.edps.pax.mastersdk.internal.initializer.RealmInitializer.create(RealmInitializer.kt:21)
at gr.edps.pax.mastersdk.internal.initializer.RealmInitializer.create(RealmInitializer.kt:10)
at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:180)
at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:238)
at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:206)
at androidx.startup.InitializationProvider.onCreate(InitializationProvider.java:45)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2092)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2066)
at android.app.ActivityThread.installProvider(ActivityThread.java:7208)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6700)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6613)
at android.app.ActivityThread.access$1300(ActivityThread.java:234)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1882)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:503)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Can you reproduce the bug?
Sometimes
Reproduction Steps
Issue occurs on start of the app
Version
1.15.0
What Atlas App Services are you using?
Local Database only
Are you using encryption?
Yes
Platform OS and version(s)
Android 10
Build environment
Android Studio version: Iguana | 2023.2.1 Patch 2
Android Build Tools version: Android SDK Build-Tools 35-rc3
Gradle version: 7.5
➤ PM Bot commented:
Jira ticket: RKOTLIN-1074
It is similar to this other report.
Can you reproduce the issue locally? Do you use any custom provider? Would you mind sharing a project that reproduces the issue?
Where are you calling this code?
val appInitializer = AppInitializer.getInstance(this)
appInitializer.initializeComponent(RealmInitializer::class.java)
Are you removing the Initializer provider and using this code?
Where are you calling this code?
val appInitializer = AppInitializer.getInstance(this) appInitializer.initializeComponent(RealmInitializer::class.java)Are you removing the Initializer provider and using this code?
Yes, I'm removing initializer in manifest and call this code in my class MainClass that inheritance from Application:
class MainApplication : Application() {
private val log: Logger = LoggerFactory.getLogger(MainApplication::class.java)
override fun onCreate() {
super.onCreate()
LogContext.init()
startKoin {
androidContext(this@MainApplication)
}
startFirebase()
startStoreSdk()
val appInitializer = AppInitializer.getInstance(this)
appInitializer.initializeComponent(RealmInitializer::class.java)
}
It is similar to this other report.
Can you reproduce the issue locally? Do you use any custom provider? Would you mind sharing a project that reproduces the issue?
Yes, it is similar to this issue, but the solutions that worked for this issue didn't work for mine , also I'm not using compose multiplatform, im using old approach with kotlin, i will try to re-create this issue in small demo and will link it
I found solutions to my problem, my issue was that i had realm in module, in my module manifest i had
<meta-data
android:name="mastersdk.internal.initializer.RealmInitializer"
android:value="androidx.startup"/>
</provider>
</application>
Sometimes this was called before io.realm.kotlin.internal.RealmInitializer, i fixed it by calling manually
override fun create(context: Context) {
val appInitializer = AppInitializer.getInstance(context)
appInitializer.initializeComponent(RealmInitializer::class.java)
Database.init(context)
Database.getOrCreateRealm()
}