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

cargo-ndk 2.7.0 breaks with_flutter example for Android #419

Closed
AlienKevin opened this issue Apr 25, 2022 · 7 comments
Closed

cargo-ndk 2.7.0 breaks with_flutter example for Android #419

AlienKevin opened this issue Apr 25, 2022 · 7 comments
Labels
bug Something isn't working

Comments

@AlienKevin
Copy link
Contributor

Describe the bug

Summary

cargo-ndk 2.7.0 breaks NDK 22. I attempted to bump NDK to latest version 24. The library -lgcc not found error is still not fixed. I then found a workaround that made the example app compile and run on Android successfully.

cargo-ndk breaks NDK 22

Recently on Mar 22, 2022, the cargo-ndk package bumped its version to 2.7.0. Following the tutorial on setting up Android, I ran cargo install cargo-ndk which installed the latest 2.7.0 version of cargo-ndk. Then, I ran the following command to build for Android:

cargo ndk -o ../android/app/src/main/jniLibs build

cargo-ndk threw an error:

[2022-04-25T20:21:20Z INFO  cargo_ndk::cli] Using NDK at path: /Users/kevin/Library/Android/sdk
thread 'main' panicked at 'could not resolve NDK version:
Os { code: 2, kind: NotFound, message: "No such file or directory" }', /Users/kevin/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-ndk-2.7.0/src/cli.rs:190:53

I tracked down the error and found that the a new function was added to cargo-ndk which checks for a source.properties file in the ~/Library/Android/sdk folder. For NDK version 22, the file is not present.

Attempt to bump my NDK from 22 to 24

So I bumped my NDK version to NDK (Side by side) 24.0.8215888 using the SDK manager in Android Studio. And I encountered an old bug related to libgcc:

ld: error: unable to find library -lgcc

The PR to rust-lang/rust referenced by cargo-ndk is merged on Jun 4, 2021 but doesn't resolve the error for released Rust toolchains. Instead, it requires a custom std builds. The NDK on CI is still old, and will always result in linking to libgcc in released Rust toolchains.

Workaround for libgcc not found

  1. Find out all the 4 folders containing file libunwind.a
    On PC, it's
C:\Users\Administrator\AppData\Local\Android\Sdk\ndk\23.1.7779620\toolchains\llvm\prebuilt\windows-x86_64\lib64\clang\12.0.8\lib\linux\x86_64\

and three other similar folders.

On macOS Monterey (Apple Silicon), it's

/Users/kevin/Library/Android/sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/darwin-x86_64/lib64/clang/14.0.1/lib/linux/x86_64/

and three other similar folders.

The three other folders end with aarch64, arm, i386 instead of x86_64.

  1. Create 4 text files named libgcc.a in the four folders mentioned above with this contents
INPUT(-lunwind)

Reference: rust-lang/rust#85806 (comment)

Result

After doing the workaround, the example app compiles and runs successfully on my Android phone.

Codegen logs with RUST_LOG=debug env variable

This is not applicable to this issue.

To Reproduce

No response

Expected behavior

No response

Generated binding code

No response

OS

macOS Monterey (Apple Silicon)

Version of flutter_rust_bridge_codegen

No response

Flutter info

No response

Version of clang++

No response

Version of cbindgen

No response

Version of ffigen

No response

Additional context

No response

@AlienKevin AlienKevin added the bug Something isn't working label Apr 25, 2022
@fzyzcjy
Copy link
Owner

fzyzcjy commented Apr 25, 2022

Good issue description! So what do you suggest this library to do? Shall we just document this, or change some of the build script?

/cc @Desdaemon What do you think?

@Desdaemon
Copy link
Contributor

It's unfortunate that in trying to integrate with flutter run, we have picked up so much unintended complexity from the ecosystem. I will update the template repository and the documentation, but I would definitely love to make this process easier in the long run.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Apr 26, 2022

@Desdaemon Totally agree. This library is indeed just a code generator, but it is complex to integrate any Rust code with any Flutter code (even without this bridge).

@AlienKevin
Copy link
Contributor Author

Good issue description! So what do you suggest this library to do? Shall we just document this, or change some of the build script?

/cc @Desdaemon What do you think?

I think we can keep the current set up but change the cargo install cargo-ndk to a version before 2.7.0 and document that it is a breaking change. And add a sidenote on how to use newer NDK versions with the create text file hack. I don't know when Rust will upgrade to NDK > 22 and I think making a custom std build is just not worth it. Wish there's a better way to customize the NDK support on the Rust side.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Apr 26, 2022

@AlienKevin Good idea. Looking forward to your PR

AlienKevin added a commit to AlienKevin/flutter_rust_bridge that referenced this issue Apr 27, 2022
AlienKevin added a commit to AlienKevin/flutter_rust_bridge that referenced this issue Apr 27, 2022
@AlienKevin
Copy link
Contributor Author

Sounds good, made a PR.

fzyzcjy added a commit that referenced this issue Apr 28, 2022
@fzyzcjy fzyzcjy closed this as completed Apr 28, 2022
@github-actions
Copy link
Contributor

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants