NDK version conflict in buildozer for Kivy app - android-ndk

I am trying to build a kivy app that has these requirements in buildozer.spec:
requirements = python3,kivy,pillow,plyer,scipy,numpy
all Android (SDK/NDK, API) settings are defaulted (commented)
One run w/o specifying NDK gives:
[INFO]: <- directory context /home/joachim/PycharmProjects/CardReader/.buildozer/android/platform/python-for-android
[WARNING]: install_libs called with no libraries to install!
[INFO]: Building lapack for arm64-v8a
[INFO]: -> directory context /home/joachim/PycharmProjects/CardReader/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/lapack/arm64-v8a__ndk_target_21/lapack/build
[ERROR]: Build failed: Please set the environment variable 'LEGACY_NDK' to point to a NDK location with gcc/gfortran support (supported NDK version: 'r21e')
When I clean and then set NDK to 21e and run again I get the other error:
[INFO]: Will compile for the following archs: arm64-v8a, armeabi-v7a
[INFO]: Found Android API target in $ANDROIDAPI: 27
[INFO]: Available Android APIs are (27)
[INFO]: Requested API target 27 is available, continuing.
[INFO]: Found NDK dir in $ANDROIDNDK: /home/joachim/.buildozer/android/platform/android-ndk-r21e
[INFO]: Found NDK version 21e
[ERROR]: Build failed: The minimum supported NDK version is 23. You can download it from https://developer.android.com/ndk/downloads/.
[INFO]: Instructions: Please, go to the android NDK page (https://developer.android.com/ndk/downloads/) and download a supported version.
*** The currently recommended NDK version is 23b ***
How can this mismatch be solved? Looking for supported NDK with gcc/gfortran support.
Or, what needs to be set for LEGACY_NDK ?

So I've just ran into that problem and found a solution.
The issue was that to build scipy python for android needs an android ndk that was built with fortran support. These appear to be only supported with NDK version 21 and lower and the NDK needs to be specifically built with fortran support. Luckily someone hosts prebuilt versions for that purpose. https://github.com/mzakharo/android-gfortran/releases (Linux only, if you are building the APK from windows you need to build your own NDK toolchain as described in the readme of that project)
Then you have to do the following:
First you need to download the legacy NDK via buildozer
For this modifiy in buildozer.spec:
#android.ndk = 23b --> android.ndk = 21e
Then Execute
buildozer android debug
When it fails (this is ok since we only ran buildozer to download the r21 NDK):
tar -jxvf gcc-arm-linux-x86_64.tar.bz2
mv arm-linux-androideabi-4.9 ~/.buildozer/android/platform/android-ndk-r21e/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
Note: change ~/.buildozer to the path where buildozer stores your ndks
Then revert the changes to buildozer.spec:
android.ndk = 21e --> #android.ndk = 23b
Now you can build and deploy with
export LEGACY_NDK=~/.buildozer/android/platform/android-ndk-r21e
buildozer android debug deploy run
Note: change ~/.buildozer as described above

Related

Pointing Android Studio to specific cmake version

I use Android Studio 4.0.1
In my project, my local.properties has the following properties:
sdk.dir=C\:\\Users\\xxx\\AppData\\Local\\Android\\Sdk
ndk.dir=c\:\\yyy\\tools\\android-ndk-r19c
cmake.dir=c\:\\zzz\\cmake-3.17.0-win64-x64
Despite this, I get a compilation error when I Build -> Rebuild project or Clean project because my CMakeLists.txt begins with cmake_minimum_required(VERSION 3.14.3) and Android Studio uses the CMake included in the Android Studio folder instead of the one I point to in cmake.dir:
CMake Error at CMakeLists.txt:5 (cmake_minimum_required):
CMake 3.14.3 or higher is required. You are running version 3.10.2
-- Configuring incomplete, errors occurred!
See also "C:/Users/xxx/AndroidStudioProjects/E2e/app/.cxx/cmake/debug/x86/CMakeFiles/CMakeOutput.log".
FAILED: build.ninja
ninja: error: rebuilding 'build.ninja': subcommand failed
C:\Users\xxx\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\cmake.exe -HC:\Users\xxx\AndroidStudioProjects\E2e\app\src\main\cpp -BC:\Users\xxx\AndroidStudioProjects\E2e\app\.cxx\cmake\debug\x86
What am I missing for AS to pick up the cmake 3.17 I already installed when I select Rebuild Project or Clean Project?
Notes:
The directory I point to with cmake.dir is valid and being read by AS. If I introduce a typo in the path, AS complains about it.
This problem only occurs when I do Build --> Rebuild project or Clean project. If instead I do Build --> Make project, then AS will pick up the cmake version that I point to in local.properties
Clean Project worked again after deleting .cxx folder
I'm not sure about Android Studio, but you could try editing the project's build.gradle :
android {
externalNativeBuild {
cmake {
path file('CMakeLists.txt')
version '3.24.1'
}
}
}
.... and CMakeLists.txt :
cmake_minimum_required(VERSION 3.24.1)

How to fix: "ABI filter 'arm64-v8a' is no longer supported in NDK version x"

I'm setting up an android project from another company which involves selfmade C++ cross platform libraries. For an older version of these libraries an complete app project was made in java with a jni interface to access these libraries, which are stored as their own modules with gradle.build files. The goal is to get the app compiling for arm64-v8a architecture because of the Google requirements for app update.
The project is set up with:
gradle experimental plugin 0.11.0
gradle plugin 4.1
boost 1.64.0 for armeabi-v7a (got arm64-v8a precompiled libraries as replacement)
opencv 2.4.13.2
ndk r15c
I checked all dependencies for getting a arm64 pendant, which was only needed for the boost dependencies.
I tried changing the ABI list which is used for every project to include all architectures or all seperatly. I tried using other ndk versions. What might help but i didn't accomplish was changing the experimental gradle plugin to the normal plugin but i couldn't get that right.
I expected some compiling or linking errors but it only tells me "ABI filter 'arm64-v8a' is no longer supported in NDK version r15.2.4203891.". If i try other architectures i get the same error, but instead of the 'arm64-v8a' the current selected architecture. If i give an invalid architecture it changes to "Target ABI 'hello' is not supported.", so it recognizes the architecture i think.
Stacktrace of first error:
A problem occurred configuring project ':app'.
Exception thrown while executing model rule: NdkComponentModelPlugin.Rules#configureNativeLibrary(ModelMap, NdkConfig, NdkHandler, ModelMap, File, ServiceRegistry) > create(livestage) > withType()
Exception thrown while executing model rule: NdkComponentModelPlugin.Rules#configureNativeLibrary(ModelMap, NdkConfig, NdkHandler, ModelMap, File, ServiceRegistry) > create(lib-jni-cxx) > withType()
Exception thrown while executing model rule: NdkComponentModelPlugin.Rules#configureNativeBinary(BinaryContainer, ModelMap, NdkConfig, NdkHandler) > withType()
ABI filter 'arm64-v8a' is no longer supported in NDK version r15.2.4203891.
The experimental plugin hasn't been supported for years, so it's no surprise that it doesn't work. Migrate to externalNativeBuild: https://developer.android.com/studio/projects/add-native-code

How do you fix "Build failed: Android SDK dir was not specified, exiting."

I am trying to build a kivy apk and I keep getting this error, " Build failed: Android SDK dir was not specified, exiting.". What do I need to do to fix it?
and when i run:
python3 -m pythonforandroid.toolchain create --dist_name=simpleapp --bootstrap=sdl2 --requirements=python3,kivy,android --arch armeabi-v7a --copy-libs --color=always --storage-dir="/home/haryo/kivy-game-2.0/.buildozer/android/platform/build" --ndk-api=21
i get:
[INFO]: Will compile for the following archs: armeabi-v7a
[ERROR]: Build failed: Android SDK dir was not specified, exiting.
You need to...specify the sdk dir. Use the --sdk-dir=... argument to pass the path to the Android SDK.
You'll also need to do the same for the NDK.

React native android build fails with NDK error [duplicate]

Can someone explain why I get this errors please?
Build command failed.
Error while executing process C:\Users\Kevin\Desktop\Android\Sdk\ndk-bundle\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\Kevin\Desktop\Mygame\proj.android-studio\app\jni\Android.mk NDK_APPLICATION_MK=C:\Users\Kevin\Desktop\Mygame\proj.android-studio\app\jni\Application.mk APP_ABI=armeabi NDK_ALL_ABIS=armeabi NDK_DEBUG=1 APP_PLATFORM=android-14 NDK_OUT=C:/Users/Kevin/Desktop/Mygame/proj.android-studio/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=C:\Users\Kevin\Desktop\Mygame\proj.android-studio\app\build\intermediates\ndkBuild\debug\lib NDK_TOOLCHAIN_VERSION=4.9 APP_PLATFORM=android-10 NDK_MODULE_PATH=C:/Users/Kevin/Desktop/Mygame/cocos2d;C:/Users/Kevin/Desktop/Mygame/cocos2d/cocos;C:/Users/Kevin/Desktop/Mygame/cocos2d/external -j4 NDK_DEBUG=1 APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}
Android NDK: INTERNAL ERROR: The armeabi ABI should have exactly one `architecture definitions. Found: ''`
process_begin: CreateProcess(NULL, "", ...) failed.
*** Android NDK: Aborting... . Stop.
Build command failed.
Error while executing process C:\Users\Kevin\Desktop\Android\Sdk\ndk-bundle\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\Kevin\Desktop\Mygame\proj.android-studio\app\jni\Android.mk NDK_APPLICATION_MK=C:\Users\Kevin\Desktop\Mygame\proj.android-studio\app\jni\Application.mk APP_ABI=armeabi NDK_ALL_ABIS=armeabi NDK_DEBUG=0 APP_PLATFORM=android-14 NDK_OUT=C:/Users/Kevin/Desktop/Mygame/proj.android-studio/app/build/intermediates/ndkBuild/release/obj NDK_LIBS_OUT=C:\Users\Kevin\Desktop\Mygame\proj.android-studio\app\build\intermediates\ndkBuild\release\lib NDK_TOOLCHAIN_VERSION=4.9 APP_PLATFORM=android-10 NDK_MODULE_PATH=C:/Users/Kevin/Desktop/Mygame/cocos2d;C:/Users/Kevin/Desktop/Mygame/cocos2d/cocos;C:/Users/Kevin/Desktop/Mygame/cocos2d/external -j4 NDK_DEBUG=0 APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}
Android NDK: INTERNAL ERROR: The armeabi ABI should have exactly one architecture definitions. Found: ''
process_begin: CreateProcess(NULL, "", ...) failed.
*** Android NDK: Aborting... . Stop.
I leave here a screenshot of my android studio if can be helpful
Most likely, you have NDK r17 installed, which does not support armeabi anymore. Your gradle plugin is not aware of this recent change. You must upgrade: in build.gradle, you should have
buildscript { dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
} }
and in gradle/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
But even after upgrade, your build.gradle most likely lacks the abiFilters statement, and therefore your project build is slower and APK larger than necessary.
You probably only need on ABI in your APK,
android { defaultConfig { ndk {
abiFilters 'armeabi-v7a'
} } }
I got this error recently - the cause was a mystery and still is. I reinstalled everything, but I could not get my project to Clean.
In the end I manually deleted the app/build and app/.externalNativeBuild folders, and the project rebuilt fine, and I was then able to run Clean without errors again.

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.

Resources