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 Cmake cross compile build CI instructions don't build #84

Closed
truedat101 opened this issue Dec 16, 2019 · 7 comments
Closed

Android Cmake cross compile build CI instructions don't build #84

truedat101 opened this issue Dec 16, 2019 · 7 comments

Comments

@truedat101
Copy link

I've attempted to follow docs here: https://doc.magnum.graphics/magnum/platforms-android.html

and also here: https://doc.magnum.graphics/corrade/building-corrade.html#building-corrade-cross-android

I've set a variable for ANDROID_NDK_HOME to point to my ndk, and set paths for tools needed like the cmake included in the SDK. In the case of the Android CI instructions, there is a nice description of grabbing the NDKr16b, unzipping it, and a simple cmake command, cmake .. -DCMAKE_ANDROID_NDK=$ANDROID_NDK_HOME -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=22 -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_BUILD_TYPE=Release

That configures nicely. When I build, I get an error right away when compiling Directory.cpp:

Scanning dependencies of target CorradeUtilityObjects
[ 3%] Building CXX object src/Corrade/Utility/CMakeFiles/CorradeUtilityObjects.dir/Debug.cpp.o
[ 6%] Building CXX object src/Corrade/Utility/CMakeFiles/CorradeUtilityObjects.dir/Directory.cpp.o
corrade.git/src/Corrade/Utility/Directory.cpp:50:31: fatal error: android/api-level.h: No such file or directory

The build is unable to find the path to the platform version headers, which are most definitely present in the NDK.

I'm looking for some pointers on what configure step I am missing. I am fairly competent with the NDK, although the integration with cmake has changed a bit over the years and I am no expert. Also, I am surprised that for a project supporting android, there is only one bug filed in this project against android. Any help would be appreciated so I can complete evaluation of this project.

@mosra mosra added this to the 2019.1c milestone Dec 18, 2019
@mosra
Copy link
Owner

mosra commented Dec 18, 2019

Hi!

I am surprised that for a project supporting android, there is only one bug filed in this project against android.

You mean this one, right? mosra/magnum#310 What's your CMake version? I didn't have a chance to test with 3.16 yet, so there's a possibility they broke something while attempting to fix everything else.

The NDK sysroot should be added to the include path by CMake and that's what the code relies on, I'm not doing anything extra to get that include. Can you run with make VERBOSE=1 and post the full command-line so I can see what exactly it does in your case? In my case it looks like this (with the required include path highlighted):

/opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android --gcc-toolchain=/opt/android-ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 --sysroot=/opt/android-ndk/sysroot -I../src -Isrc -isystem /opt/android-ndk/sources/cxx-stl/llvm-libc++/include -isystem /opt/android-ndk/sources/android/support/include -isystem /opt/android-ndk/sources/cxx-stl/llvm-libc++abi/include -isystem /opt/android-ndk/sysroot/usr/include -isystem /opt/android-ndk/sysroot/usr/include/aarch64-linux-android -funwind-tables -no-canonical-prefixes -D__ANDROID_API__=22 -fexceptions -frtti -O3 -DNDEBUG -fPIC -std=c++11 -Wall -Wextra -Wold-style-cast -Winit-self -Werror=return-type -Wmissing-declarations -Wpedantic -fvisibility=hidden -fvisibility-inlines-hidden -Wmissing-prototypes -Wno-shorten-64-to-32 -MD -MT src/Corrade/Utility/CMakeFiles/CorradeUtilityObjects.dir/Directory.cpp.o -MF src/Corrade/Utility/CMakeFiles/CorradeUtilityObjects.dir/Directory.cpp.o.d -o src/Corrade/Utility/CMakeFiles/CorradeUtilityObjects.dir/Directory.cpp.o -c ../src/Corrade/Utility/Directory.cpp

@truedat101
Copy link
Author

Ha, yes, every project I've seen that aims to support multiple platforms always seems to have to dedicate a lot of resources fixing things related the evolution of Android builds, and the people who try to build them. And yes, there's this confusing aspect of Android Studio, in the SDK Manager pane for tools where it lists two different cmakes, one with a version (3.4 old stuff) and a newer one (3.6 or something but it isn't marked). That might be part of the issue, just discovered that looking at a different build I am working on.

As far as the NDK being picked up the by the include path, I see a point on the travis ci page that you have CMAKE_PREFIX_PATH= . Should I point this to the location where my NDK is installed? I am having trouble understanding how it is picking up the NDK from the install path, other than there being an ndk-build in my PATH.

@mosra
Copy link
Owner

mosra commented Dec 20, 2019

Oh, I think I know where this comes from, then (and the 100-page long Android troubleshooting guide doesn't mention it early enough for some reason -- sorry. Going to update that.).

CMake has builtin Android support since 3.7 (but ideally the newer versions, 3.9 and up), if you're using the vintage ones that are bundled with Android Studio, those won't work -- CMake will ignore all the options passed and then die on the missing include. With 3.6 and below it needs to use some toolchain from hell that's bundled inside the NDK and to be frank I never even tried to use that one (instead made my own, and then scrapped it once CMake's builtin support appeared). I also never used Android Studio so I don't know how hard it is to convince it to use system CMake instead of the bundled one -- probably easiest to build it completely outside via the command line?

Hope this helps, and sorry for the pain :)

@truedat101
Copy link
Author

Gah , android tool chain .... Thanks for the response. So I'm clear, should I not use the one bundled in Android stuidio? I hate using studio but customers use it so I have to provide things that work with it. As far as the bundled cmake, It's old for sure, clocked at cmake 3.6.x.? So should I just be using whatever latest and greatest cmake 3.16.x version is available?

@mosra
Copy link
Owner

mosra commented Dec 20, 2019

I can confirm anything between 3.9.2 and 3.15 works, didn't have a chance to test with 3.16 yet but I assume it would work too.

With the bundled 3.6 it should work in some way also but you'd need to figure out what all magic spells Gradle is passing to it to make it work (CMAKE_TOOLCHAIN_FILE at least) and then repeat that while building on the command line. What I'm doing when interfacing with Gradle is building all dependencies using new CMake (3.9+), installing those somewhere, and only using the bundled old cmake when I really need to build the final APK using Gradle.

Alternatively, you could go the CMake Subproject way -- add_subdirectory(corrade) etc. from your final project, and build everything from within Gradle, without doing separate installs. Basically what magnum's Getting Started Guide suggests, only adapted for Android -- that way, if the stars align correctly, Gradle's builtin cmake support might "just work" and build everything in one go. That could be also "customer friendly" enough :)

@truedat101
Copy link
Author

Thanks, I'll try to go though that set up later this week .

@mosra
Copy link
Owner

mosra commented Jun 10, 2020

Things seem to work well again with NDK r19+ and CMake 3.16+ (and a bunch of extra things to help CMake find libraries), see mosra/magnum@8bc1fa1 for updated instructions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

2 participants