Repository: conan-io/conan-center-index

Issue:
[package] android-ndk/r22: Bug after update android recipe
<!-- 
  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: **android-ndk/r22**
  * Operating System+version: **Linux Ubuntu 18.04**
  * Compiler+version: **GCC 8**
  * Docker image: **conanio/gcc8**
  * Conan version: **conan latest**
  * 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)
```
include(default)

[settings]
os=Android
os.api_level=21
compiler=clang
compiler.version=11
compiler.libcxx=c++_static
arch=armv7

[build_requires]
*: android-ndk/r22

```


### Steps to reproduce (Include if Applicable)



### Logs (Include/Attach if Applicable)
<details><summary>Click to expand log</summary>


There is a problem on Android NDK R22 recipe after update to latest commit:

```
ERROR: android-ndk/r22: Error in package_info() method, line 266
	self.env_info.LD = self._define_tool_var("LD", "ld")
while calling '_define_tool_var', line 168
	raise ConanException(f"'Environment variable {name} could not be created: '{path}'")
	ConanException: 'Environment variable LD could not be created: '/home/runner/.conan/data/android-ndk/r22/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/toolchains/llvm/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld'
COMMAND: conan install /home/runner/work/ezored/ezored/files/targets/android/conan/recipe/conanfile.py -pr:b default -pr:h ezored_android_profile -s:h arch=armv7 -s:h os.api_level=16 -s:h build_type=Debug -o ezored_arch=armv7 -o ezored_name=ezored -o ezored_version=1.0.0 --build=missing --update
WORKING DIR: /home/runner/work/ezored/ezored/build/android/Debug/armv7/conan
```

</details>

FULL LOG:
https://github.com/ezored/ezored/runs/4108829881?check_suite_focus=true#step:12:182



Discussion:
I'm currently at the same point, same error. As far as I can see, there is a new check in the recipe: if the file the environment variable point to doesn't exist, raise this exception. Don't know if this file was missing before undetected or if it's missing now.

I can reproduce in conan-center-index master branch:

```
conan create recipes/gtest/all/ gtest/1.11.0@ -pr:b tmp/profiles/bcm/linux_profile -pr:h tmp/profiles/bcm/android_profile
```

Results in this output:

```
[HOOK - conan-center.py] pre_export(): [DEPRECATED GLOBAL CPPSTD (KB-H001)] OK
[HOOK - conan-center.py] pre_export(): [REFERENCE LOWERCASE (KB-H002)] OK
[HOOK - conan-center.py] pre_export(): [RECIPE METADATA (KB-H003)] OK
[HOOK - conan-center.py] pre_export(): [HEADER_ONLY, NO COPY SOURCE (KB-H005)] OK
[HOOK - conan-center.py] pre_export(): [FPIC OPTION (KB-H006)] OK
[HOOK - conan-center.py] pre_export(): [VERSION RANGES (KB-H008)] OK
[HOOK - conan-center.py] pre_export(): [RECIPE FOLDER SIZE (KB-H009)] Total recipe size: 42.8134765625 KB
[HOOK - conan-center.py] pre_export(): [RECIPE FOLDER SIZE (KB-H009)] OK
[HOOK - conan-center.py] pre_export(): [EXPORT LICENSE (KB-H023)] exports: None
[HOOK - conan-center.py] pre_export(): [EXPORT LICENSE (KB-H023)] exports: ['CMakeLists.txt', 'patches/*']
[HOOK - conan-center.py] pre_export(): [EXPORT LICENSE (KB-H023)] OK
[HOOK - conan-center.py] pre_export(): [TEST PACKAGE FOLDER (KB-H024)] OK
[HOOK - conan-center.py] pre_export(): [META LINES (KB-H025)] OK
[HOOK - conan-center.py] pre_export(): [CONAN CENTER INDEX URL (KB-H027)] OK
[HOOK - conan-center.py] pre_export(): [CMAKE MINIMUM VERSION (KB-H028)] OK
[HOOK - conan-center.py] pre_export(): [TEST PACKAGE - RUN ENVIRONMENT (KB-H029)] OK
[HOOK - conan-center.py] pre_export(): [SYSTEM REQUIREMENTS (KB-H032)] OK
[HOOK - conan-center.py] pre_export(): [CONANDATA.YML FORMAT (KB-H030)] OK
[HOOK - conan-center.py] pre_export(): [TEST PACKAGE - NO IMPORTS() (KB-H034)] OK
[HOOK - conan-center.py] pre_export(): [NO AUTHOR (KB-H037)] OK
[HOOK - conan-center.py] pre_export(): [NO TARGET NAME (KB-H040)] OK
[HOOK - conan-center.py] pre_export(): [NO FINAL ENDLINE (KB-H041)] OK
[HOOK - conan-center.py] pre_export(): [NO REQUIRES.ADD() (KB-H044)] OK
[HOOK - conan-center.py] pre_export(): [DELETE OPTIONS (KB-H045)] OK
[HOOK - conan-center.py] pre_export(): [CMAKE VERBOSE MAKEFILE (KB-H046)] OK
[HOOK - conan-center.py] pre_export(): [CMAKE VERSION REQUIRED (KB-H048)] OK
[HOOK - conan-center.py] pre_export(): [CMAKE WINDOWS EXPORT ALL SYMBOLS (KB-H049)] OK
[HOOK - conan-center.py] pre_export(): [DEFAULT OPTIONS AS DICTIONARY (KB-H051)] OK
[HOOK - conan-center.py] pre_export(): [CONFIG.YML HAS NEW VERSION (KB-H052)] OK
[HOOK - conan-center.py] pre_export(): [PRIVATE IMPORTS (KB-H053)] OK
[HOOK - conan-center.py] pre_export(): [SINGLE REQUIRES (KB-H055)] OK
[HOOK - conan-center.py] pre_export(): [TOOLS RENAME (KB-H057)] OK
[HOOK - conan-center.py] pre_export(): [ILLEGAL CHARACTERS (KB-H058)] OK
[HOOK - conan-center.py] pre_export(): [CLASS NAME (KB-H059)] OK
[HOOK - conan-center.py] pre_export(): [NO CRLF (KB-H060)] OK
[HOOK - conan-center.py] pre_export(): [NO BUILD SYSTEM FUNCTIONS (KB-H061)] OK
[HOOK - conan-center.py] pre_export(): WARN: [TOOLS CROSS BUILDING (KB-H062)] The 'tools.cross_building(self.settings)' syntax in /home/zoufala/sandbox/github/andioz/conan-center-index/recipes/gtest/all/test_package/conanfile.py may not work correctly in some scenarios. Consider using tools.cross_building(self).
[HOOK - conan-center.py] pre_export(): [TOOLS CROSS BUILDING (KB-H062)] OK
[HOOK - conan-center.py] pre_export(): [INVALID TOPICS (KB-H064)] OK
Exporting package recipe
gtest/1.11.0 exports: File 'conandata.yml' found. Exporting it...
gtest/1.11.0 exports: Copied 1 '.yml' file: conandata.yml
gtest/1.11.0 exports_sources: Copied 1 '.txt' file: CMakeLists.txt
gtest/1.11.0 exports_sources: Copied 3 '.patch' files: gtest-1.8.1.patch, gtest-1.10.0.patch, gtest-1.10.0-override.patch
[HOOK - conan-center.py] post_export(): [CONANDATA.YML REDUCE (KB-H031)] Saving conandata.yml: {'sources': {'1.11.0': {'url': 'https://github.com/google/googletest/archive/release-1.11.0.tar.gz', 'sha256': 'b4870bf121ff7795ba20d20bcdd8627b8e088f2d1dab299a031c1034eddc93d5'}}}
[HOOK - conan-center.py] post_export(): [CONANDATA.YML REDUCE (KB-H031)] New conandata.yml contents: sources:
  1.11.0:
    sha256: b4870bf121ff7795ba20d20bcdd8627b8e088f2d1dab299a031c1034eddc93d5
    url: https://github.com/google/googletest/archive/release-1.11.0.tar.gz

[HOOK - conan-center.py] post_export(): [CONANDATA.YML REDUCE (KB-H031)] OK
[HOOK - conan-center.py] post_export(): [DEFAULT SHARED OPTION VALUE (KB-H050)] OK
[HOOK - conan-center.py] post_export(): [LICENSE PUBLIC DOMAIN (KB-H056)] OK
gtest/1.11.0: A new conanfile.py version was exported
gtest/1.11.0: Folder: /home/zoufala/sandbox/github/andioz/conan-center-index/tmp/.conan/data/gtest/1.11.0/_/_/export
gtest/1.11.0: Exported revision: 088aa58a3c2115519f99667eee50d0a1
Configuration (profile_host):
[settings]
arch=armv8
build_type=Release
compiler=clang
compiler.libcxx=c++_static
compiler.version=11
os=Android
os.api_level=21
[options]
[build_requires]
*: android-ndk/r22
[env]

Configuration (profile_build):
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=9
os=Linux
os_build=Linux
[options]
[build_requires]
[env]

gtest/1.11.0: Forced build from source
android-ndk/r22: Not found in local cache, looking in remotes...
android-ndk/r22: Trying with 'conancenter'...
Downloading conanmanifest.txt completed [0.23k]                                          
Downloading conanfile.py completed [14.60k]                                              
Downloading conan_export.tgz completed [0.39k]                                           
Decompressing conan_export.tgz completed [0.00k]                                         
android-ndk/r22: Downloaded recipe revision 0
gtest/1.11.0 (test package): Installing package
Requirements
    gtest/1.11.0 from local cache - Cache
Packages
    gtest/1.11.0:4c229a6088f1fcee4be0cf8bd89eff11cbf3b712 - Build
Build requirements
    android-ndk/r22 from 'conancenter' - Cache
Build requirements packages
    android-ndk/r22:4db1be536558d833e52e862fd84d64d75c2b3656 - Download

Cross-build from 'Linux:x86_64' to 'Android:armv8'
Installing (downloading, building) binaries...
android-ndk/r22: Retrieving package 4db1be536558d833e52e862fd84d64d75c2b3656 from remote 'conancenter' 
Downloading conanmanifest.txt completed [1011.84k]                                       
Downloading conaninfo.txt completed [0.20k]                                              
Downloading conan_package.tgz completed [1113459.34k]                                    
Decompressing conan_package.tgz completed [0.00k]                                        
android-ndk/r22: Package installed 4db1be536558d833e52e862fd84d64d75c2b3656
android-ndk/r22: Downloaded package revision 0
android-ndk/r22: Creating ANDROID_NDK_ROOT environment variable: /home/zoufala/sandbox/github/andioz/conan-center-index/tmp/.conan/data/android-ndk/r22/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656
android-ndk/r22: Creating ANDROID_NDK_HOME environment variable: /home/zoufala/sandbox/github/andioz/conan-center-index/tmp/.conan/data/android-ndk/r22/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656
android-ndk/r22: Creating CONAN_CMAKE_SYSTEM_PROCESSOR environment variable: aarch64
android-ndk/r22: Creating NDK_ROOT environment variable: /home/zoufala/sandbox/github/andioz/conan-center-index/tmp/.conan/data/android-ndk/r22/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/toolchains/llvm/prebuilt/linux-x86_64
android-ndk/r22: Creating CHOST environment variable: aarch64-linux-android
android-ndk/r22: Creating CONAN_CMAKE_FIND_ROOT_PATH environment variable: /home/zoufala/sandbox/github/andioz/conan-center-index/tmp/.conan/data/android-ndk/r22/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/toolchains/llvm/prebuilt/linux-x86_64/sysroot
android-ndk/r22: Creating SYSROOT environment variable: /home/zoufala/sandbox/github/andioz/conan-center-index/tmp/.conan/data/android-ndk/r22/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/toolchains/llvm/prebuilt/linux-x86_64/sysroot
android-ndk/r22: Creating self.cpp_info.sysroot: /home/zoufala/sandbox/github/andioz/conan-center-index/tmp/.conan/data/android-ndk/r22/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/toolchains/llvm/prebuilt/linux-x86_64/sysroot
android-ndk/r22: Creating ANDROID_NATIVE_API_LEVEL environment variable: 21
android-ndk/r22: Creating CONAN_CMAKE_PROGRAM environment variable: /home/zoufala/sandbox/github/andioz/conan-center-index/tmp/.conan/data/android-ndk/r22/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/cmake-wrapper
android-ndk/r22: Creating CONAN_CMAKE_TOOLCHAIN_FILE environment variable: /home/zoufala/sandbox/github/andioz/conan-center-index/tmp/.conan/data/android-ndk/r22/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/build/cmake/android.toolchain.cmake
android-ndk/r22: Creating CC environment variable: /home/zoufala/sandbox/github/andioz/conan-center-index/tmp/.conan/data/android-ndk/r22/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang
android-ndk/r22: Creating CXX environment variable: /home/zoufala/sandbox/github/andioz/conan-center-index/tmp/.conan/data/android-ndk/r22/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang++
ERROR: android-ndk/r22: Error in package_info() method, line 266
	self.env_info.LD = self._define_tool_var("LD", "ld")
while calling '_define_tool_var', line 168
	raise ConanException(f"'Environment variable {name} could not be created: '{path}'")
	ConanException: 'Environment variable LD could not be created: '/home/zoufala/sandbox/github/andioz/conan-center-index/tmp/.conan/data/android-ndk/r22/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-ld'
```


