My Android project generates native executables as part of the build, and also it should support all devices starting from API 14 (Android 4.0).
As you know, Android 4.0 supports only non-PIE executables, while Android > 5.0 does support only PIE ones.So I should generate both PIE and non-PIE executables, and I can't find any suitable way to achieve that on my current setup (Android Studio 3.0, NDK r16, llvm-5.0).
I was using the following hack for Android Studio 2.3 and NDK r15 in my CMakeLists.txt file:
add_executable(hello
src/main/cpp/main.cpp
)
add_executable(hello-nonpie
src/main/cpp/main.cpp
)
target_compile_definitions(hello
PRIVATE
-DANDROID_PIE=ON
)
target_compile_definitions(hello-nonpie
PRIVATE
-DANDROID_PIE=OFF
)
This hack does not work anymore on AS 3.0 and NDK r16 - it produces non-PIE binaries only as my `minSdkVersion` is set to 14, or PIE binaries only if I explicitly pass `-DANDROID_PIE=ON` argument to CMake.
The only way I found to embed both PIE and non-PIE versions in one build is to create two identical Android library modules. They build same binaries, but one of them passes `-DANDROID_PIE=ON` argument to CMake. Then I include those project as my app dependencies. It does work, but slows down configure & build time more than twice as now I have not one but three projects (app itself and two modules, each of them configuring builds for multiple architectures).
Any thoughts on solving this problem more nicely?