I set ANDROID_NDK_HOME but it keep says not set correctly - android-ndk

pedrojung#pedroui-MacBookPro MediaPipeUnityPlugin-master2 % echo $ANDROID_HOME
/Users/pedrojung/Library/Android/sdk
pedrojung#pedroui-MacBookPro MediaPipeUnityPlugin-master2 % echo $ANDROID_NDK_HOME
/Users/pedrojung/Library/Android/sdk/ndk
what is weird is that
on setting android_ndk_home
pedrojung#pedroui-MacBookPro MediaPipeUnityPlugin-master2 % export ANDROID_NDK_HOME =/Users/pedrojung/Library/Android/sdk/ndk
zsh: /Users/pedrojung/Library/Android/sdk/ndk not found
it says idk folder is not found but it exist.
anyway, echo command says ANDROID_NDK_HOME is set.
ANDROID_NDK_HOME is located just same folder of ANDROID_HOME with only difference of idk folder...
error is.
Analysis of target '//mediapipe_api:mediapipe_proto_srcs' failed; build aborted: Could not read RELEASE.TXT in Android NDK: /Users/pedrojung/Library/Android/sdk/ndk/RELEASE.TXT (No such file or directory) Unable to read the Android NDK at /Users/pedrojung/Library/Android/sdk/ndk, the path may be invalid. Is the path in android_ndk_repository() or ANDROID_NDK_HOME set correctly? If the path is correct, the contents in the Android NDK directory may have been modified.
from above error , I can get android_ndk is not set correctly.
how can I set android_ndk correctly...?
I'm using m1 MacBook.
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
pedrojung#pedroui-MacBookPro MediaPipeUnityPlugin-master2 % cd $ANDROID_NDK_HOME
pedrojung#pedroui-MacBookPro ndk % ls
21.4.7075529 22.1.7171670 23.0.7599858
I checked path again, and yes it really has ndk.
and I installed ndk through android studio 's SDK manager.

Related

Unknown host CPU architecture: arm64 , Android NDK SiliconM1 Apple MacBook Pro

I've got a project that is working fine in windows os but when I switched my laptop and opened an existing project in MacBook Pro M1. I'm unable to run an existing android project in MacBook pro M1. first I was getting
Execution failed for task ':app:kaptDevDebugKotlin'. > A failure
occurred while executing
org.jetbrains.kotlin.gradle.internal.KaptExecution >
java.lang.reflect.InvocationTargetException (no error message)
this error was due to the Room database I applied a fix that was adding below library before Room database and also changed my JDK location from file structure from JRE to JDK.
kapt "org.xerial:sqlite-jdbc:3.34.0"
//Room components
kapt "org.xerial:sqlite-jdbc:3.34.0"
implementation "androidx.room:room-ktx:$rootProject.roomVersion"
kapt "androidx.room:room-compiler:$rootProject.roomVersion"
androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"
after that now I'm getting an issue which is Unknown host CPU architecture: arm64
there is an SDK in my project that is using this below line.
android {
externalNativeBuild {
ndkBuild {
path 'Android.mk'
}
}
ndkVersion '21.4.7075529'
}
App Gradle
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.18.1"
//version "3.10.2"
}
}
[CXX1405] error when building with ndkBuild using
/Users/mac/Desktop/Consumer-Android/ime/dictionaries/jnidictionaryv2/Android.mk:
Build command failed. Error while executing process
/Users/mac/Library/Android/sdk/ndk/21.4.7075529/ndk-build with
arguments {NDK_PROJECT_PATH=null
APP_BUILD_SCRIPT=/Users/mac/Desktop/Consumer-Android/ime/dictionaries/jnidictionaryv2/Android.mk
APP_ABI=arm64-v8a NDK_ALL_ABIS=arm64-v8a NDK_DEBUG=1
APP_PLATFORM=android-21
NDK_OUT=/Users/mac/Desktop/Consumer-Android/ime/dictionaries/jnidictionaryv2/build/intermediates/cxx/Debug/4k4s2lc6/obj
NDK_LIBS_OUT=/Users/mac/Desktop/Consumer-Android/ime/dictionaries/jnidictionaryv2/build/intermediates/cxx/Debug/4k4s2lc6/lib
APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n} ERROR:
Unknown host CPU architecture: arm64
which is causing this issue and whenever I comment on this line
path 'Android.mk'
it starts working fine, is there any way around which will help me run this project with this piece of code without getting this NDK issue?
Update - It seems that Room got fixed in the latest updates, Therefore you may consider updating Room to the latest version (2.3.0-alpha01 / 2.4.0-alpha03 or above)
use ndkVersion "24.0.8215888" update ndk to this version and no need to edit any script :)
GitHub Issue Tracker
solved this issue.
Finder -> Go To Folder(/Users/mac/Library/Android/sdk/ndk/21.4.7075529)
-> now edit ndk-build open it in text editor and paste below code script and re-run your project.
from
#!/bin/sh
DIR="$(cd "$(dirname "$0")" && pwd)"
$DIR/build/ndk-build "$#"
to
#!/bin/sh
DIR="$(cd "$(dirname "$0")" && pwd)"
arch -x86_64 /bin/bash $DIR/build/ndk-build "$#"
Reference Link
To solve this on a Apple Silicon M1 I found three options
A
Use NDK 24
android {
ndkVersion "24.0.8215888"
...
}
You can install it with
echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install 'ndk;24.0.8215888'
or
echo "y" | sudo ${ANDROID_HOME}/sdk/cmdline-tools/latest/bin/sdkmanager --install 'ndk;24.0.8215888'
Depending what where sdkmanager is located
B
Change your ndk-build to use Rosetta x86. Search for your installed ndk with
find ~ -name ndk-build 2>/dev/null
eg
vi ~/Library/Android/sdk/ndk/22.1.7171670/ndk-build
and change
DIR="$(cd "$(dirname "$0")" && pwd)"
$DIR/build/ndk-build "$#"
to
DIR="$(cd "$(dirname "$0")" && pwd)"
arch -x86_64 /bin/bash $DIR/build/ndk-build "$#"
C
convert your ndk-build into a cmake build

How do I fix "ld: error: unable to find library -lgcc" when cross-compiling rust to android?

I'm trying to get rust working on android. However, when I try to cross-compile to android I get the following linking error:
$ cargo build --target=arm-linux-androideabi
Compiling <project> v0.1.0 (<project>)
error: linking with `/opt/android-sdk/ndk/23.0.7599858/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi31-clang` failed: exit status: 1
(very long toolchain command from cargo)
ld: error: unable to find library -lgcc
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
I have installed the ndk and changed the linker in .cargo/config to the android clang linker. I also tried the standalone toolchains with the same result. The guide I used was the following: https://mozilla.github.io/firefox-browser-architecture/experiments/2017-09-21-rust-on-android.html
Cross-compilation does work when using crate-type = ["rlib"] instead of crate-type = ["cdylib"], but I need an .so file not an .rlib file.
In case it's relevant, i'm using Manjaro Linux.
UPDATE:
I found the following pull request: https://github.com/rust-lang/rust/pull/85806 After switching to ndk22 it worked. I havn't tried if the pull request fixes the issue (probably does).
Without switching to an older NDK version, I found using the workaround provided by ssrlive to work for me. Here's their comment:
Fixing build error for NDK 23 and above
find out all the 4 folders containing file libunwind.a, in my PC,
it's
C:\Users\Administrator\AppData\Local\Android\Sdk\ndk\23.1.7779620\toolchains\llvm\prebuilt\windows-x86_64\lib64\clang\12.0.8\lib\linux\x86_64\
and more. create 4 text files named libgcc.a in the same folders
with this contents
INPUT(-lunwind)
reference
link
In macOS, the paths are
~/Library/Android/sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/darwin-x86_64/lib64/clang/14.0.1/lib/linux/i386/libunwind.a
~/Library/Android/sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/darwin-x86_64/lib64/clang/14.0.1/lib/linux/arm/libunwind.a
~/Library/Android/sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/darwin-x86_64/lib64/clang/14.0.1/lib/linux/aarch64/libunwind.a
~/Library/Android/sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/darwin-x86_64/lib64/clang/14.0.1/lib/linux/x86_64/libunwind.a
In Linux, the paths are
~/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.1/lib/linux/i386/libunwind.a
~/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.1/lib/linux/aarch64/libunwind.a
~/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.1/lib/linux/x86_64/libunwind.a
~/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.1/lib/linux/arm/libunwind.a
In Windows, the paths are
~/AppData/Local/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/windows-x86_64/lib64/clang/14.0.1/lib/linux/aarch64/libunwind.a
~/AppData/Local/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/windows-x86_64/lib64/clang/14.0.1/lib/linux/arm/libunwind.a
~/AppData/Local/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/windows-x86_64/lib64/clang/14.0.1/lib/linux/i386/libunwind.a
~/AppData/Local/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/windows-x86_64/lib64/clang/14.0.1/lib/linux/x86_64/libunwind.a
create file command in Linux/macOS
cat << EOF > libgcc.a
INPUT(-lunwind)
EOF
This is of course extremely brittle and not the "right" solution, but the workaround works fine as of 2022-10-12 with ndk version 25.1.8937393.

CMake not finding Qt5 when trying to create Qt5 Project in CLion on Linux

I am getting the following CMake error:
CMake Error at CMakeLists.txt:23 (find_package):
By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5", but
CMake did not find one.
Could not find a package configuration file provided by "Qt5" with any of
the following names:
Qt5Config.cmake
qt5-config.cmake
Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
to a directory containing one of the above files. If "Qt5" provides a
separate development package or SDK, be sure it has been installed.
In my CMakeLists.txt, there is this line:
if (NOT CMAKE_PREFIX_PATH)
message(WARNING "CMAKE_PREFIX_PATH is not defined, you may need to set it "
"(-DCMAKE_PREFIX_PATH=\"path/to/Qt/lib/cmake\" or -DCMAKE_PREFIX_PATH=/usr/include/{host}/qt{version}/ on Ubuntu)")
endif ()
So I did what it says and set my PREFIX_PATH to "/usr/include/x86_64-linux-gnu/qt5/".
However, the error I get says that CMake cannot find "qt5-config.cmake", which is located at "/usr/lib/x86_64-linux-gnu/cmake/Qt5" and not "/usr/include/x86_64-linux-gnu/qt5/", so I tried setting the "Qt5_DIR" to that directory (since it says in the error to set it to a dir that contains the above files) but still without success. Any ideas why it cant find the files it needs?
edit:
my CMakeLists.txt:
cmake_minimum_required(VERSION 3.19)
project(untitled1)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_PREFIX_PATH "/usr/lib/x86_64-linux-gnu/cmake/Qt5/")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(QT_VERSION 5)
set(REQUIRED_LIBS Core Gui Widgets)
set(REQUIRED_LIBS_QUALIFIED Qt5::Core Qt5::Gui Qt5::Widgets)
add_executable(${PROJECT_NAME} main.cpp)
if (NOT CMAKE_PREFIX_PATH)
message(WARNING "CMAKE_PREFIX_PATH is not defined, you may need to set it "
"(-DCMAKE_PREFIX_PATH=\"path/to/Qt/lib/cmake\" or -DCMAKE_PREFIX_PATH=/usr/include/{host}/qt{version}/ on Ubuntu)")
endif ()
find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED)
target_link_libraries(${PROJECT_NAME} ${REQUIRED_LIBS_QUALIFIED})
note that the file has been auto-generated by CLion, all I did was change the path according to what is specified in the if-Block

Unable to build NDK project from latest Android Studio (version 2.1.2, Windows 64 bit)

I am unable to build a NDK project from the Android Studio environment but can build it manually using the command console.
I get the following error after building:
Error:Execution failed for task ':xxxxxx:compileReleaseNdk'.> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\xxxxx\AppData\Local\Android\SDK\android-sdk\ndk-bundle\ndk-build.cmd'' finished with non-zero exit value 2
I got a similar error while invoking ndk-build.cmd manually using the console from the jni directory where my NDK project is stored.However I fixed it by modifying the following in my Application.mk file as follows:
NDK_TOOLCHAIN_VERSION := 4.9
since 4.9 is the tool chain available on my install. I suspect from the Android Studio environment, the toolchain version is being picked incorrectly, and yet I do not know where to set this option in the GUI.
The build.gradle file has the following NDK block:
ndk{
moduleName "xxxxxx"
ldLibs "log"
cFlags "-std=c++11 -fexceptions"
stl "gnustl_static"
abiFilters "arm64-v8a armeabi armeabi-v7a mips mips64 x86 x86_64"
}
Please advise me on how to go about solving this problem.
Just out of curiosity, I moved my project directory to the desktop and tried to build that project. The build was successful.
Finally narrowed down the problem to the NDK compiler not being able to create the following intermediate object file inside my project folder:
C:\Users\xxxxx\GitRepos\REVIEWS\xxx\SMART-xxx\xxxx-xxx-androidnative\xxxLibraries\xxxlibrary\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/natXXXX/C_\Users\xxxxx\GitRepos\REVIEWS\xxx\SMART-xxxx\xxxx-xxx-androidnative\xxxLibraries\xxxlibrary\src\main\jni\NativeXXXX.o.d
The reason was the well known windows path cannot exceed 255 characters issue. As you can see above the NDK-Build utility tries to append a deep folder hierarchy like "C_\Users\xxxxx\GitRepos\REVIEWS\xxx\SMART-xxxx\xxxx-xxx-androidnative\xxxLibraries\xxxlibrary\src\main\jni\" which exceeds MAX_PATH.

I got following error while build Android NDK

I got following error while build Android-ndk Please help me.
Cygwin.bat
#echo off
set IS_UNIX=
set DEV_ROOT=C:/iliu-Android-NDK-Fibonacci-a546a1a
set JAVA_HOME=C:/Program Files/Java/jre6/bin
set CLASSPATH=C:/iliu-Android-NDK-Fibonacci-a546a1a/obj
set PATH=D:/new_eclipse/android-sdk-windows/android-sdk-windows/tools;D:/new_eclipse/android-sdk-windows/android-sdk-windows/android-ndk-r7
set ANDROID_NDK_ROOT=/cygdrive/d/new_eclipse/android-sdk-windows/android-sdk-windows/android-ndk-r7
set NDK_PROJECT_PATH=/cygdrive/C/iliu-Android-NDK-Fibonacci-a546a1a
C:
chdir C:/cygwin/bin
bash --login -i
**Error:**
$ ./ndk-build
Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
/cygdrive/d/new_eclipse/android-sdk-windows/android-sdk-windows/android-ndk-r7/build/core/build-local.mk:102: *** Android NDK: Aborting . Stop.
I got following error while build Android-ndk
Please help me.
You have to call ndk-build from your project directory, so in pseudocode,
cd $MyProject
$NDK/ndk-build
you should call ndk from the of your project
like that :
C:\Users\Xhunter\AndroidStudioProjects\mupdf\platform\android\viewer>C:\Users\Xhunter\Downloads\ndk\ndk\ndk-build

Resources