BrainiumLLC / cargo-mobile

Rust on mobile made easy!
Apache License 2.0
1.24k stars 52 forks source link

Broken android setup #53

Open alecnotthompson opened 3 years ago

alecnotthompson commented 3 years ago

I seem to have had a bad android studio setup on my computer for years from only occasionally having react native gigs and can't figure out how to fix it.

After some toiling I think I have a working installation but can't run a cargo mobile generated project. It works just fine on desktop and iOS simulator (without legacy build system even!) and am getting the following error:

error: Failed to locate required build tool
    Missing tool `ar`; tried at
    "/Users/me/Library/Android/sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/darwin-x86_64/bin/x86_64-linux-android-ar".

The file is indeed not in the folder it is looking in but I do see some -as files.

Could it be that I have upgraded beyond supported android studio? 😭 I don't know much about the build system or what I'm looking for but I did see this page saying certain things related to standalone toolchains are obsolete when googling things related to the error above.

Any help would be appreciated. I'm excited to finally be digging into a project with this tool!

zeerooth commented 3 years ago

Hello!

It seems like the NDK release 23 removed the AR tool that is required for cargo-mobile to work and I see others struggling with a similar issue.

For now, try reverting your NDK version through Android Studio to some earlier version. I've tested with 22.1.7171670 and it appears to be working.

Screenshot from 2021-12-02 21-51-21

Of course eventually, we should probably add support for NDK>=23 but for now this should be a functional workaround.

lexi-the-cute commented 1 year ago

Hai! The NDK now uses llvm-ar in the same folder

ethankuhrts commented 1 year ago

Hai! The NDK now uses llvm-ar in the same folder

How can i change cargo mobile to target this instead?

Alexdelia commented 1 year ago

Hai! The NDK now uses llvm-ar in the same folder

How can i change cargo mobile to target this instead?

a workaround is to create a symlink to all needed file:

export YOUR_ARCH_TYPE=linux-x86_64

# aarch64-linux-android-ar
ln -s $NDK_HOME/toolchains/llvm/prebuilt/$YOUR_ARCH_TYPE/bin/llvm-ar $NDK_HOME/toolchains/llvm/prebuilt/$YOUR_ARCH_TYPE/bin/aarch64-linux-android-ar

# arm-linux-androideabi-ar
ln -s $NDK_HOME/toolchains/llvm/prebuilt/$YOUR_ARCH_TYPE/bin/llvm-ar $NDK_HOME/toolchains/llvm/prebuilt/$YOUR_ARCH_TYPE/bin/arm-linux-androideabi-ar

# i686-linux-android-ar
ln -s $NDK_HOME/toolchains/llvm/prebuilt/$YOUR_ARCH_TYPE/bin/llvm-ar $NDK_HOME/toolchains/llvm/prebuilt/$YOUR_ARCH_TYPE/bin/i686-linux-android-ar

# x86_64-linux-android-ar
ln -s $NDK_HOME/toolchains/llvm/prebuilt/$YOUR_ARCH_TYPE/bin/llvm-ar $NDK_HOME/toolchains/llvm/prebuilt/$YOUR_ARCH_TYPE/bin/x86_64-linux-android-ar

_(the folder YOUR_ARCH_TYPE is most probably the only folder in $NDK_HOME/toolchains/llvm/prebuilt/, you just need to look up its name)_