conan
conan copied to clipboard
[bug] Android cross compilation not working. Targets not getting linked
Environment details
- Operating System+version: Fedora 40 / Android 24
- Compiler+version: clang 17
- Conan version: 2.0.14
- Python version: Python 3.12.0
Steps to reproduce
I was mostly following https://docs.conan.io/2/examples/cross_build/android/android_studio.html#examples-cross-build-android-studio except for some fixes i had to do for Conan2:
- Use
build=missing - Use
--output-folderto put the files in the right place - Only build release packages
My Android profile
include(default)
[settings]
os=Android
os.api_level=24
compiler=clang
compiler.version=17
compiler.libcxx=c++_static
compiler.cppstd=17
[conf]
tools.android:ndk_path=/home/stephan/Android/Sdk/ndk/25.1.8937393
My build.gradle (relevant portions)
task conanInstall {
def conanExecutable = "conan" // define the path to your conan installation
def buildDir = new File("app/build")
buildDir.mkdirs()
// Don't build the debug configurations
["Release"].each { String build_type ->
["armv7", "armv8", "x86", "x86_64"].each { String arch ->
def cmd = conanExecutable + " install " +
"../../../../../../ --profile android -s build_type="+ build_type +" -s arch=" + arch +
" --build=missing --output-folder=conan-"+ arch +" -c tools.cmake.cmake_layout:build_folder_vars=['settings.arch']"
print(">> ${cmd} \n")
def sout = new StringBuilder(), serr = new StringBuilder()
def proc = cmd.execute(null, buildDir)
proc.consumeProcessOutput(sout, serr)
proc.waitFor()
println "$sout $serr"
if (proc.exitValue() != 0) {
throw new Exception("out> $sout err> $serr" + "\nCommand: ${cmd}")
}
}
}
}
android {
compileSdkVersion 33
ndkVersion '25.1.8937393'
buildFeatures {
prefab true
}
defaultConfig {
minSdkVersion 24
targetSdkVersion 33
versionCode 258
versionName "6.8.7"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments "-DMES_MOBILE_BUILD=TRUE", "-DANDROID_STL=c++_shared", "-DCMAKE_TOOLCHAIN_FILE=./Applications/pocket/client/droid/app/conan_android_toolchain.cmake"
cppFlags "-DMES_MOBILE_BUILD", "-fsigned-char","-fPIC",
"-D_LIBCPP_HAS_NO_OFF_T_FUNCTIONS"
}
}
}
externalNativeBuild {
cmake {
path file('../../../../../CMakeLists.txt')
version "3.22.1"
}
}
namespace 'org.mes'
}
My toolchain:
# During multiple stages of CMake configuration, the toolchain file is processed and command-line
# variables may not be always available. The script exits prematurely if essential variables are absent.
if ( NOT ANDROID_ABI )
message(FATAL_ERROR "Please specify ANDROID_ABI")
return()
endif()
if(${ANDROID_ABI} STREQUAL "x86_64")
message(STATUS "Using x86_64 toolchain")
include("${CMAKE_CURRENT_LIST_DIR}/build/conan-x86_64/conan_toolchain.cmake")
elseif(${ANDROID_ABI} STREQUAL "x86")
message(STATUS "Using x86 toolchain")
include("${CMAKE_CURRENT_LIST_DIR}/build/conan-x86/conan_toolchain.cmake")
elseif(${ANDROID_ABI} STREQUAL "arm64-v8a")
message(STATUS "Using arm64-v8a toolchain")
include("${CMAKE_CURRENT_LIST_DIR}/build/conan-armv8/conan_toolchain.cmake")
elseif(${ANDROID_ABI} STREQUAL "armeabi-v7a")
message(STATUS "Using armeabi-v7a toolchain")
include("${CMAKE_CURRENT_LIST_DIR}/build/conan-armv7/conan_toolchain.cmake")
else()
message(FATAL "Not supported configuration")
endif()
Logs
No response
I created a Conan plugin for gradle that is exactly doing that. If you're still interested, I can share the code with you.