Android 5.1.1 - Build run-as binary - android

I'm trying to build a from android lollipop source the run-as binary.
I have download run-as package here : https://android.googlesource.com/platform/system/core/+archive/android-cts-5.1_r28/run-as.tar.gz
Well, here is the Android.mk code :
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := run-as.c package.c
LOCAL_SHARED_LIBRARIES := libselinux
LOCAL_MODULE := run-as
LOCAL_CFLAGS := -Werror
include $(BUILD_EXECUTABLE)
When I try to build, I receive this error :
Android NDK: Module run-as depends on undefined modules: selinux
*** Android NDK: Aborting (set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies)
So I add this line to my android.mk file
APP_ALLOW_MISSING_DEPS=true
Then, I download headers files from here (android_filesystem_config.h) and from here (android.h) to include proper headers files needed for run-as.c
But when I tried to build again, I have this error:
./run-as.c:158: error: undefined reference to 'selinux_android_setcontext'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
I guess I miss something on the build process...
An help would be appreciate.
Thanks

Related

"Failed to retrieve application ABI from Android.mk" error in ndk-gdb

I'm trying to debug a native android app using ndk-gdb tool. When I execute the ndk-gdb, I get the following error.
"/home/amila/Android/Ndk/android-ndk-r20/build/core/add-application.mk:88:
*** Android NDK: Aborting... . Stop. ERROR: Failed to retrieve application ABI from Android.mk."
I have built the native parts using ndk-build command and the app is getting built in Android Studio without any issue.
jni directory: /ndktest/jni (where ndktest is the app name)
I ran the ndk-gdb command in the directory where the AndroidManifest.xml resides (/ndktest/app/src/main).
I also tried by adding APP_ABI := arm64-v8a into the Android.mk and nothing changed.
jni/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ndktest
LOCAL_SRC_FILES := ndktest.cpp
include $(BUILD_SHARED_LIBRARY)
jni/Application.mk
APP_ABI := arm64-v8a
There should be no errors when I run the ndk-gdb tool.
Note that ndk-gdb does not take your gradle configuration into consideration, so if you have a modified file structure, make sure that your Android.mk file is located inside a "jni" folder inside the project directory.

android NDK ndk-build error

I'm new to Android studio and android NDK. I'm trying to compile a simple hello.c program with android NDK for a class assignment. I've followed the following project instructions but get an error:
Create a c program
create Android.mk with following contents:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello.out
LOCAL_SRC_FILES :=hello.c
include $(BUILD_EXECUTABLE)
Create Application.mk with following content:
APP_ABI := armeabi
APP_PLATFORM := android-10
APP_STL := stlport_static
APP_BUILD_SCRITP := Android.mk
Put hello.c, Android.mk, Application.mk into same folder x.
go to folder x
run command:
export NDK_PROJECT_PATH=.
Run command
[NDK_dir]/ndk-build NDK_APPLICATION_MK=./Application.mk
the executable will be generated at ./libs/armeabi/hello.out
But I get this error when following those instructions:
/home/justin/Desktop/android-ndk-r16/build/core/add-application.mk:49: Application.mk: No such file or directory
Android NDK: APP_PLATFORM not set. Defaulting to minimum supported version android-14.
Android NDK: There is no Android.mk under ./jni
Android NDK: If this is intentional please define APP_BUILD_SCRIPT to point
Android NDK: to a valid NDK build script.
/home/justin/Desktop/android-ndk-r16/build/core/add-application.mk:116: *** Android NDK: Aborting... . Stop.
I installed android NDK components through Andoird studio SDK and my [NDK_DiR] is /home/justin/Android/Sdk/ndk-bundle
The easy fix is to move all three files to a subdirectory called jni. You don't need to export NDK_PROJECT_PATH, and your command will look like
<path-to/>ndk-build -C <path-to/>x/jni
If you need to avoid jni directory at any price, try
<path-to/>ndk-build NDK_PROJECT_PATH=<path-to/>x NDK_APPLICATION_MK=<path-to/>x/Application.mk APP_BUILD_SCRIPT=<path-to/>x/Android.mk
which is almost equivalent to
<path-to/>ndk-build -C <path-to/>x NDK_PROJECT_PATH=. NDK_APPLICATION_MK=Application.mk APP_BUILD_SCRIPT=Android.mk

How to resolve "Relocations in Generic ELF" during ndk-build?

I'm trying to build a static library using a standalone toolchain for a project that has its own build process, which I then wrap with a C++ library and expose to Android (compiled with ndk-build). However, on the ndk-build step I receive the following error:
➜ jni /Users/chrisfosterelli/Library/Android/sdk/ndk-bundle/ndk-build
[arm64-v8a] Compile++ : wrapper <= wrapper.cpp
In file included from /Users/chrisfosterelli/workspace/android/jni/wrapper.cpp:9:
In file included from ../prebuild/include/valhalla/meili/universal_cost.h:7:
In file included from ../prebuild/include/valhalla/sif/dynamiccost.h:4:
In file included from ../prebuild/include/valhalla/baldr/directededge.h:5:
../prebuild/include/valhalla/baldr/graphconstants.h:432:11: warning: 21 enumeration values not handled in switch: 'kRoad', 'kRamp', 'kTurnChannel'... [-Wswitch]
switch (use) {
^
1 warning generated.
[arm64-v8a] SharedLibrary : libwrapper.so
/Users/chrisfosterelli/Library/Android/sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: /Users/chrisfosterelli/workspace/android/jni/../prebuild/libvalhalla_meili.a(libvalhalla_meili_la-map_matcher_factory.o): Relocations in generic ELF (EM: 62)
[...above message repeated many times...]
/Users/chrisfosterelli/workspace/android/jni/../prebuild/libvalhalla_meili.a: error adding symbols: File in wrong format
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/Users/chrisfosterelli/workspace/android/obj/local/arm64-v8a/libwrapper.so] Error 1
➜ jni ls /Users/chrisfosterelli/Library/Android/sdk/ndk-bundle/
This error indicates, as far as I can tell, that I'm trying to mix and match binaries compiled for different architectures. However, from what I can tell the library is the correct architecture:
root#eacbdb1c0e46:/meili/meili2/newtest# ar x libvalhalla_meili.a
root#eacbdb1c0e46:/meili/meili2/newtest# file libvalhalla_meili_la-map_matcher_factory.o
libvalhalla_meili_la-map_matcher_factory.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), not stripped
root#eacbdb1c0e46:/meili/meili2/newtest#
FWIW, these are my current Application.mk,
APP_STL := c++_static
APP_CPPFLAGS := -frtti -std=gnu++11 -D_GLIBCXX_USE_C99
APP_CPPFLAGS += -fexceptions
NDK_TOOLCHAIN_VERSION := clang
APP_LDFLAGS := -latomic
APP_PLATFORM := android-21
APP_ABI := arm64-v8a
and Android.mk,
LOCAL_PATH := $(call my-dir)
# static library info
include $(CLEAR_VARS)
LOCAL_MODULE := libvalhalla_meili
LOCAL_SRC_FILES := ../prebuild/libvalhalla_meili.a
LOCAL_EXPORT_C_INCLUDES := ../prebuild/include
include $(PREBUILT_STATIC_LIBRARY)
# wrapper info
include $(CLEAR_VARS)
LOCAL_C_INCLUDES += ../prebuild/include
LOCAL_MODULE := wrapper
LOCAL_SRC_FILES := wrapper.cpp
LOCAL_STATIC_LIBRARIES := libvalhalla_meili
include $(BUILD_SHARED_LIBRARY)
Any ideas how to resolve this? I've tried a number of things but all of them lead to more (more obscure) errors, so I'm hoping someone here can point me in the correct direction!
I discovered the problem, but I wish I had a more insightful answer. Apparently the build process had created two library files. The one that I inspected was, of course, ARM64. However the one that I actually copied to the Android device was x86.
So, the error message was correct and so was the library file, but there was more than one file involved. If you're running into the same problem and pretty sure your library is ARM64, double check that's actually the same file that is being compiled into the ndk build!

android ndk linking against libcutils.so

I am trying to link an executable against libcutils.so, but I get the following error:
Executable : gps_test
/home/jbrew/android_gps/jni/lib_dir//libcutils.so: undefined reference to `ioprio_set'
/home/jbrew/android_gps/jni/lib_dir//libcutils.so: undefined reference to `ioprio_get'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/gps_test] Error 1
Here is what my Android.mk file looks like:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
gps_test.c
LOCAL_LDLIBS:= -L/home/jbrew/android_gps/jni/lib_dir/ -llog -lhardware -lcutils
LOCAL_C_INCLUDES:= \
/home/jbrew/android_gps/jni/includes
LOCAL_MODULE:= gps_test
#include $(BUILD_SHARED_LIBRARY)
include $(BUILD_EXECUTABLE)
Is there a way to get the compiler to ignore these? I tried to add CFLAG --warn-unresolved-symbols, but the compiler didn't know what that flag meant.
For anyone else that has this issue, the problem was my API level. ndk-build was using android-3 to build by default. I added a default.properties file to my project path, then put "target=android-9" in that file. After this addition, I could build the executable.

hello-jni Sample ndk-build fails

I'm following the instructions here for hello-jni sample:
There are a few other questions on SO on this, but none have the same message.
My command line:
I have set environmental variable up for ndkroot
From the project dir>%ndkroot%/ndk-build
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
/usr/bin/sh: -c: line1: syntax error: unexpected end of file
make: *** [libs/armabi/gdbserver] Error 1
I have made the build.xml file as instructed and my Android.mk file is untouched, not sure if it should be though:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_SHARED_LIBRARY)
I am using NDK 7b.
I guess it was a mismatch between the instructions and the NDK version. I had v7b, but the latest is v8b. Once I downloaded v8b, it worked as per the instructions.

Categories

Resources