Can anyone help us :)
@justinmcbride I add you here because you made the last update, maybe you have better insights… 
I tried the previous recipe, adding the checks:

```python
        if not os.path.isfile(path):
            raise ConanException(f"'Environment variable {name} could not be created: '{path}'")
```

I'm not surprised, th old recipe fails here too. `LD` is the only variable which has no executable. I'm not sure if this is a bug for a long time now, but I think things would not work without `LD`, right? 

In my case (armv8), there exists 2 executables with extra suffices:

```
.conan/data/android-ndk/r22/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-ld.bfd
.conan/data/android-ndk/r22/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-ld.gold
```
And I've seen there exists options like `-fuse-ld=gold`.
https://github.com/android/ndk/issues/556

I guess in case of `LD` only the prefix is meant, not the real executable, and the additional suffix is added at runtime? Does anyone know more about this NDK details?


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
@@ -263,7 +263,11 @@ def package_info(self):
             self.env_info.READELF = self._define_tool_var("READELF", "readelf", True)
             # there doesn't seem to be an 'elfedit' included anymore.
         else:
-            self.env_info.LD = self._define_tool_var("LD", "ld")
+            if tools.Version(self._ndk_version) >= 22:
+                # Special handling for LD in r22 required: ld has no prefix
+                self.env_info.LD = self._define_tool_var_naked("LD", "ld")
+            else:
+                self.env_info.LD = self._define_tool_var("LD", "ld")
             self.env_info.AR = self._define_tool_var("AR", "ar")
             self.env_info.AS = self._define_tool_var("AS", "as")
             self.env_info.RANLIB = self._define_tool_var("RANLIB", "ranlib")


Test patch: