Android studio - ndk_build_command failing on Clean task - android

I recently checked out a project originally built under Windows (using JNI) in my Studio on Ubuntu
When I run a clean task, I see an error when it tries to execute what seems to be a Windows ndk-clean command
org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'C:UsersTishuAppDataLocalAndroidandroid-ndk-r8e-windows-x86_64android-ndk-r8endk-build.cmd
I am not sure what triggers this command but it happens on this task: 'externalNativeBuildCleanDebug'
I have searched in my project for references to 'AppData' and found few in this file: project/.externalNativeBuilds/ndkbuild/debug/mips/ndkBuild_build_commands.txt
This file contains windows related information, starting with
Executable : C:\Users\Tishu\AppData\Local\Android\android-ndk-r8e-windows-x86_64\android-ndk-r8e\ndk-build.cmd
Problem is I cannot find this file in Files or in Studio. The .externalNativeBuilds folder doesn't show. I have this is my build.gradle
externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}
And the Android.mk file contains only
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_ALLOW_UNDEFINED_SYMBOLS=false
LOCAL_MODULE := jpgexif
LOCAL_SRC_FILES := JpgExif.c
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
include $(BUILD_SHARED_LIBRARY)
How do I disable this step, or update it to be relevant for my platform?

It sounds to me like either of these things have happened:
Someone checked the .externalNativeBuild directory into the repo, which they shouldn't have done. The build tools should generate that directory for you locally. If you can't see the directory in the file explorer, press Ctrl+H, or whatever the command is to show hidden files. Then delete the directory and trigger a gradle sync. Or just remove it from a terminal window.
Someone checked the local.properties file into the repo, and in it they set the ndk.dir property to a Windows path. Again, this file should probably not be part of your shared repository. If this is what happened you might be able to fix it by editing the file and specifying the correct NDK path for your machine, and then triggering a gradle sync.

Related

Issue while integrating car-ui-lib

i want to integrate car-ui-lib into my project. i manually create Android.mk in (src/main/jni) file from this google git
After i build my project the android studio create cpp folder and add my Android.mk file there by using this piece of code in build.gradle module.
sourceSets { main {
res.srcDirs = ['src/main/res']
} }
externalNativeBuild {
ndkBuild {
path "src/main/jni/Android.mk"
}
}
useLibrary 'android.car'
Now the issue is, the car-ui components still not show, i try these imports:
import com.android.car.ui.toolbar.TabLayout;
import com.android.car.ui.core.CarUi;
but still it says "Cannot resolve symbol ui"
I also try below Android.mk code but the issue remains the same.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
CAR_UI_RRO_SET_NAME := oem
LOCAL_MODULE := car-ui
CAR_UI_RESOURCE_DIR := $(LOCAL_PATH)/res
CAR_UI_RRO_TARGETS := $(CAR_UI_RRO_PACKAGE_NAMES)
CAR_UI_GENERATE_RRO_SET := $(call my-dir)/generate_rros.mk
LOCAL_STATIC_ANDROID_LIBRARIES := car-ui-lib
include $(BUILD_STATIC_LIBRARY)
I also tried their official documentation but still nothing works.
Any tutorial/help would be appreciated :)
Android.mk/Android.bp are makefiles of AOSP build system, they are not compatible with Android Studio (or Gradle). With the former you build Android OS and system apps, with the latter you build regular apps.
What you need to do is to create a new folder in AOSP tree and build it from here. You can start by copying that paintbooth test app (don't forget to change package name). Then you can build the app through "make YourPackageName" and push to your device with "adb root && adb remount && adb sync". Please note this requires building and flashing your entire own system image first (doing and flashing a full AAOS build).
While this line useLibrary 'android.car' in your Gradle config will allow you to use the car-ui-lib, there are still many apis that aren't available in the public version. The car-ui-lib is still under hard development I believe, so if you really need to use code from your Android Studio project, you will need to use the car-ui-lib jar that you can find when you build the AAOS. You can find it under this path:
out/target/common/obj/JAVA_LIBRARIES/android.car_intermediates/classes.jar
If you move your project from Android Studio to the platform, then you will be able to use those apis, given that you have the right configuration in your makefile: LOCAL_STATIC_ANDROID_LIBRARIES := car-ui-lib.

Android Studio ndk example build errors

I am new to using an ndk and was trying to use some of the sample projects that came in the android ndk10d folder. For example the hello-jni sample project. I keep getting this error:
Error:Execution failed for task ':app:compileDebugNdk'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\Jonathon\android-ndk-r10d\ndk-build.cmd NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\Jonathon\AndroidStudioProjects\hello-jni2\app\build\intermediates\ndk\debug\Android.mk APP_PLATFORM=android-21 NDK_OUT=C:\Users\Jonathon\AndroidStudioProjects\hello-jni2\app\build\intermediates\ndk\debug\obj NDK_LIBS_OUT=C:\Users\Jonathon\AndroidStudioProjects\hello-jni2\app\build\intermediates\ndk\debug\lib APP_ABI=all
Error Code: 2 Output:
make.exe: *** No rule to make target `C:\Users\Jonathon\AndroidStudioProjects\hello-jni2\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/hello-jni/C_\Users\Jonathon\AndroidStudioProjects\hello-jni2\app\src\main\jni', needed by `C:\Users\Jonathon\AndroidStudioProjects\hello-jni2\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/hello-jni/C_\Users\Jonathon\AndroidStudioProjects\hello-jni2\app\src\main\jni\hello-jni.o'. Stop.
I have checked and the file: ndk-build.cmd is indeed in the location specified. When I try to open it command prompt says that it cannot find the application project directory. Please define the NDK_PROJECT_PATH variable to it
I re-installed and updated my whole environment from 0.8.9 to android studio 0.9.9 and now 1.01 and I get the same error. It seems it can't find the file or file directory and that must mean my configuration isn't right but I can't determine what to do to fix it.
local.properties
sdk.dir=C\:\\Users\\Jonathon\\AppData\\Local\\Android\\sdk
ndk.dir=C\:\\Users\\Jonathon\\android-ndk-r10d
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_SHARED_LIBRARY)
Check out this video for building simple NDK projects with Android studio
https://www.youtube.com/watch?v=kFtxo7rr2HQ&list=UUkbLy9aj5IBXfS6WqLy5Qmw
Alternatively you can also download Intel Native Developer Experience tool that comes with the NDK plugin for Android Studio
You can remove the Android.mk file: it will be ignored as a new one is generated on the fly from your gradle configuration (build.gradle file). You can get more information on this from my article on NDK support in Android Studio.
The bug you're experiencing is this one: https://code.google.com/p/android/issues/detail?id=66937&
A simple workaround is to create a empty .c file next to hello-jni.c.
If you have only one .c (or .cpp) file add a dummy .c (or .cpp) file and it works.

Android NDK Include Path In Eclipse

I have an Android NDK project that builds fine in cygwin using ndk-build.
However, I wanted to have it build in eclipse, so I installed C/C++ Development tools into my ADT version of eclipse and added native support to the project in eclipse. However, after building, I get the following error:
fatal error: timer.h: No such file or directory
In my original Android.mk file, I have the following include that lets it work in cygwin:
LOCAL_C_INCLUDES := /cygdrive/c/ADT/includes/
I tried adding a similar include path (C:\ADT\includes) to Project->Properties->C/C++ General->Paths and Symbols, but still no luck. Any suggestions?
The fix was to use windows paths
LOCAL_C_INCLUDES := C:/ADT/includes/
Note that using the following works as well (per cpu2's answer)
LOCAL_CFLAGS := -IC:/ADT/includes/
Add -I/path/to/includes to your cflags.

Android NDK Build error in Cygwin

I am configuring NDK for an android app which makes use of the linux/input.h file in its header - #include . The issue is when I call ndk-build, it gives an error which basically implies that it cannot find linux/input.h. Now, cygwin does not contain the linux directory, which is probably why this error is occuring but the ndk does contain it - android-ndk-r8e\platforms\android-14\arch-x86\usr\include\linux\input.h - shouldn't ndk-build search here as well? To give some more context, I am trying to compile the EventInjector library described here and others seem to have it working, which means it must be possible somehow.
Please follow these instructions:
in Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
TARGET_PLATFORM := android-8
LOCAL_MODULE := your_lib
LOCAL_SRC_FILES := my_file.c
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
include $(BUILD_SHARED_LIBRARY)</li>
your_lib will be the name of your library, you may write any name
my_file.c will be your source file name that is present in JNI folder
Right click on project
Choose Properties>Builders
Click on New...
Select Program, then Ok
In main tab:
Give your Builder a suitable name, eg. "NDK"
For Location, click on Browse file system>select your ndk-build.cmd,
eg. C:\android-ndk-r8-windows\android-ndk-r8\ndk-build.cmd (My NDK path)
Below there will be Working Directory:
Click on: Browse workspace - choose your project,
eg. ${workspace_loc:/Test} (My project 'Test')
Click on **Refresh Tab**
Select **Specific Resources** radio button
Click on **Specify Resources..**
Select libs folder from your project
Now click on **Build Options** Tab
Check:
After a Clean
During manual builds
During auto builds
Specify working set of relevant resources
Click on **Specify Resources...**
Select JNI folder of your project
Click Apply...Ok
Now clean it and build...then refresh
You will get your_lib.so in libs>armeabi
libs>armeabi>your_lib.so this structure will create automatically ....

Trying to build Cyanogenmod 7 - can't find wifi.h

I try to build Cyanogenmod 7 (Android 2.3.7) for my ZTE Tureis.
The build stops at
frameworks/base/core/jni/android_net_wifi_Wifi.cpp:26:18: error: wifi.h: No such file or directory
When I open up the cpp file and change
<include "wifi.h">
to
<#include "../../../hardware/libhardware_legacy/include/hardware_legacy/wifi.h">
the build passes this one but it complains later on about missing headers in other files again.
Any ideas here? I already made a new repo sync, all files should be in place.
Copy paste this line in Android.mk file where you are trying to include "wifi.h"
LOCAL_C_INCLUDES += $(call include-path-for, libhardware_legacy)/hardware_legacy

Categories

Resources