conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.27k stars 981 forks source link

[question] Setting android api level in conan 2? #14249

Open wbehrens-on-gh opened 1 year ago

wbehrens-on-gh commented 1 year ago

What is your question?

I have the following profile when trying to cross compile using ndk r19

{% set api_level = '21' %}
{% set target_host = 'aarch64-linux-android' %}
{% set android_ndk = os.getenv("ANDROID_NDK") %}

[settings]
os=Android
os.api_level={{api_level}}
arch=armv8
compiler=clang
compiler.libcxx=c++_shared
compiler.version=8
build_type=Release

[conf]
tools.android:ndk_path={{android_ndk}}
tools.cmake.cmaketoolchain:generator=Ninja

[buildenv]
PATH=[{{android_ndk}}/toolchains/llvm/prebuilt/linux-x86_64/bin]
CHOST={{target_host}}
ANDROID_STL=c++_shared
AR={{target_host}}-ar
AS={{target_host}}-as
LD={{target_host}}-ld
STRIP={{target_host}}-strip
RANLIB={{target_host}}-ranlib
CC={{target_host}}{{api_level}}-clang
CXX={{target_host}}{{api_level}}-clang++

CONAN_MAKE_PROGRAM={{android_ndk}}/prebuilt/linux-x86_64/bin/make
CONAN_CMAKE_TOOLCHAIN_FILE={{android_ndk}}/custom/custom.android.toolchain.armv8.api21.cmake

when I try and do conan create I'm hit with ERROR: Error reading 'clang8-android-armv8' profile: Error while parsing line 2: 'api_level=21'

has the way you set android api level changed in conan 2? I didn't notice a change in the docs.

Have you read the CONTRIBUTING guide?

memsharded commented 1 year ago

Hi @wbehrens-on-gh

I am not sure what is failing on your side, it seems to be working fine here. Maybe you can try to reduce a bit the files? Something like:

Also, please make sure you are in latest Conan 2.0.7, are you?

wbehrens-on-gh commented 1 year ago

I'm using conan 2.0.7, when I run it on my local machine it works fine strangely, the error I'm getting is when running in a jenkins pipeline? what I'm running in the jenkins pipeline though is the exact same as what I tested locally.

wbehrens-on-gh commented 1 year ago

after testing inside the same docker container used by the pipeline I get the following image I guess jenkins didn't show the full error

memsharded commented 1 year ago

It seems the settings.yml in the jenkins is different to your local one. Maybe it is being reused from conan config install or something like that? The Conan 2.0 settings.yml has changed, now it is more standard yaml, so null instead of the previous string None that was converted internally.

I suspect that your jenkins might have sdk: ANY instead of 2.0 sdk: [ANY]

wbehrens-on-gh commented 1 year ago

Ignore the above error screenshot because I did messed up and installed the config I had to v1. Retrying with the correct configuration inside the container and it worked fine. I then uploaded that container image and ran the jenkins pipeline inside it getting the same error.

there isn't a settings.yml in my conan config install config (for v2), it uses settings_user.yml. The settings.yml should be the one created by default when installing conan v2 since this is installed inside a fresh container.

memsharded commented 1 year ago

There must be something different in your CI pipeline...

Next thing I'd try is to check the Python dependencies, maybe? What version of Jinja2 you have locally and which one are you running in the CI server? It seems that for some reason, the jinja rendering is leaving {% set api_level = '21' %} there and writing api_level=21 in that line, which doesn't make sense...

wbehrens-on-gh commented 1 year ago

correct me if I'm wrong @memsharded, but in conan 2 profiles no longer need the .jinja extension to be ran through the template engine? so if the profile name is android_armv7 it'll still get templated?

memsharded commented 1 year ago

Yes, Conan 2 renders all profiles via jinja, the file extension .jinjs is no longer necessary. Yes, the android_armv7 filename for profile will still be templated.

I was thinking of some difference in the jinja library in the server, that resulted in some kind of different final output of the render.

wbehrens-on-gh commented 1 year ago

Well, I'm not sure why but adding the .jinja extension seemed to fix it, I'm running into some other issues that I'm not sure if they're related or not.

memsharded commented 1 year ago

That is super weird, that would only make sense if it runs Conan 1.X. I have just double checked the work, there is no check at all for the jinja extension, it is not conditional anymore. Can you please provide a full output of the command, until it fails?