Android - Native code trigger a SIGILL only on emulator - android

My app is triggering a SIGILL fault only when i run it on the emulator. The app is using ActionBarSherlock and the minimum SDK target is API level 8. The fault is triggered when native code is executed (the rest of the app, written in Java, seems to work). I have tried a number of different emulator setup without success. There is no specific code that is faulting. If i comment the function that is faulting, the SIGILL is triggered by some other function at some other point. I use the macro LOGI to write things on the console and the native-code functions are called properly. I have absolutely no idea of what is happening. The app is working perfectly on two different phones (an armv6 rev 5 running android 2.3.4 and an armv7 rev 9 running android 4.0.3). The native code is a library that i have written and tested on my Windows desktop system, and it is working without problems.
Help!
Android.mk
OCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#LOCAL_CFLAGS := -DANDROID_NDK -Wno-psabi
LOCAL_C_INCLUDES += png++/
LOCAL_C_INCLUDES += libpng/
LOCAL_C_INCLUDES += zlib/
LOCAL_MODULE := mylib
LOCAL_SRC_FILES := /* a list of .cpp files... */
LOCAL_SRC_FILES += $(wildcard ./*.c)
LOCAL_SRC_FILES += $(wildcard ./zlib/*.c)
LOCAL_SRC_FILES += $(wildcard ./libpng/*.c)
LOCAL_LDLIBS := -llog
LOCAL_LDLIBS += -ljnigraphics
LOCAL_CFLAGS += -marm -march=armv6 -mfloat-abi=softfp -mfpu=vfp -fpermissive -fwrapv -O2 -fexceptions
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_STL := gnustl_static
APP_OPTIM := release
APP_CPPFLAGS += -frtti

I had a similar problem. I gave up trying on emulator; I think it's something related to ARMv6 support on Android emulator. As mine works on the device too, I no longer care about this issue.

Related

How to Fix the following error in Android NDK Project "only position independent executables (PIE) are supported"

I am working on a Android NDK Project using Iperf library for measuring network performance. App is working perfect up to Android version 4.x.But not working in Android latest versions from 5.x(Lollipop), getting an error "error: only position independent executables (PIE) are supported.".I am using Eclipse Luna, NDK12.
Please reply if anybody has the solution to this .
Thanks in Advance.
`LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Enable PIE manually. Will get reset on $(CLEAR_VARS). This
# is what enabling PIE translates to behind the scenes.
LOCAL_CFLAGS += -fPIE
LOCAL_LDFLAGS += -fPIE -pie
L_DEFS := -DHAVE_CONFIG_H -UAF_INET6
L_CFLAGS := $(L_DEFS)
L_COMMON_HDR := Condition.h gnu_getopt.h Locale.h Reporter.h Thread.h config.win32.h headers.h Mutex.h service.h util.h Extractor.h inet_aton.h report_CSV.h snprintf.h version.h gettimeofday.h List.h report_default.h SocketAddr.h \
Client.hpp Listener.hpp Server.hpp Timestamp.hpp delay.hpp PerfSocket.hpp Settings.hpp
L_COMMON_SRC := Extractor.c Locale.c Reporter.c sockets.c gnu_getopt.c ReportCSV.c service.c stdio.c gnu_getopt_long.c ReportDefault.c SocketAddr.c tcp_window_size.c \
Client.cpp List.cpp main.cpp Server.cpp Launch.cpp Listener.cpp PerfSocket.cpp Settings.cpp
L_COMMON_COMPAT := headers_slim.h error.c inet_ntop.c signal.c string.c gettimeofday.c inet_pton.c snprintf.c Thread.c delay.cpp
iperf_SOURCES := $(L_COMMON_HDR) $(L_COMMON_SRC) $(L_COMMON_COMPAT)
include $(CLEAR_VARS)
LOCAL_MODULE := iperf
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
LOCAL_MODULE_TAGS := tests eng
LOCAL_CFLAGS := $(L_CFLAGS)
LOCAL_SRC_FILES := $(iperf_SOURCES)
LOCAL_DISABLE_FORMAT_STRING_CHECKS := true
include $(BUILD_EXECUTABLE)`

Android NDK build to support all available devices

I am using in my project both java files and native c++ code. I would like to make the app available for all devices and hardware (API lvl >= 15). I am also using OpenCV4Android both in java and my native c++ if that matters. I'm not quite sure if my current configuration is sufficient to support all available hardware:
Application.mk
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-9
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
include C:/OpenCV4Android/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_MODULE := myNativeLib
LOCAL_SRC_FILES := myNativeLib.cpp
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_LIBRARY)
I have tested this configuration on a few devices and it seems to work but doesn't APP_ABI := armeabi-v7a narrow down the supported devices to only those with armeabi-v7a, or actually every device will be able to run it? Maybe I should insert APP_ABI := all as mentioned here? https://developer.android.com/ndk/guides/application_mk.html
It is very important to me to make the app responding and working for all devices possible.
To support all platforms you should use APP_ABI := all
. For API 15 use APP_PLATFORM := android-15.
Pay attention that the more platforms you will support the larger your apk file will be, since it will create a binary for each supported platform in your APK.

Android Lollipop native executable NDK 9 PIE executable support

Previously I've been using the following make file (or similar) to build a native app with the NDK (version r9d):
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= nativeApp.c
LOCAL_MODULE := nativeApp
LOCAL_STATIC_LIBRARIES := libcutils libc
LOCAL_SHARED_LIBRARIES:= libbinder liblog
include $(BUILD_EXECUTABLE)
However, Lollipop started enforcing that native applications were PIE. I've seen several solutions online and on S.O. and from that I've tried adding the following lines to address this issue:
APP_PLATFORM := android-16
LOCAL_CFLAGS += -fPIE
LOCAL_LDFLAGS += -fPIE -pie
It always builds fine but no matter what flags I use when I try to run it on the device I always get the PIE support error. I already have an environment set up around NDK r9d so I was trying to not have to go and change it but is that the only way to address this?

Android makefile links twice

I've set up a makefile for my game in SDL. The template of the Application.mk file included in SDL has three architectures:
APP_ABI := armeabi armeabi-v7a x86
Everything compiles just fine for armeabi, but for armeabi-v7a it fails. To me, it looks like compilation completes, but the linker has all obj files of two certain folders twice. While this does not happen for armeabi. The linker (ld) gives me an error of this kind:
/path/to/bin/ld: error: /path/to/myObjFile.obj: multiple definition of 'foo(int, int)'
/path/to/bin/ld: /path/to/myObjFile.obj: previous definition here
The path is exactly the same, so this makes me assume that the linker uses every file twice. A full example of such an error is here:
/Users/martijncourteaux/Development/android-ndk-r10c/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /Volumes/Stuff/Projects/GameDev/Gump/GumpAndroid/obj/local/armeabi-v7a/objs/main//Volumes/Stuff/Projects/GameDev/Gump/GumpAndroid/jni/src/__/ThirdParty/Box2D/Collision/b2Distance.o: multiple definition of 'b2Distance(b2DistanceOutput*, b2SimplexCache*, b2DistanceInput const*)'
/Users/martijncourteaux/Development/android-ndk-r10c/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: /Volumes/Stuff/Projects/GameDev/Gump/GumpAndroid/obj/local/armeabi-v7a/objs/main//Volumes/Stuff/Projects/GameDev/Gump/GumpAndroid/jni/src/__/ThirdParty/Box2D/Collision/b2Distance.o: previous definition here
However, the object files that are linked double also generate this warning when I launch ndk-build:
/Users/martijncourteaux/Development/android-ndk-r10c/build/core/build-binary.mk:449: warning: ignoring old commands for target `/Volumes/Stuff/Projects/GameDev/Gump/GumpAndroid/obj/local/armeabi-v7a/objs/main//Volumes/Stuff/Projects/GameDev/Gump/GumpAndroid/jni/src/__/ThirdParty/Collision/b2Distance.o'
/Users/martijncourteaux/Development/android-ndk-r10c/build/core/build-binary.mk:449: warning: overriding commands for target `/Volumes/Stuff/Projects/GameDev/Gump/GumpAndroid/obj/local/armeabi-v7a/objs/main//Volumes/Stuff/Projects/GameDev/Gump/GumpAndroid/jni/src/__/ThirdParty/Collision/b2Distance.o'
Note that I have the impression that all these obj-files that have these multiple definition errors generate also generate this warning.
This is my Application.mk:
APP_STL := gnustl_static
APP_ABI := armeabi armeabi-v7a x86
NDK_TOOLCHAIN_VERSION := clang
APP_CPPFLAGS += -std=c++11
APP_PLATFORM := android-10
And here is my Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := main
SDL_PATH := ../SDL
THIRD_PARTY_FOLDER := $(LOCAL_PATH)/../ThirdParty
LOCAL_CPPFLAGS += -frtti
LOCAL_CPPFLAGS += -fexceptions
LOCAL_CPPFLAGS += -funwind-tables
PCH_FILE := $(LOCAL_PATH)/Gump/Gump-Prefix.pch
#PCH_FILE := Gump/Gump-Prefix.pch
LOCAL_CPPFLAGS += -include $(PCH_FILE)
#LOCAL_PCH := $(PCH_FILE)
#LOCAL_CPPFLAGS += -DPCH
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include \
$(LOCAL_PATH)/$(SDL_PATH)_mixer/ \
$(LOCAL_PATH)/$(SDL_PATH)_image/ \
$(LOCAL_PATH)/$(SDL_PATH)_net/ \
$(LOCAL_PATH)/../ThirdParty/ \
$(LOCAL_PATH)/Gump/
# Add your application source files here...
GUMP_SRC_FILES := $(wildcard $(LOCAL_PATH)/Gump/*.cpp)
THIRD_PARTY_SRC_FILES += $(wildcard $(THIRD_PARTY_FOLDER)/tinyxml2/tinyxml2.cpp)
THIRD_PARTY_SRC_FILES += $(wildcard $(THIRD_PARTY_FOLDER)/Box2D/*/*.cpp)
THIRD_PARTY_SRC_FILES += $(wildcard $(THIRD_PARTY_FOLDER)/Box2D/*/*/*.cpp)
THIRD_PARTY_SRC_FILES += $(wildcard $(THIRD_PARTY_FOLDER)/poly2tri/**/*.cc)
LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c $(THIRD_PARTY_SRC_FILES) $(GUMP_SRC_FILES)
LOCAL_SHARED_LIBRARIES := SDL2_image SDL2_mixer SDL2_net SDL2
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog
include $(BUILD_SHARED_LIBRARY)
My Guess (turns out false):
After writing this question and looking closely to provide you guys the most accurate information as possible about my problem, I noticed that the obj-files that are giving errors are those were I've used a wildcard on folder level as well. Eg: $(ROOT)/*/*.cpp. While these wildcards give no problem: $(ROOT)/Gump/*.cpp. I don't know for sure, but I guess that the wildcards work different on when linking for these different architectures...
Update:
I've tested it again not using wildcards for folders, and the same error about multiple definition appears.
Your list of files is appended every time a new ABI is being built. LOCAL_SRC_FILES is erased through include $(CLEAR_VARS); GUMP_SRC_FILES is redefined each time. But THIRD_PARTY_SRC_FILES only grows longer and longer. This has nothing to do with the wildcards, as you noticed. Simply add line
THIRD_PARTY_SRC_FILES :=
after include $(CLEAR_VARS), and your build will be fine.
Running ndk-build V=1 shows the build commands executed during the process. There I could see the .o files being linked twice. I'm not sure what the reason for that is. I guess it might have been due to the fact that the android makefile in the src/ folder used sources from his parent directory: ../ThirdParty/[morehere].
I fixed it by creating extra makefiles for these third party libraries, so now every library creates a shared library in a .so file. Which gets linked at compile-time. I think this is neater, because changing a makefile requires only that subproject to be recompiled.

Some users of my Android app are experiencing an Unsatisfied Link Error

why is it that only some of my customers are experiencing an unsatisfied link error whilst it works flawlessly in most cases?
java.lang.UnsatisfiedLinkError: Couldn't load Foo: findLibrary returned null
I read about this problem before but couldn't find a solution. Any ideas?
Thanks
Edit: Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# disable thumb mode
LOCAL_ARM_MODE := arm
LOCAL_MODULE := Foo
#-Wno-psabi to remove warning about GCC 4.4 va_list warning
LOCAL_CFLAGS := -DANDROID_NDK -Wno-psabi -Wno-write-strings
LOCAL_DEFAULT_CPP_EXTENSION := cpp
LOCAL_SRC_FILES := \
source1.cpp \
source2.c
LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog -lz
include $(BUILD_SHARED_LIBRARY)
One reason could be that you built the library for ARM v7 (i.e. with APP_ABI=armeabi-v7a) but not for ARM v6 (APP_ABI=armeabi). But maybe some of your customers are using MIPS, or x86 - powered devices?
If these explanations do not fit, please provide more info, e.g. show your Android.mk and Application.mk files.

Categories

Resources