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

ffi: compress only ARM and x86_64 libraries when building the AAR #708

Merged
merged 1 commit into from
Jan 6, 2025

Conversation

yukibtc
Copy link
Member

@yukibtc yukibtc commented Jan 5, 2025

The UPX compression is known to cause issues on x86 devices for certain Android API levels (e.g., API 30). Since x86 devices constitute a very small percentage of the Android market (<1%, see links below), apps are unlikely to be shipped for this architecture and are typically used only for testing purposes. Therefore, compress only the ARM (arm64-v8a and armeabi-v7a) and x86_64 libraries.

Closes #703

@dluvian
Copy link
Contributor

dluvian commented Jan 5, 2025

Your example code:
x86_64 + API 35 => ✅
x86_64 + API 30 => ✅
x86 + API 30 => ❌
x86 + API 26 => ❌

Error in both cases is:

FATAL EXCEPTION: main
Process: com.example.myapplication2, PID: 3129
rust.nostr.sdk.NostrSdkException$Generic: Out of memory (os error 12)
	at rust.nostr.sdk.FfiConverterTypeNostrSdkError.read(nostr_sdk.kt:40398)
	at rust.nostr.sdk.FfiConverterTypeNostrSdkError.read(nostr_sdk.kt:40394)
	at rust.nostr.sdk.FfiConverter$DefaultImpls.liftFromRustBuffer(nostr_sdk.kt:195)
	at rust.nostr.sdk.FfiConverterRustBuffer$DefaultImpls.liftFromRustBuffer(nostr_sdk.kt:207)
	at rust.nostr.sdk.FfiConverterTypeNostrSdkError.liftFromRustBuffer(nostr_sdk.kt:40394)
	at rust.nostr.sdk.FfiConverterTypeNostrSdkError.liftFromRustBuffer(nostr_sdk.kt:40394)
	at rust.nostr.sdk.FfiConverterRustBuffer$DefaultImpls.lift(nostr_sdk.kt:208)
	at rust.nostr.sdk.FfiConverterTypeNostrSdkError.lift(nostr_sdk.kt:40394)
	at rust.nostr.sdk.FfiConverterTypeNostrSdkError.lift(nostr_sdk.kt:40394)
	at rust.nostr.sdk.NostrSdkException$ErrorHandler.lift(nostr_sdk.kt:40390)
	at rust.nostr.sdk.NostrSdkException$ErrorHandler.lift(nostr_sdk.kt:40389)
	at rust.nostr.sdk.Nostr_sdkKt.uniffiCheckCallStatus(nostr_sdk.kt:271)
	at rust.nostr.sdk.Nostr_sdkKt.access$uniffiCheckCallStatus(nostr_sdk.kt:1)
	at rust.nostr.sdk.NostrDatabase$Companion.lmdb(nostr_sdk.kt:47588)
	at com.example.myapplication2.MainActivityKt$Greeting$getLocationOnClick$1$1.invokeSuspend(MainActivity.kt:61)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
	at androidx.compose.ui.platform.AndroidUiDispatcher.performTrampolineDispatch(AndroidUiDispatcher.android.kt:81)
	at androidx.compose.ui.platform.AndroidUiDispatcher.access$performTrampolineDispatch(AndroidUiDispatcher.android.kt:41)
	at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.run(AndroidUiDispatcher.android.kt:57)
	at android.os.Handler.handleCallback(Handler.java:938)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:223)
	at android.app.ActivityThread.main(ActivityThread.java:7656)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.ui.platform.MotionDurationScaleImpl@c447515, androidx.compose.runtime.BroadcastFrameClock@810702a, StandaloneCoroutine{Cancelling}@ba8be1b, AndroidUiDispatcher@4a75bb8]

@dluvian
Copy link
Contributor

dluvian commented Jan 5, 2025

No error when I remove the database lines

@yukibtc
Copy link
Member Author

yukibtc commented Jan 5, 2025

No error when I remove the database lines

Yeah, that error is related to LMDB. Probably due to the sync of 1000 events. I'm not practical with android emulators but maybe the x86 emulator have few RAM.

Just for curiosity, if you want to try, changing the sync filter and asking for only 10 events, does return the same error?

@dluvian
Copy link
Contributor

dluvian commented Jan 5, 2025

Just for curiosity, if you want to try, changing the sync filter and asking for only 10 events, does return the same error?

It returns the same error. It actually crashes way before the sync filter, when calling val database = NostrDatabase.lmdb(lmdbPath)

@yukibtc
Copy link
Member Author

yukibtc commented Jan 6, 2025

It returns the same error. It actually crashes way before the sync filter, when calling val database = NostrDatabase.lmdb(lmdbPath)

Ok thank you! So I'll merge this and open another issue for LMDB on x86 devices.

The UPX compression is known to cause issues on `x86` devices for certain Android API levels (e.g., API 30). Since `x86` devices constitute a very small percentage of the Android market (<1%, see links below), apps are unlikely to be shipped for this architecture and are typically used only for testing purposes. Therefore, compress only the ARM (`arm64-v8a` and `armeabi-v7a`) and `x86_64` libraries.

* https://android.stackexchange.com/questions/186334/what-percentage-of-android-devices-runs-on-x86-architecture
* https://web.archive.org/web/20170808222202/http://hwstats.unity3d.com:80/mobile/cpu-android.html

Closes #703
Closes #708

Tested-by: dluvian <[email protected]>
Signed-off-by: Yuki Kishimoto <[email protected]>
@yukibtc yukibtc closed this in 4c2b3db Jan 6, 2025
@yukibtc yukibtc merged commit 4c2b3db into master Jan 6, 2025
8 checks passed
@yukibtc yukibtc deleted the build-aar branch January 6, 2025 09:16
yukibtc added a commit that referenced this pull request Jan 6, 2025
The UPX compression is known to cause issues on `x86` devices for certain Android API levels (e.g., API 30). Since `x86` devices constitute a very small percentage of the Android market (<1%, see links below), apps are unlikely to be shipped for this architecture and are typically used only for testing purposes. Therefore, compress only the ARM (`arm64-v8a` and `armeabi-v7a`) and `x86_64` libraries.

* https://android.stackexchange.com/questions/186334/what-percentage-of-android-devices-runs-on-x86-architecture
* https://web.archive.org/web/20170808222202/http://hwstats.unity3d.com:80/mobile/cpu-android.html

Closes #703
Closes #708

Tested-by: dluvian <[email protected]>
Signed-off-by: Yuki Kishimoto <[email protected]>
(cherry picked from commit 4c2b3db)
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

Successfully merging this pull request may close these issues.

Can't migrate to nostr-sdk:0.38.0 Kotlin
2 participants