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

Android UnsatisfiedLinkError in release builds with R8 #172

Open
komar-tgm opened this issue Sep 6, 2024 · 6 comments
Open

Android UnsatisfiedLinkError in release builds with R8 #172

komar-tgm opened this issue Sep 6, 2024 · 6 comments

Comments

@komar-tgm
Copy link

When I use the Cast API in a release build that uses R8, I get this exception:

java.lang.UnsatisfiedLinkError: JNI_ERR returned from JNI_OnLoad in "/data/app/~~64wYiOChoMGh9JTT1t63Ag==/at.alysis.nofuss-IM--hyxOpz9yLfhKeMp5MA==/lib/arm64/libQt6Core_arm64-v8a.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:1082)
at java.lang.Runtime.loadLibrary0(Runtime.java:1003)
at java.lang.System.loadLibrary(System.java:1661)
at me.clarius.sdk.Cast.(SourceFile:3)
at at.alysis.nofuss.service.clarius.CastService.onCreate(Unknown Source:28)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:5098)
at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2506)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:230)
at android.os.Looper.loop(Looper.java:319)
at android.app.ActivityThread.main(ActivityThread.java:8919)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)

In the proguard-rules.pro File I added these lines:

-keep class me.clarius.sdk.** { ; }
-keep class at.alysis.nofuss.service.clarius.
* { *; } // package where all the cast api calls are made

I currently use version v.11.1.0. Debug builds work fine.

@julien-l
Copy link
Contributor

julien-l commented Sep 6, 2024

It looks like the native library is missing, make sure to build with the DSL option useLegacyPackaging = true in the Gradle file. If this does not resolve the issue, can you post a minimal example project that reproduces the issue?

@komar-tgm
Copy link
Author

In my build.gradle:

packagingOptions {
        jniLibs {
            // required to load qt plugins because qt cannot find uncompressed shared libs in apk
            useLegacyPackaging = true
        }
}

AndroidManifest.xml:

<activity
            android:name=".MainActivity"
            android:exported="true"
            android:theme="@style/Theme.NOFUSS"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <!-- Make the example app visible to the clarius app
                to improve user workflow when launching marketplace apps -->
                <action android:name="me.clarius.sdk.action.LAUNCH" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

Then I have got a ConnectionScreen, where I connect to the device and this is where it immediately crashes:

lateinit var castBinder: CastBinder
val castConnection = object : ServiceConnection {
        override fun onServiceConnected(p0: ComponentName?, p1: IBinder?) {
            // We've bound to our service, cast the IBinder now
            castBinder = p1 as CastBinder
            Log.i(tag, "onServiceConnected")

            // check if there is already a connection
            if (castBinder.cast.isConnected) {
                Log.i(tag, "Cast is connected")
            } else {
                viewModel.viewModelScope.launch {
                    Log.i(tag, "Cast is NOT connected")
                    viewModel.getLatestUsedConnectionData()
                    if (isButtonEnabled()) {
                        Log.i(tag, "Connection Data is fully entered. Try to connect to probe now.")
                        connectToProbe()
                    }
                }
            }
        }

        override fun onServiceDisconnected(p0: ComponentName?) {
            Log.i(tag, "onServiceDisconnected")
        }
    }

LaunchedEffect(key1 = true, block = {
        Log.i(tag, "Starting foreground service.")
        val serviceIntent = Intent(context, CastService::class.java)
        context.bindService(serviceIntent, castConnection, Context.BIND_AUTO_CREATE)
    })

The CastService.java Class is taken from the Demo App.

@komar-tgm
Copy link
Author

The Clarius Cast Example Project also crashes when enabling the minifier in the build.gradle app. I used the same API version.

buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.debug
        }
    }

@julien-l
Copy link
Contributor

I was able to reproduce but I do not have a fix for minifyEnabled true sorry.

@komar-tgm
Copy link
Author

Will there be a fix anytime soon for this problem ?

@julien-l
Copy link
Contributor

It is not planned for now sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants