Repository: conan-io/conan-center-index

Issue:
[package] xmlsec/1.2.30: Android build failed
<!-- 
  Please don't forget to update the issue title.
  Include all applicable information to help us reproduce your problem.
-->

### Package and Environment Details (include every applicable attribute)
  * Package Name/Version: **xmlsec/1.2.30**
  * Operating System+version: **macOS Catalina (Android cross-build)**
  * Compiler+version: **clang 9**
  * Conan version: **conan 1.31.3**
  * Python version: **Python 3.7.4**


### Conan profile (output of `conan profile show default` or `conan profile show <profile>` if custom profile is in use)
```
[settings]
os_build=Macos
arch_build=x86_64

compiler=clang
compiler.version=9
compiler.libcxx=libc++

os=Android
os.api_level=21
arch=armv7
build_type=Release

[build_requires]
android_ndk_installer/r21d@bincrafters/stable
cmake_installer/3.15.5@conan/stable
```


### Steps to reproduce (Include if Applicable)



### Logs (Include/Attach if Applicable)
<details><summary>Click to expand log</summary>

```
ERROR: m4/1.4.18: Error in build() method, line 90
        autotools.make()
        ConanException: Error 2 while executing make -j12


In file included from ../source_subfolder/lib/freading.c:22:
../source_subfolder/lib/stdio-impl.h:72:22: error: field has incomplete type 'struct __sbuf'
      struct  __sbuf _ub; /* ungetc buffer */
                     ^
../source_subfolder/lib/stdio-impl.h:72:15: note: forward declaration of 'struct __sbuf'
      struct  __sbuf _ub; /* ungetc buffer */
              ^
../source_subfolder/lib/freading.c:41:16: error: no member named '_flags' in 'struct __sFILE'
  return (fp_->_flags & __SRD) != 0;
          ~~~  ^
../source_subfolder/lib/freading.c:41:25: error: use of undeclared identifier '__SRD'
  return (fp_->_flags & __SRD) != 0;
                        ^
3 errors generated.
```

</details>



Discussion:
Google says: _stdioext: Fix compilation errors with newer Android headers_ https://lists.gnu.org/archive/html/bug-gnulib/2018-05/msg00103.html
Thanks for the link.

It looks like you're building m4 for Android.
m4 is only used as a build requirement and an arm executable will not rui n on your Intel build system.

I think you must use build and host profiles
See https://docs.conan.io/en/latest/reference/profiles.html#build-profiles-and-host-profiles
Thanks for quick reply! My cross build profile working for other libs very well.
conan.txt

[requires]
cpprestsdk/2.10.16
openssl/1.1.1h
libxml2/2.9.10
libxslt/1.1.33@bincrafters/stable
spdlog/1.8.0
gtest/1.10.0

[generators]
cmake

[options]
cpprestsdk:with_websockets = False
libxml2:docbook = False
libxml2:ftp = False
libxml2:http = False
libxml2:legacy = False
The important thing is to split the profiles, and not use arch_build and os_build
For the last two years all working fine. But i can try. Do you have a working example?
build profile (save as e.g. `build_profile`)
```
[settings]
os=Linux
arch=x86_64
compiler=gcc
compiler.version=9
compiler.libcxx=libstdc++11
build_type=Release
[options]
[build_requires]
```

host profile (save as `android_profile`):
```
[settings]
compiler=clang
compiler.version=9
compiler.libcxx=libc++

os=Android
os.api_level=21
arch=armv7
build_type=Release

[build_requires]
android_ndk_installer/r21d@bincrafters/stable
cmake/3.19.0
```

And build using (untested):
```
`conan create . xmlsec/1.2.30@ -pr:h ./android_profile -pr:b ./build_profile
```
conan install ./conanfile.txt --build missing -pr:h ./profiles/host -pr:b ./profiles/android1
Configuration (profile_host):
[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.libcxx=libc++
compiler.version=9
os=Macos
[options]
[build_requires]
[env]

Configuration (profile_build):
[settings]
arch=armv7
build_type=Release
compiler=clang
compiler.libcxx=libc++
compiler.version=9
os=Android
os.api_level=21
[options]
[build_requires]
*: android_ndk_installer/r21d@bincrafters/stable, cmake/3.19.0
[env]

m4/1.4.18: WARN: Package binary is corrupted, removing: 5e3eda2e5f927dd59617d1d1f021008f1b5ce905
ERROR: android_ndk_installer/r21d@bincrafters/stable: '**settings.arch_build**' value not defined

Mmmh, android uses `arch_build` and `os_build` (https://github.com/bincrafters/conan-android_ndk_installer/blob/testing/r20b/conanfile.py)

@SSE4 @jgsogo 
How can this be done?
Nothing working now. 

### Logs (Include/Attach if Applicable)
<details><summary>Click to expand log</summary>

```
conan install ./conanfile.txt --build missing -pr:h ./profiles/android1 -pr:b ./profiles/build
Configuration (profile_host):
[settings]
arch=armv8
build_type=Release
compiler=clang
compiler.libcxx=libc++
compiler.version=9
os=Android
os.api_level=21
[options]
[build_requires]
[env]

