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.
Related
I was given a shared library built on Linux x86, let's call it libA.so, and I want to use the function calls provided by this library SDK.
I am having issues building and have a few questions:
1) I will be able to build for x86, but will I be able to build for arm? I believe the answer is no, meaning I cannot run on a Nexus 5 for example.
2) The ndk-build complains of the #include that should be resolved by my LOCAL_SHARED_LIBRARIES. I am not sure why that is. My Android.mk is as follow:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := B
LOCAL_SRC_FILES := B.cpp
LOCAL_SHARED_LIBRARIES := A
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
Can someone please help me resolve my Android.mk? I don't understand why it is complaining about my include statement in B.cpp. Please let me know if I can run B in an arm environment, although the SDK I am relying on was built on x86.
If your shared library libA.so has been compiled for linux-x86, it will certainly not run on android x86 targets (mainly because it needs to be linked to Bionic C library instead of glibc), and absolutely not on android arm devices.
Then, to solve your second issue, if you can get properly compiled android shared libraries for your android targets, you would include your library this way:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := A
LOCAL_SRC_FILES := ../libA/prebuilts/$(TARGET_ARCH_ABI)/libA.so # path to libA .so file, depending on the target ABI.
LOCAL_EXPORT_C_INCLUDES := ../libA/includes # path to libA headers.
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := B
LOCAL_SRC_FILES := B.cpp
LOCAL_SHARED_LIBRARIES := A
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
I'm using NDK-r9d and trying to integrate C++ Google Play Game (GPG) Services to my sample native-activity project.
Now native-activity (sample from NDK ) compiles perfectly and runs fine on my android phone.
But when I add GPG using this code
gpg::AndroidPlatformConfiguration platform_configuration;
platform_configuration.SetActivity(state->activity->clazz);
I got error
"Symbol 'function' could not be resolved" at achievement_manager.h /HelloJni/modules/gpg-cpp-sdk/android/include/gpg line 54 Semantic Error
I've added includes to STL and everything needed from this link Eclipse indexer errors when using STL with Android NDK with no success.
This is my Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.cpp
LOCAL_STATIC_LIBRARIES := android_native_app_glue libgpg-1
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM
LOCAL_CFLAGS := -std=c++11
include $(BUILD_SHARED_LIBRARY)
$(call import-add-path,$(LOCAL_PATH)/../modules)
$(call import-module,gpg-cpp-sdk/android)
$(call import-module,android/native_app_glue)
And this is my Application.mk
APP_PLATFORM := android-10
APP_ABI := armeabi-v7a
APP_STL := c++_static
Any suggestions?
I had some problems with compiling gpg sources until I specified the toolchain in Application.mk like this:
NDK_TOOLCHAIN_VERSION := 4.8
Note that I am on SDK 19, google play services 21, and NDK r9d.
Am trying to build an android ndk app using clang instead of gcc, for know i have tried this
in the Android.mk
NDK_TOOLCHAIN_VERSION := clang
LOCAL_CLANG :=true
LOCAL_LDLIBS := -lc++_static
LOCAL_CFLAGS := -std=c++11
and in the Application.mk
APP_PLATFORM := android-9
APP_STL := libc++_static
APP_CPPFLAGS := -fexceptions -frtti
APP_ABI := armeabi-v7a
but it always give me link errors with the std library.
Any help is appreciated !
There are several mistakes in your *.mk files:
libc++_static isn't a proper value for APP_STL, it should be c++_static here.
NDK_TOOLCHAIN_VERSION has no effect when set inside Android.mk, it should be set inside Application.mk
LOCAL_CLANG is a variable used inside system modules from AOSP, not when using the NDK.
Since you're setting APP_STL as c++_static, the NDK toolchain will correctly tell the linker what lib to use, you shouldn't add LOCAL_LDLIBS := -lc++_static.
Also, you set APP_ABI to only armeabi-v7a, is it on purpose ? Android runs on other architectures as well and you'll get better performance on these if you also compile your libraries accordingly. You can either set APP_ABI to all or to a list of architectures armeabi-v7a x86...
In summary:
Android.mk
LOCAL_CFLAGS := -std=c++11
Application.mk
NDK_TOOLCHAIN_VERSION := clang
APP_PLATFORM := android-9
APP_STL := c++_static
APP_CPPFLAGS := -fexceptions -frtti
APP_ABI := all
If you continue having some troubles compiling your code, please show the exact errors you're getting.
The building settings are correct,
mostly this is happens because you are linking with library that use gcc instead of clang. check if all your linked library using clang !
I am trying to compile C++ code dependent on OpenCV on the Android NDK.
I have looked into several answers (mainly this) but apparently the NDK still cannot see the directory I'm giving it in the LOCAL_C_INCLUDES variable.
This is my Application.mk:
APP_ABI :=armeabi armeabi-v7a
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_PLATFORM :=android-14
NDK_TOOLCHAIN_VERSION=4.7
This is my Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= swt
LOAL_CPP_EXTENSIO:=.cpp
LOCAL_C_INCLUDES := /usr/include:/usr/include/i386-linux-gnu:/usr/include/i386-linux-gnu/bits:/usr/include/i386-linux-gnu/sys:/usr/include/i386-linux-gnu/gnu:/usr/include/i386-linux-gnu/asm:/home/hamdy/Downloads/android-ndk-r8e/sources:/usr/local/include/opencv:/usr/local/include/opencv2/core
LOCAL_CFLAFS := -x c++ -lopencv_core -lopencv_highgui -lopencv_imgproc
LOCAL_SRC_FILES := TextDetection.cpp FeaturesMain.cpp
include $(BUILD_SHARED_LIBRARY)
This is the error I'm getting [cv.h is the file included in my .cpp so it can apparently see that in the /usr/local/include/opencv directory but cannot get past the includes in it]:
/usr/local/include/opencv/cv.h:63:33: fatal error: opencv2/core/core_c.h: No such file or directory
compilation terminated.
I don't know why but when I've compiled the same under Linux everything compiled fine. Under Windows there were errors. So I've switched to Linux
I'm trying to configure Android.mk to cross compile native code to support different chipset namely armeabi, mips, and x86. I know I can configure Application.mk in the following way to compile the source code for different chip set:
APP_ABI := all
This will trigger Android-NDK's build script to compile the source code for all the chipsets. However, I want to dynamically tell Android.mk to look for different static library dependencies compiled with different chip set.
# Get the architecture info
ARCH := ????
include $(CLEAR_VARS)
LOCAL_MODULE:= mylib
LOCAL_SRC_FILES:= build/lib/libxxx_$(ARCH).a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
Is this possible to do? If so, can anyone advice how to do so?
Update: I tried something like this in Application.mk:
APP_ABI := armeabi armeabi-v7a mips x64
with Android.mk:
# Get the architecture info
ARCH := $(APP_ABI)
include $(CLEAR_VARS)
LOCAL_MODULE:= mylib
LOCAL_SRC_FILES:= build/lib/libxxx_$(ARCH).a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
but it errors with the following:
The LOCAL_SRC_FILES for a prebuilt static library should only contain one item
which makes sense. I want to pass APP_ABI := all in Application.mk and be able to
dynamically reference it. Any ideas?
Check TARGET_ARCH_ABI:
ifeq($(TARGET_ARCH_ABI), armeabi-v7a)
# v7a-specific stuff
endif
There is TARGET_ARCH variable that holds the value of the current ABI being built. You can use it the following way:
ifeq ($(TARGET_ARCH),x86)
LOCAL_CFLAGS := $(COMMON_FLAGS_LIST)
else
LOCAL_CFLAGS := -mfpu=vfp -mfloat-abi=softfp $(COMMON_FLAGS_LIST)
endif
If you specify APP_ABI := armeabi-v7a armeabi mips x86 or APP_ABI := all in your Application.mk you will get each and every separate ABI value.