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 example fails to run: UnsatisfiedLinkError #4103

Closed
vi opened this issue Mar 4, 2022 · 11 comments
Closed

Android example fails to run: UnsatisfiedLinkError #4103

vi opened this issue Mar 4, 2022 · 11 comments
Labels
C-Bug An unexpected or incorrect behavior C-Startup A crash that occurs when first attempting to run a Bevy app O-Android Specific to the Android mobile operating system P-Crash A sudden unexpected crash

Comments

@vi
Copy link

vi commented Mar 4, 2022

Bevy version

b6a647c

Operating system & version

Building on Linux x86_64 for Android.

What you did

Followed the https://github.com/bevyengine/bevy/tree/latest/examples#android,
but with cargo apk build --example android, with manual installation of tha apk.

The 215-megabyte "android" application appeared on the device. But upon starting it the window immediately closes.

What you expected to happen

Some Android view with some UI appears

What actually happened

03-04 20:28:08.412  9304  9304 D AndroidRuntime: Shutting down VM
03-04 20:28:08.413  9304  9304 E AndroidRuntime: FATAL EXCEPTION: main
03-04 20:28:08.413  9304  9304 E AndroidRuntime: Process: rust.example.android, PID: 9304
03-04 20:28:08.413  9304  9304 E AndroidRuntime: java.lang.UnsatisfiedLinkError: Unable to load native library "/data/app/~~6E5dAovNIGKNfvRukbcJ_g==/rust.example.android-DAiOvJ6LjHGyMIvo9MQiIw==/lib/arm64/libandroid.so": dlopen failed: cannot locate symbol "__cxa_pure_virtual" referenced by "/data/app/~~6E5dAovNIGKNfvRukbcJ_g==/rust.example.android-DAiOvJ6LjHGyMIvo9MQiIw==/lib/arm64/libandroid.so"...
03-04 20:28:08.413  9304  9304 E AndroidRuntime:        at android.app.NativeActivity.onCreate(NativeActivity.java:178)
03-04 20:28:08.413  9304  9304 E AndroidRuntime:        at android.app.Activity.performCreate(Activity.java:8000)
03-04 20:28:08.413  9304  9304 E AndroidRuntime:        at android.app.Activity.performCreate(Activity.java:7984)
03-04 20:28:08.413  9304  9304 E AndroidRuntime:        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
03-04 20:28:08.413  9304  9304 E AndroidRuntime:        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3404)
03-04 20:28:08.413  9304  9304 E AndroidRuntime:        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595)
03-04 20:28:08.413  9304  9304 E AndroidRuntime:        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
03-04 20:28:08.413  9304  9304 E AndroidRuntime:        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
03-04 20:28:08.413  9304  9304 E AndroidRuntime:        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
03-04 20:28:08.413  9304  9304 E AndroidRuntime:        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
03-04 20:28:08.413  9304  9304 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:106)
03-04 20:28:08.413  9304  9304 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:223)
03-04 20:28:08.413  9304  9304 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:7660)
03-04 20:28:08.413  9304  9304 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
03-04 20:28:08.413  9304  9304 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
03-04 20:28:08.413  9304  9304 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

Additional information

Running on Pixel 3 XL with Android 11.

rustc 1.60.0-nightly (0c292c966 2022-02-08)

@vi vi added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Mar 4, 2022
@vi vi changed the title Android example fails to run Android example fails to run: UnsatisfiedLinkError Mar 4, 2022
@alice-i-cecile alice-i-cecile added O-Android Specific to the Android mobile operating system C-Startup A crash that occurs when first attempting to run a Bevy app P-Crash A sudden unexpected crash and removed S-Needs-Triage This issue needs to be labelled labels Mar 4, 2022
@konradmoesch
Copy link

Hi!
I also ran into this error. Unfortunately, I wasn't able to fix it.