Configuration (profile_build):
[settings]
arch=x86_64
os=Macos
[options]
[build_requires]
*: android_ndk_installer/r21d@bincrafters/stable, cmake/3.19.0, m4/1.4.18, autoconf/2.69, automake/1.16.2, ninja/1.10.1
[env]

WARN: cpprestsdk/2.10.16: requirement openssl/1.1.1g overridden by your conanfile to openssl/1.1.1h 
WARN: libxslt/1.1.33@bincrafters/stable: requirement libxml2/2.9.9 overridden by your conanfile to libxml2/2.9.10 
openssl/1.1.1h: WARN: Package binary is corrupted, removing: d90c6937a846904107bf4cebd7a8705bc34c61ab


Cross-build from 'Macos:x86_64' to 'Android:armv8'
Installing (downloading, building) binaries...

openssl/1.1.1h: Copying sources to build folder
openssl/1.1.1h: Building your package in /Users/dmn/.conan/data/openssl/1.1.1h/_/_/build/d90c6937a846904107bf4cebd7a8705bc34c61ab
openssl/1.1.1h: Generator txt created conanbuildinfo.txt
openssl/1.1.1h: Calling build()
openssl/1.1.1h: using target: conan-Release-Android-armv8-clang-9 -> linux-generic64
openssl/1.1.1h: my %targets = (
    "conan-Release-Android-armv8-clang-9" => {
        inherit_from => [ "linux-generic64" ],
        cflags => add("-O3"),
        cxxflags => add("-O3"),
        defines => add("NDEBUG"),
        includes => add(),
        lflags => add(""),
        
        
        
        
        
        
        
        perlasm_scheme => "linux64",
    },
);

openssl/1.1.1h: ['"conan-Release-Android-armv8-clang-9"', 'no-shared', '--prefix="/Users/dmn/.conan/data/openssl/1.1.1h/_/_/package/d90c6937a846904107bf4cebd7a8705bc34c61ab"', '--openssldir="/Users/dmn/.conan/data/openssl/1.1.1h/_/_/package/d90c6937a846904107bf4cebd7a8705bc34c61ab/res"', 'no-unit-test', 'threads', 'PERL=perl', 'no-tests', '--release', ' -D__ANDROID_API__=21', '-fPIC']
Configuring OpenSSL version 1.1.1h (0x1010108fL) for conan-Release-Android-armv8-clang-9
Using os-specific seed configuration
Creating configdata.pm
Creating Makefile

**********************************************************************
***                                                                ***
***   OpenSSL has been successfully configured                     ***
***                                                                ***
***   If you encounter a problem while building, please open an    ***
***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***
***   and include the output from the following command:           ***
***                                                                ***
***       perl configdata.pm --dump                                ***
***                                                                ***
***   (If you are new to OpenSSL, you might want to consult the    ***
***   'Troubleshooting' section in the INSTALL file first)         ***
***                                                                ***


gcc  -I. -Iinclude -fPIC -pthread -O3 -Wall -O3 -fPIC -DOPENSSL_USE_NODELETE -DOPENSSL_PIC -DOPENSSLDIR="\"/Users/dmn/.conan/data/openssl/1.1.1h/_/_/package/d90c6937a846904107bf4cebd7a8705bc34c61ab/res\"" -DENGINESDIR="\"/Users/dmn/.conan/data/openssl/1.1.1h/_/_/package/d90c6937a846904107bf4cebd7a8705bc34c61ab/lib/engines-1.1\"" -DNDEBUG -DNDEBUG -D__ANDROID_API__=21 -MMD -MF ssl/d1_msg.d.tmp -MT ssl/d1_msg.o -c -o ssl/d1_msg.o ssl/d1_msg.c
gcc  -I. -Iinclude -fPIC -pthread -O3 -Wall -O3 -fPIC -DOPENSSL_USE_NODELETE -DOPENSSL_PIC -DOPENSSLDIR="\"/Users/dmn/.conan/data/openssl/1.1.1h/_/_/package/d90c6937a846904107bf4cebd7a8705bc34c61ab/res\"" -DENGINESDIR="\"/Users/dmn/.conan/data/openssl/1.1.1h/_/_/package/d90c6937a846904107bf4cebd7a8705bc34c61ab/lib/engines-1.1\"" -DNDEBUG -DNDEBUG -D__ANDROID_API__=21 -MMD -MF ssl/d1_srtp.d.tmp -MT ssl/d1_srtp.o -c -o ssl/d1_srtp.o ssl/d1_srtp.c
engines/e_afalg.c:24:10: fatal error: 'linux/version.h' file not found
#include <linux/version.h>
         ^~~~~~~~~~~~~~~~~
1 error generated.
make[1]: *** [engines/e_afalg.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [all] Error 2
openssl/1.1.1h: 
openssl/1.1.1h: ERROR: Package 'd90c6937a846904107bf4cebd7a8705bc34c61ab' build failed
openssl/1.1.1h: WARN: Build folder /Users/dmn/.conan/data/openssl/1.1.1h/_/_/build/d90c6937a846904107bf4cebd7a8705bc34c61ab
ERROR: openssl/1.1.1h: Error in build() method, line 704
        self._make()
while calling '_make', line 658
        self._run_make()
while calling '_run_make', line 616
        self.run(" ".join(command), win_bash=self._win_bash)
        ConanException: Error 2 while executing /usr/bin/make -j12

```

</details>
 
Hi! Using the two profiles approach is the way to go and Conan will deprecate `os_build` `arch_build` settings in Conan v2 (we cannot do it before). The `android-ndk` recipe in bincrafters will stop to work as it is implemented now. There are other efforts you can have a look to, like https://github.com/conan-io/conan-center-index/pull/3004 by @a4z  (I haven't had time to have a look at it, and I should 😞 , but time constraints...).

In Conan we are also working in a new paradigm to supersede some limitations of the current build. We are working on `toolchains` (experimental yet) and if we manage to provide everything we want, it will be the default way (and only way) in Conan 2.0.  Not ready yet.

@dmn-star the profiles shared by @madebr should work using a new implementation of the `android-ndk` recipe (the one in the PR I shared with you before or [here](https://github.com/jgsogo/conan-center-index/tree/android_ndk/recipes/android-ndk/all) you can find a POC by myself). It is important to realize that you need to choose between old approach (one profile and `os/arch_build` settings) or the new approach (two profiles), they are not going to play well together. Choose one and use it.

In your latest log you are using two profiles, but there is something wrong:

 * your _host_ profile, it says the binaries you are generating, this one looks like ok:
   ```
   Configuration (profile_host):
   [settings]
   arch=armv8
   build_type=Release
   compiler=clang
   compiler.libcxx=libc++
   compiler.version=9
   os=Android
   os.api_level=21
   [options]
   [build_requires]
   [env]
   ```

 * but your _build_ profile is wrong. The _build_ profile tell Conan the binaries to use in the build-machine, the binaries that are going to run where you are compiling your sources, these are typically Win/Linux/Macos binaries. 
   ```
   Configuration (profile_build):
   [settings]
   arch=x86_64
   os=Macos
   [options]
   [build_requires]
   *: android_ndk_installer/r21d@bincrafters/stable, cmake/3.19.0, m4/1.4.18, autoconf/2.69, automake/1.16.2, ninja/1.10.1
   [env]
   ```

   The `[settings]` section is right, you are using Macos/x86_64, but you are telling Conan to generate these binaries using `android_ndk_installer`... are you going to generate binaries for Macos using Android-NDK? I don't think so.

You should use the profiles suggested by @madebr (https://github.com/conan-io/conan-center-index/issues/3627#issuecomment-731198329), the build-requires to `android-ndk` appears in the _host_ profile, you are telling Conan to build the binaries for your _host_ architecture (Android) using Android-NDK. 👍 

Keep in mind:
 * `build_requires` tells Conan the tools to use to generate the binaries that match that profile.
 * `host` profile: describes the binaries to be generated, the library/project you want to build.
    + if this profile contains any `build_requires`, these packages listed under `[build_requires]` will be built (only if needed) using the settings in the `build`-profile because the are to be run in the build-machine.
 * `build` profile: describes the binaries you will be **using** to generate the packages in the `host` profile.
    + if this profile contains any `build_requires`, these packages listed here will only be retrieved if Conan needs to build some of the packages in the `build`-context (packages that are build-requires of your library).

![image](https://user-images.githubusercontent.com/1406456/100131379-400bad80-2e84-11eb-89ca-284a00c0667b.png)


I think I'm not explaining myself well enough 😓   Feel free to blame me and I'll try to explain it better.



if the bincrafters/stable has not been changed since I looked at it the last time, I doubt you can use it with 2 profiles, since is uses os_build os_arch

this one https://github.com/conan-io/conan-center-index/pull/3004 works.

I would not waste time to the old approach with os_build and os_arch since the 2 profile way of handing xcompile is more natural and better, and you do not run into problems that build requirements wants to be build in debug modes, and sich things.... 

here an example how some of the  profiles I use look like, in the 2 profile way, for an OSX to Android Armv8 build
```
Configuration (profile_host):
[settings]
arch=armv8
build_type=Release
compiler=clang
compiler.libcxx=libc++
compiler.version=9
os=Android
os.api_level=21
[options]
libcurl:with_ssl=openssl
lua:compile_as_cpp=True
ms-gsl:on_contract_violation=throw
nlohmann_json:multiple_headers=True
paho-mqtt-c:asynchronous=True
paho-mqtt-c:shared=False
paho-mqtt-c:ssl=True
paho-mqtt-cpp:ssl=True
[build_requires]
*: android-ndk/r21d
[env]

Configuration (profile_build):
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=apple-clang
compiler.libcxx=libc++
compiler.version=12.0
os=Macos
os_build=Macos
[options]
[build_requires]
[env]

``` 

@jgsogo Many thanks for the detailed explanation.
@a4z Thank you very much for sharing your profiles and for #3004 

There is no way to build xmlsec with android_ndk_installer/r21d@bincrafters/stable.
The "old" way (arch_build and os_build ) and the "new" way ( 2 profiles) both don't work.

conan install xmlsec/1.2.30@ --build missing --profile:host ./conan/profiles/android  --profile:build ./conan/profiles/mac
Configuration (profile_host):
[settings]
arch=armv8
build_type=Release
compiler=clang
compiler.libcxx=libc++
compiler.version=9
os=Android
os.api_level=21
[options]
[build_requires]
[env]

Configuration (profile_build):
[settings]
arch=x86_64
build_type=Release
compiler=apple-clang
compiler.libcxx=libc++
compiler.version=12.0
os=Macos
[options]
[build_requires]
*: android_ndk_installer/r21d@bincrafters/stable, cmake/3.19.0, ninja/1.10.1, m4/1.4.18, autoconf/2.69, automake/1.16.2
[env]

ERROR: The recipe is contraining settings. Invalid setting 'Macos' is not a valid 'settings.os' value.
Possible values are ['Android']
Read "http://docs.conan.io/en/latest/faq/troubleshooting.html#error-invalid-setting"
I think, I wait until #3004 is merged.
your profile build is wrong since it still points to `bincrafters/stable`, that will not work

and yes, the old way with 1 profile is not good, and therefore the bincrafter package should be removed, it just steala peoples time who try it with it 

you can checkout #3004 and use it already today, not sure how long it will take until it is merged, it is already pretty long in the Q and I do not expect a fast process 



Resolving patch:
diff --git a/recipes/libxml2/all/conanfile.py b/recipes/libxml2/all/conanfile.py
--- a/recipes/libxml2/all/conanfile.py
+++ b/recipes/libxml2/all/conanfile.py
@@ -254,8 +254,7 @@ def package_info(self):
             bindir = os.path.join(self.package_folder, "bin")
             self.output.info("Appending PATH environment variable: {}".format(bindir))
             self.env_info.PATH.append(bindir)
-
-        if self.settings.os in ["Linux", "Macos", "FreeBSD"]:
+        if self.settings.os in ["Linux", "Macos", "FreeBSD", "Android"]:
             self.cpp_info.system_libs.append('m')
         if self.settings.os == "Windows":
             self.cpp_info.system_libs.append('ws2_32')


Test patch: