Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnsatisfiedLinkError when trying to create RealmConfig #1735

Closed
DmytroTols opened this issue May 2, 2024 · 6 comments
Closed

UnsatisfiedLinkError when trying to create RealmConfig #1735

DmytroTols opened this issue May 2, 2024 · 6 comments

Comments

@DmytroTols
Copy link

DmytroTols commented May 2, 2024

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

Copy link

sync-by-unito bot commented May 2, 2024

➤ PM Bot commented:

Jira ticket: RKOTLIN-1074

@sync-by-unito sync-by-unito bot added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label May 3, 2024
@clementetb
Copy link
Contributor

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?

@clementetb
Copy link
Contributor

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?

@DmytroTols
Copy link
Author

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)
}

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels May 8, 2024
@DmytroTols
Copy link
Author

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

@DmytroTols
Copy link
Author

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()
}

@sync-by-unito sync-by-unito bot removed the Needs-Attention Reporter has responded. Review comment. label May 8, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants