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

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

Related

Android studio - ndk_build_command failing on Clean task

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.

AOSP Native Code Linking Error

I've created an Application that works perfectly in Android Studio. If I generate an AAR and APK and use these files they again work fine. I can install the APK on several devices and it works flawlessly. Now when I install the APK inside of an AOSP build I keep getting an java.lang.UnsatisfiedLinkError: which points to the very first line of code that's calling my native method. I used this link as a reference Add .apk files in aosp. When I run the emulator and click my application it crashes and produces that UnsatisfiedLinkError. The same thing happens if I generate an APK using my AAR file. Just to clarify again this only happens in AOSP it does not happen when using the AAR inside Android Studio doing other builds and the APK always works regardless of the device I install it on. Any advice as to why this is happening would be great!
which points to the very first line of code that's calling my native method.
Sounds like you are building your application with native libraries included and the .APK you created has only bundled some architecture types into it. If you have native libraries, make sure to include all architecture types (usually x86 and armv7 does the job, but always consult your compatibility checklist first) and make sure if you do ABI splitting that you are using the right APK.
Please consule the following guide to make sure you have the NDK integration set up correctly.
AOSP was trying to find the .so that my APK uses from either the system/lib or vendor/lib folders and since it wasn't there it was causing the UnsatisfiedLinkError. So by adding the .so object file directory to those locations the APK started up fine inside the emulator after that. This could also be accomplished by modifying the Android.mk as well by adding these lines to the file.
include $(CLEAR_VARS)
LOCAL_MODULE := myfile
LOCAL_SRC_FILES := lib/myfile.so # or wherever your .so is located
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SUFFIX := .so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
include $(BUILD_PREBUILT)

Hello-Jni on Windows, Android NDK - build-local.mk: No such file

I have tried scouring the Internet and StackOverflow (too many articles to count) but cannot find assistance that is all of these things:
More recent than 2013
Does not require Cygwin if developing
on Windows
Is geared to Android Studio, NOT Eclipse.
I am diving head first into Android development for the very first time and the project I have newly joined depends on developing with the NDK. I've been reading the docs that come with the NDK but have run into a stone wall with this sample.
I am trying to build hello-jni, the sample project within the NDK. Here is my environment:
Android Studio 1.4 (most up to date, stable version currently available)
NDK version: r10e
OS: Windows 7
Contents of Application.mk file:
APP_ABI := all64 // Came with 'all', read somewhere on SO that it
// should be 'all64'. Result is the same.
Contents of Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_SHARED_LIBRARY)
My PATH environment variable includes a path to my NDK root folder and to \prebuilt\windows-x86_64\bin (because I read on one of many articles that it should.) When I navigate to the hello-jni root folder though, and call ndk-build, I am only presented with errors.
c:\NDK\android-ndk-r10e\build\core\build-local.mk:40: c:/NDK/android-ndk-r10e/build/core/build/core/init.mk: No such file or directory
c:\NDK\android-ndk-r10e\build\core\build-local.mk:191: \add-application.mk: No such file or directory
c:\NDK\android-ndk-r10e\build\core\build-local.mk:206: \setup-imports.mk: No such file or directory
c:\NDK\android-ndk-r10e\build\core\build-local.mk:223: \build-all.mk: No such file or directory
make.exe: *** No rule to make target `\build-all.mk'. Stop.
If anything else is required for people to assist me, say the word I will provide what I can. All help will be greatly appreciated.
EDIT:
Most of the articles of I've seen for Windows mention Cygwin, but according to the docs, it isn't needed. If this is incorrect, please correct me?
Except from \android-ndk-r10e\docs\Programmers_Guide\html\md_3__key__topics__building__s_t_a_n_d_a_l_o_n_e-_t_o_o_l_c_h_a_i_n.html
Windows support
The Windows binaries do not depend on Cygwin. The good news is that they are thus faster, the bad news is that they do not understand the Cygwin path specification like /cygdrive/c/foo/bar (instead of C:/foo/bar).
The NDK build system ensures that all paths passed to the compiler from Cygwin are automatically translated, and deals with other horrors for you. If you have a custom build system, you may need to deal with the problem yourself.
I can't take the credit for this answer, a coworker kindly sleuthed it out for me. When he found the answer, I demanded to know what else he had done, because clearly I must have missed some magic? I only saw him switch two lines in a make file, there had to be more? Alas, no. This alone was the source of my woe.
While I'm hesitant to call it an error within the NDK because I don't know how it works with Cygwin, neither of us can understand how this has ever worked for anyone building in native Windows, as the line I will be referencing is recorded in the git repository as being added back in 2011 or 2010. ( https://android.googlesource.com/platform/ndk/+/master/build/core/build-local.mk )
To aid explanation, here is the first line of my error again:
c:\NDK\android-ndk-r10e\build\core\build-local.mk:40: c:/NDK/android-ndk-r10e/build/core/build/core/init.mk: No such file or directory
The first file that is unable to found is ...build/core/build/core/init.mk, which of course doesn't exist because build/core should not be repeated.
The command that begins the build, ndk-build.cmd, calls build\core\build-local.mk to begin the process. Inside this file the environment variable, NDK_ROOT, is recreated upon entry. Whatever my NDK_ROOT is, is irrelevant.
NDK_ROOT := $(dir $(lastword $(MAKEFILE_LIST)))
NDK_ROOT := $(strip $(NDK_ROOT:%build/core/=%))
NDK_ROOT := $(subst \,/,$(NDK_ROOT))
NDK_ROOT := $(NDK_ROOT:%/=%)
.
.
.
The second line strips the end of the current directory (the build/core/) from the end of my new NDK_ROOT, because the true root should be the parent directory of build and because it will be added back later to find all those 'missing' files. That's fine, except note the forward-slashes (/) used in the search. Windows does not use (or in my experience at least, usually does not return) forward-slashes, though it will often parse them if that is what it's given. (When changing directories, for example, I've found either to be acceptable as long as I already know where I need to go. Tab completion does not seem to function if my path ends with a /.)
Oh, but look at the third line (added way back in 2011)! A substitution is made of every backslash (\) in NDK_ROOT, replaced with forward-slash (/). So the replacement of build/core/ should go off without a hitch, right? Problem: it's too late.
The strip call has already occurred and if the NDK_ROOT received a path with backslashes instead of forward-slashes, build/core/ is never found and stripped from the variable. How did my coworker fix it? Easy. He switched the lines around:
NDK_ROOT := $(dir $(lastword $(MAKEFILE_LIST)))
NDK_ROOT := $(subst \,/,$(NDK_ROOT))
NDK_ROOT := $(strip $(NDK_ROOT:%build/core/=%))
NDK_ROOT := $(NDK_ROOT:%/=%)
My hello-jni project now builds, along with Teapot, another sample from the NDK, which I tried just to be sure. And so does native-audio, native-codec, native-media, and More Teapots. Haven't tried to run them yet... but I have no build errors.
I don't know if this fix will break Cygwin users, I don't have that on my box. I also don't know if it would break Linux environments because I don't have Linux on my box. But this may help native Windows users, and I hope so, because I uselessly beat my head on this for 3 or 4 days and read more SO articles than I ever care to at once.
Using a windows machine I encountered this error but it was saying the clear-vars.mk : No such file or directory. After I looked at the ndk-build.cmd in the directory
C:\Users\\AppData\Local\Android\Sdk\ndk-bundle\build
the file looks like this
#echo off
set NDK_ROOT=%~dp0\..
set PREBUILT_PATH=%NDK_ROOT%\prebuilt\windows-x86_64
if exist %PREBUILT_PATH% goto FOUND
set PREBUILT_PATH=%NDK_ROOT%\prebuilt\windows
:FOUND
"%PREBUILT_PATH%\bin\make.exe" -f "%NDK_ROOT%\build\core\build-local.mk" SHELL=cmd %*
But you will also find the same file name under directory
C:\Users\jmatthews\AppData\Local\Android\Sdk\ndk-bundle
and the file looks like this
#echo off
%~dp0\build\ndk-build.cmd %*
remove the second line so it looks like this with only 1 line echo off
#echo off
This file is called and messes up the Windows directory structure. After that I was able to compile on windows. Also I had issues with the project using a space in the directory so move your project location to directories without spaces.

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.

Categories

Resources