React native android build fails with NDK error [duplicate] - android-ndk

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.

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)

NDK cutils and c missing

I am trying to build an executable with NDK. However I am getting the following error:
Tools/android-ndk-r14b/build/core/build-binary.mk:687: Android NDK: Module ABCD depends on undefined modules: cutils c
Tools/android-ndk-r14b/build/core/build-binary.mk:700: *** Android NDK: Aborting (set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies) . Stop.
How can I fix it?
Just remove cutils and c from LOCAL_SHARED_LIBRARIES and LOCAL_STATIC_LIBRARIES. That's always been a no-op in your build file: https://github.com/android-ndk/ndk/issues/208

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.

Android Studio Build not working after migration from Eclipse

I'm migrating my Android project from Eclipse to Android Studio. The original project relied on two apache libraries: commons-io-2.4.jar and commons-codec-1.9.jar.
I've copied these jar files to the proper libs directory and updated build.gradle to reflect this:
dependencies {
compile project(':aviarySDK')
compile project(':showcaseView')
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.google.android.gms:play-services:+'
compile files('libs/commons-cli-1.2.jar')
compile files('libs/httpclient-4.3.1.jar')
compile files('libs/httpcore-4.3.jar')
compile files('libs/httpmime-4.3.1.jar')
compile files('libs/metadata-extractor-2.6.4.jar')
compile files('libs/tape-1.1.0.jar')
compile files('libs/commons-codec-1.9.jar')
compile files('libs/commons-io-2.4.jar')
}
When I try to build the project a I get a duplication error message:
Error:duplicate files during packaging of APK /Users/gkipnis/repos/floomitandroidclient/floomItNewCamera/build/outputs/apk/floomItNewCamera-debug-unaligned.apk
Path in archive: META-INF/LICENSE.txt
Origin 1: /Users/gkipnis/repos/floomitandroidclient/floomItNewCamera/libs/commons-io-2.4.jar
Origin 2: /Users/gkipnis/repos/floomitandroidclient/floomItNewCamera/libs/commons-codec-1.9.jar
You can ignore those files in your build.gradle:
android {
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}
}
Error:Execution failed for task ':floomItNewCamera:packageDebug'.
> Duplicate files copied in APK META-INF/LICENSE.txt
File 1: /Users/gkipnis/repos/floomitandroidclient/floomItNewCamera/libs/commons-io-2.4.jar
File 2: /Users/gkipnis/repos/floomitandroidclient/floomItNewCamera/libs/commons-io-2.4.jar
Information:BUILD FAILED
Information:Total time: 3.144 secs
Can someone provide any pointers to what might be going on.
Thank You,
Gary Kipnis
As suggested by the error message add this part to your build.gradle
android {
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}
}

Android error: package android.os does not exist

I have imported a project to Android Studio using Gradle. Import process was successful, but it gives an error for android.os.*, when I try to import it.
It is a libGDX project.
I suggest to use AGP Upgrade assistent.
I often have probs upgrading gradle. This time with artic fox and java 11 it I got all those infamous android.* not found errors.
Then I discovered that neat AGP Upgrade assistent (in tools since Studio 4.2) - and it did what it should and everything is now using gradle 7 and compiles again.
About time such a tool was introduced - and I just saw about half a year too late ;)
Recently, I met a similar case in Android Studio 3.2.1 Ubuntu/Linux version.
I am quite sure about the issue shall be related to the Android SDK installation,because I build the same project in Android Studio of my Windows 10 laptop.
Issue:
Java compiler error at Android studio
error: package android.os does not exist
error: package android.media does not exist
error: package android.content does not exist
error: package android.util does not exist
error: cannot find symbol variable Log
error: cannot find symbol class Context
error: cannot find symbol class AudioRecord
Solution:
The android.jar which was mentioned at the build.gradle file was not installed at the /sdk/platforms/ directory. See the android.jar dependency at my build.gradle file below(which caused the issue),
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files(sdkDir+'/platforms/android-24/android.jar')
}
Install the correct android platform(correct API level as mentioned in the build.gradle file,if any) and rebuild the project.
I am building from an old article, https://medium.com/#authmane512/how-to-build-an-apk-from-command-line-without-ide-7260e1e22676, and it doesn't yet have a build.gradle file, but I had the same error. I solved it by changing the compile command in my Makefile to:
classes: $(SOURCES)
javac -d obj \
-source 1.6 \
-target 1.8 \
-classpath src \
-bootclasspath $(ANDROID) \
$+
where ANDROID is /usr/local/src/android/adt-bundle-linux-x86_64-20130717/sdk/platforms/android-19/android.jar.
I get warnings now that source value 6 is obsolete, but at least it compiles.
In my case it was showing same kind of error with android.content.context
I figured out that the issue is I was using old gradle version with below android params in build.gradle
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}
So I removed this and the error is no more.

Resources