Here is what I found out so far:
The resources (including the app icon) are not correctly included in the apk any more. I think the configuration options for cargo-apk have changed.
By modifying the cargo.toml (ll.520ff.), I was able to fix some issues:

  • apk_label -> apk_name
  • res -> resources
  • maybe unnecessary: crate_type (l.520): i changed from ["cdylib"] to ["lib", "cdylib"] (don't know what this means, but this is how it looks in the example from rust-windowing/android-ndk-rs

I also added a new section [package.metadata.android.application]:

[package.metadata.android.application]
icon = "@mipmap/ic_launcher"
label = "Bevy Example"

I moved the icon option from the previous section and added the label option.

Now, the app appears correctly in the application list. Assets are included again. I checked via adb, the libandroid.so file is also installed with the apk.

Btw. I think #4295 might be related to this issue. At least the second part of the error message is the same.

Maybe there are some other breaking changes from android-ndk-rs / cargo-apk? Or is libandroid.so compiled from Bevy code?
I unfortunately have no more ideas how to fix this issue, thus no PR. Maybe someone else has an idea?

@mockersf
Copy link
Member

mockersf commented Apr 6, 2022

some people have been able to run on android with #4139

@konradmoesch
Copy link

Thanks! Will have a look into it.
But I think the issues from #4139 are different from this one? I don't have any RustStdoutStderr messages in the adb log, so no directly rust / bevy code related error messages.
Maybe because the .so is not loaded correctly?

@bit-garden
Copy link

I was actually just reinstalling my linux machine to test if this(#4295) was happening elsewhere too. I ran into the exact link error Vi ran into.

@konradmoesch the Rust code doesn't seem to be loading at all and it's purely a Java error at the moment. It's not saying the file doesn't exist, but it's saying the symbol doesn't exist.

Between this and #4295 though, it's complaining about different symbols depending on which OS is compiling.

@konradmoesch
Copy link

Hm okay, but the libandroid.so is the compiled rust code, right?
So the missing symbol is caused by some error in the bevy code or the impl of the example? Or is this a compiler related error or an issue in the NDK?

I am new to Bevy and also quite new to rust (started maybe one year ago), sorry. But I'd love to get a bit more into it.

@bit-garden
Copy link

bit-garden commented Apr 6, 2022

I'm in the same boat really, much greener though(a month or so).

From what I can gather, the assumption that it's an upstream issue from cargo-apk makes sense. It's building the .so file, and the device reports only missing symbols. It may also be the toolchain issue as well.

I'm currently using nightly(mainly because the rust-analyzer) so maybe the toolchain messing the builds up?

I'll see if I can get the stable Rust to work. I'm going to also try quadmacro and see if that works and maybe see what is done differently if it does.

@konradmoesch
Copy link

konradmoesch commented Apr 7, 2022

I manually linked libc++_shared.so as described in this answer.
Now, the missing symbol error disappeared and I see the rust logging (I get
rust.example.android I/RustStdoutStderr: thread '<unnamed>' panicked at 'called 'Option::unwrap()' on a 'None' value', [...]\ndk-glue-0.6.1\src\lib.rs:60:39)
Will see if I can find a fix for this issue as well, at least some rust code is running now.

Edit:
After reading #4139 and the commits again, I think its now the same issue (rendering too early).
But I don't understand why its not required to link libc++ in the branch from MannevilleF.

@bit-garden
Copy link

Jinx. I just did the link this morning too. I found that screenshot posted on several Rust projects.

I'm looking into 4139 now. Now that we are getting something Rust launching, the rest should be easy.

@bit-garden
Copy link

This issue should be closed with katyo/oboe-rs#28 (comment) as the solution. Now I'm running into the unwrap error now, though on a different line. Time to chase this down.

@bit-garden
Copy link

But I don't understand why its not required to link libc++ in the branch from MannevilleF.

I can't find this. All the Bevy forks I have found all fail in the same way without the build.rs fix.

@konradmoesch
Copy link

I mean this branch by ManevilleF (pull req #4139)
This branch does not link libc++ manually iirc

bors bot pushed a commit that referenced this issue Feb 6, 2023
# Objective

- Merge the examples on iOS and Android
- Make sure they both work from the same code

## Solution

- don't create window when not in an active state (from #6830)
- exit on suspend on Android (from #6830)
- automatically enable dependency feature of bevy_audio on android so that it works out of the box
- don't inverse y position of touch events
- reuse the same example for both Android and iOS

Fixes #4616
Fixes #4103
Fixes #3648
Fixes #3458
Fixes #3249
Fixes #86
bors bot pushed a commit that referenced this issue Feb 6, 2023
# Objective

- Merge the examples on iOS and Android
- Make sure they both work from the same code

## Solution

- don't create window when not in an active state (from #6830)
- exit on suspend on Android (from #6830)
- automatically enable dependency feature of bevy_audio on android so that it works out of the box
- don't inverse y position of touch events
- reuse the same example for both Android and iOS

Fixes #4616
Fixes #4103
Fixes #3648
Fixes #3458
Fixes #3249
Fixes #86
@bors bors bot closed this as completed in 7e0a9bf Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Bug An unexpected or incorrect behavior C-Startup A crash that occurs when first attempting to run a Bevy app O-Android Specific to the Android mobile operating system P-Crash A sudden unexpected crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants