Repository: conan-io/conan-center-index

Issue:
[package] expat/2.4.8: Problems for iOS and Android
### Package and Environment Details

* Package Name/Version: **expat/2.4.8**
* Operating System+version: **macos**
* Compiler+version: **clang**
* Docker image: **conanio/gcc8**
* Conan version: **n/a**
* Python version: **Python 3.9**


### Conan profile

ANDROID:

```
Configuration (profile_host):
[settings]
arch=armv7
build_type=Debug
compiler=clang
compiler.libcxx=c++_static
compiler.version=14
os=Android
os.api_level=19
[options]
nativium_arch=armeabi-v7a
nativium_build_type=debug
nativium_entrypoint=main
nativium_product_name=Nativium
nativium_project_name=nativium
nativium_target=android
nativium_version=1.0.0
nativium_version_code=1
[build_requires]
*: android-ndk/r24
[env]

Configuration (profile_build):
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++
compiler.version=9
os=Linux
os_build=Linux
[options]
[build_requires]
[env]
```

iOS:

```
Configuration (profile_host):
[settings]
arch=armv7
arch_build=x86_64
build_type=Debug
compiler=apple-clang
compiler.libcxx=libc++
compiler.version=13
os=iOS
os.version=9
os_build=Macos
[options]
nativium_arch=armv7
nativium_build_type=debug
nativium_group=ios
nativium_product_name=Nativium
nativium_project_name=nativium
nativium_target=ios
nativium_version=1.0.0
nativium_version_code=1
darwin-toolchain:enable_bitcode=True
[build_requires]
*: darwin-toolchain/1.0.0@nativium/stable
[env]

Configuration (profile_build):
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=apple-clang
compiler.libcxx=libc++
compiler.version=13
os=Macos
os_build=Macos
[options]
[build_requires]
[env]
```

### Steps to reproduce

_No response_

### Logs

<details><summary>Click to expand log</summary>


On iOS i get this error:

```
expat/2.4.8: Applying build-requirement: darwin-toolchain/1.0.0@nativium/stable
expat/2.4.8: Configuring sources in /Users/runner/.conan/data/expat/2.4.8/_/_/source
expat/2.4.8: 
expat/2.4.8: Copying sources to build folder
expat/2.4.8: Building your package in /Users/runner/.conan/data/expat/2.4.8/_/_/build/46221fc4c36793650b0016e531a7f0811b03d5eb
expat/2.4.8: Generator txt created conanbuildinfo.txt
expat/2.4.8: Calling generate()
ERROR: expat/2.4.8: Error in generate() method, line 77
	tc.generate()
	ConanException: Please, specify a suitable value for os.sdk.
```

Link: https://github.com/nativium/nativium-modules/runs/7523237525?check_suite_focus=true#step:14:289

On Android i get this error:

```
expat/2.4.8: Applying build-requirement: android-ndk/r24
expat/2.4.8: Configuring sources in /home/runner/.conan/data/expat/2.4.8/_/_/source
expat/2.4.8: 
expat/2.4.8: Copying sources to build folder
expat/2.4.8: Building your package in /home/runner/.conan/data/expat/2.4.8/_/_/build/0d8a864b9520081c588f865eed67d1f1730380fc
expat/2.4.8: Generator txt created conanbuildinfo.txt
expat/2.4.8: Calling generate()
WARN: Remotes registry file missing, creating default one in /home/runner/.conan/remotes.json
ERROR: expat/2.4.8: Error in generate() method, line 77
	tc.generate()
	ConanException: 'settings.compiler.libcxx' doesn't exist for 'clang'
'settings.compiler' possible configurations are ['runtime', 'runtime_type', 'version']
```

Link: https://github.com/nativium/nativium-modules/runs/7523237528?check_suite_focus=true#step:14:475

</details>



Discussion:
I have updated everything and it still not working:

**ANDROID:**

```
CMakeToolchain needs tools.android:ndk_path configuration defined
```

Im using conan android ndk recipe.

[settings]
os=Android
os.api_level=21
compiler=clang
compiler.version=14
compiler.libcxx=c++_static
arch=armv8

[build_requires]
*: android-ndk/r24

Log:
https://github.com/nativium/nativium-modules/runs/7685214156?check_suite_focus=true#step:14:474

**IOS:**

```
ERROR: expat/2.4.8: Error in generate() method, line 77
	tc.generate()
	ConanException: Please, specify a suitable value for os.sdk.
```

Log:
https://github.com/nativium/nativium-modules/runs/7685214142?check_suite_focus=true#step:14:286

Something is very wrong, because it start happen recently.
Duplicated with https://github.com/conan-io/conan-center-index/issues/11863

Resolving patch:
diff --git a/recipes/android-ndk/all/conanfile.py b/recipes/android-ndk/all/conanfile.py
--- a/recipes/android-ndk/all/conanfile.py
+++ b/recipes/android-ndk/all/conanfile.py
@@ -1,10 +1,11 @@
-from conan import ConanFile, tools
+from conan import ConanFile
 from conan.errors import ConanInvalidConfiguration
+from conan.tools.files import get, download, unzip, load, copy
 import os
 import re
 import shutil
 
-required_conan_version = ">=1.33.0"
+required_conan_version = ">=1.47.0"
 
 
 class AndroidNDKConan(ConanFile):
@@ -22,7 +23,7 @@ class AndroidNDKConan(ConanFile):
 
     @property
     def _source_subfolder(self):
-        return "source_subfolder"
+        return os.path.join(self.source_folder, "source_subfolder")
 
     @property
     def _is_universal2(self):
@@ -47,9 +48,9 @@ def validate(self):
     def build(self):
         if self.version in ['r23', 'r23b', 'r23c', 'r24', 'r25']:
             data = self.conan_data["sources"][self.version][str(self.settings.os)][str(self._arch)]
-            self.unzip_fix_symlinks(url=data["url"], target_folder=self._source_subfolder, sha256=data["sha256"])
+            self._unzip_fix_symlinks(url=data["url"], target_folder=self._source_subfolder, sha256=data["sha256"])
         else:
-            tools.files.get(self, **self.conan_data["sources"][self.version][str(self.settings.os)][str(self._arch)],
+            get(self, **self.conan_data["sources"][self.version][str(self.settings.os)][str(self._arch)],
                   destination=self._source_subfolder, strip_root=True)
 
     def package_id(self):
@@ -59,11 +60,11 @@ def package_id(self):
         del self.info.settings.build_type
 
     def package(self):
-        self.copy("*", src=self._source_subfolder, dst=".", keep_path=True, symlinks=True)
-        self.copy("*NOTICE", src=self._source_subfolder, dst="licenses")
-        self.copy("*NOTICE.toolchain", src=self._source_subfolder, dst="licenses")
-        self.copy("cmake-wrapper.cmd")
-        self.copy("cmake-wrapper")
+        copy(self, "*", src=self._source_subfolder, dst=self.package_folder, keep_path=True)
+        copy(self, "*NOTICE", src=self._source_subfolder, dst=os.path.join(self.package_folder, "licenses"))
+        copy(self, "*NOTICE.toolchain", src=self._source_subfolder, dst=os.path.join(self.package_folder, "licenses"))
+        copy(self, "cmake-wrapper.cmd", src=self.build_folder, dst=self.package_folder)
+        copy(self, "cmake-wrapper", src=self.build_folder, dst=self.package_folder)
         self._fix_broken_links()
         self._fix_permissions()
 
@@ -340,38 +341,40 @@ def package_info(self):
         self.env_info.CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = "BOTH"
         self.env_info.CMAKE_FIND_ROOT_PATH_MODE_PACKAGE = "BOTH"
 
+        self.conf_info.define("tools.android:ndk_path", self.package_folder)
 
-    def unzip_fix_symlinks(self, url, target_folder, sha256):
+
+    def _unzip_fix_symlinks(self, url, target_folder, sha256):
         # Python's built-in module 'zipfile' won't handle symlinks (https://bugs.python.org/issue37921)
         # Most of the logic borrowed from this PR https://github.com/conan-io/conan/pull/8100
-    
+
         filename = "android_sdk.zip"
-        tools.files.download(self, url, filename, sha256=sha256)
-        tools.files.unzip(self, filename, destination=target_folder, strip_root=True)
-    
+        download(self, url, filename, sha256=sha256)
+        unzip(self, filename, destination=target_folder, strip_root=True)
+
         def is_symlink_zipinfo(zi):
             return (zi.external_attr >> 28) == 0xA
-    
+
         full_path = os.path.normpath(target_folder)
         import zipfile
         with zipfile.ZipFile(filename, "r") as z:
             zip_info = z.infolist()
-    
+
             names = [n.replace("\\", "/") for n in z.namelist()]
             common_folder = os.path.commonprefix(names).split("/", 1)[0]
-    
+
             for file_ in zip_info:
                 if is_symlink_zipinfo(file_):
                     rel_path = os.path.relpath(file_.filename, common_folder)
                     full_name = os.path.join(full_path, rel_path)
-                    target = tools.files.load(self, full_name)
+                    target = load(self, full_name)
                     os.unlink(full_name)
-    
+
                     try:
                         os.symlink(target, full_name)
                     except OSError:
                         if not os.path.isabs(target):
                             target = os.path.normpath(os.path.join(os.path.dirname(full_name), target))
                         shutil.copy2(target, full_name)
-    
+
         os.unlink(filename)


Test patch:
diff --git a/recipes/android-ndk/all/test_package/CMakeLists.txt b/recipes/android-ndk/all/test_package/CMakeLists.txt
--- a/recipes/android-ndk/all/test_package/CMakeLists.txt
+++ b/recipes/android-ndk/all/test_package/CMakeLists.txt
@@ -1,8 +1,5 @@
 cmake_minimum_required(VERSION 3.0)
-project(test_package)
-
-include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
-conan_basic_setup(TARGETS)
+project(test_package CXX)
 
 add_executable(${PROJECT_NAME} test_package.cpp)
 target_link_libraries(${PROJECT_NAME})
diff --git a/recipes/android-ndk/all/test_package/conanfile.py b/recipes/android-ndk/all/test_package/conanfile.py
--- a/recipes/android-ndk/all/test_package/conanfile.py
+++ b/recipes/android-ndk/all/test_package/conanfile.py
@@ -1,31 +1,34 @@
 import os
-from conans import ConanFile, tools, CMake
+from conan import ConanFile
+from conan.tools.cmake import CMake, cmake_layout
+from conan.tools.build import cross_building
 
 
 class TestPackgeConan(ConanFile):
-    settings = "os", "arch"
-    test_type = "explicit"
-    generators = "cmake"
+    settings = "os", "arch", "compiler", "build_type"
+    generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
 
     def build_requirements(self):
-        self.build_requires(self.tested_reference_str)
+        self.tool_requires(self.tested_reference_str)
+
+    def layout(self):
+        cmake_layout(self)
 
     def build(self):
-        # It only makes sense to build a library, if the target os is Android
+        # INFO: It only makes sense to build a library, if the target OS is Android
         if self.settings.os == "Android":
             cmake = CMake(self)
             cmake.configure()
             cmake.build()
 
     def test(self):
-        if not tools.cross_building(self):
+        if not cross_building(self):
             if self.settings.os == "Windows":
-                self.run("ndk-build.cmd --version", run_environment=True)
+                self.run("ndk-build.cmd --version", env="conanrun")
             else:
-                self.run("ndk-build --version", run_environment=True)
+                self.run("ndk-build --version", env="conanrun")
 
-        # Run the project that was built using Android NDK
+        # INFO: Run the project that was built using Android NDK
         if self.settings.os == "Android":
             test_file = os.path.join("bin", "test_package")
             assert os.path.exists(test_file)
-            # self.run("android-emulator {}".format(test_file), run_environment=True)
diff --git a/recipes/android-ndk/all/test_v1_package/CMakeLists.txt b/recipes/android-ndk/all/test_v1_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/android-ndk/all/test_v1_package/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.0)
+project(test_package CXX)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup(TARGETS)
+
+add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/../test_package/test_package.cpp)
+target_link_libraries(${PROJECT_NAME})
diff --git a/recipes/android-ndk/all/test_v1_package/conanfile.py b/recipes/android-ndk/all/test_v1_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/android-ndk/all/test_v1_package/conanfile.py
@@ -0,0 +1,32 @@
+import os
+from conan import ConanFile
+from conans import CMake
+from conan.tools.build import cross_building
+
+
+class TestPackgeConan(ConanFile):
+    settings = "os", "arch", "compiler", "build_type"
+    test_type = "explicit"
+    generators = "cmake"
+
+    def build_requirements(self):
+        self.build_requires(self.tested_reference_str)
+
+    def build(self):
+        # It only makes sense to build a library, if the target os is Android
+        if self.settings.os == "Android":
+            cmake = CMake(self)
+            cmake.configure()
+            cmake.build()
+
+    def test(self):
+        if not cross_building(self):
+            if self.settings.os == "Windows":
+                self.run("ndk-build.cmd --version", run_environment=True)
+            else:
+                self.run("ndk-build --version", run_environment=True)
+
+        # Run the project that was built using Android NDK
+        if self.settings.os == "Android":
+            test_file = os.path.join("bin", "test_package")
+            assert os.path.exists(test_file)