Pointing Android Studio to specific cmake version - android-studio

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)

Related

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.

Some gradle issue after updating Android Studio to v2.0

I have updated Android Studio, and when opening a project done in the 1.5 version this is the error I am getting:
Error:Failed to open zip file. Gradle's dependency cache may be
corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires
network)
The following is my dependencies:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:support-v4:23.2.0'
}
I faced the same issue when I updated my android studio to 2.2.3 from 2.1.
After a while of struggling, went project->right click -> open module settings->project
1) Gradle : 2.14.1
2) Android plugin version : 2.2.3
3) Android plugin repository : jcenter
4) Default library repository : jcenter

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.

NDK includes and the Android Gradle plugin version 0.7.+

Version 0.7.+'s of the gradle plugin includes preliminary ndk support. I worked off the examples but I get a compilation error when trying to include a standard NDK header:
In file included from /foo/src/main/jni/Bar.h:4:0,
from /foo/src/main/jni/Bar.cpp:1:
/foo/src/main/jni/baz.h:4:25: fatal error: android/log.h: No such file or directory
compilation terminated.
Where baz.h has this line:
#include <android/log.h>
And my gradle file has:
ndk {
ldLibs "log"
}
Has anyone made this work?
shouldn't it be ldLibs "-llog" ?
P.S.
NDK support is very unstable now... I was fighting with it for a few days - it completely broken on Windows. No easy way to disable it (but still possible). On some circumstances build process will generate wrong file path (like /foo/bar//foo/bar/source.c). So we switched back to the 0.6.+ version and monitoring https://code.google.com/p/android/issues/list?q=tools%40android.com

Resources