I should say that I'm first time at android studio with ndk.
environment is Android Studio 3.1.4 and OpenCV 3.4 at windows 10 os.
I use open source about opencv that 'Facetracker' link is below
https://github.com/kylemcdonald/FaceTracker
i changed some codes and want to build at android studio
so i drew up CMakeList.txt, Android.mk, Application.mk, build.gradle.
Synchronization with gradle work well but build, generate signed APK occur error below.
Build command failed.
Error while executing process C:\Users\Duru\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build D:\ProgramFiles\Android\Projects\OpencvTest\app\.externalNativeBuild\cmake\release\x86_64 --target PAW}
[1/1] **Linking CXX shared library** ..\..\..\..\build\intermediates\cmake\release\obj\x86_64\libPAW.so
FAILED: cmd.exe /C "cd . && C:\Users\Duru\AppData\Local\Android\Sdk\ndk-bundle\toolchains\x86_64-4.9\prebuilt\windows-x86_64\bin\x86_64-linux-android-g++.exe --sysroot=C:/Users/Duru/AppData/Local/Android/Sdk/ndk-bundle/sysroot -fPIC -isystem C:/Users/Duru/AppData/Local/Android/Sdk/ndk-bundle/sysroot/usr/include/x86_64-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -frtti -fexceptions -std=gnu++11 -O2 -DNDEBUG -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a --sysroot C:/Users/Duru/AppData/Local/Android/Sdk/ndk-bundle/platforms/android-21/arch-x86_64 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libPAW.so -o ..\..\..\..\build\intermediates\cmake\release\obj\x86_64\libPAW.so CMakeFiles/PAW.dir/src/main/jni/src/lib/PAW.cc.o -latomic -lm "C:/Users/Duru/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/libgnustl_static.a" && cd ."
D:/ProgramFiles/Android/Projects/OpenCV-android-sdk/sdk/native/jni/include/opencv2/core/cvstd.hpp:648: error: undefined reference to 'cv::String::deallocate()'
**D:/ProgramFiles/Android/Projects/OpenCV-android-sdk/sdk/native/jni/include/opencv2/core/cvstd.hpp:648: error: undefined reference to 'cv::String::deallocate()'
D:/ProgramFiles/Android/Projects/OpenCV-android-sdk/sdk/native/jni/include/opencv2/core/mat.inl.hpp:2686: error: undefined reference to 'cv::MatConstIterator::seek(long, bool)'
D:\ProgramFiles\Android\Projects\OpencvTest\app\src\main\jni\src\lib/PAW.cc:146: error: undefined reference to 'cv::Mat::zeros(int, int, int)'
D:/ProgramFiles/Android/Projects/OpenCV-android-sdk/sdk/native/jni/include/opencv2/core/mat.inl.hpp:2591: error: undefined reference to 'cv::MatConstIterator::seek(int const*, bool)'
D:/ProgramFiles/Android/Projects/OpenCV-android-sdk/sdk/native/jni/include/opencv2/core/mat.inl.hpp:2591: error: undefined reference to 'cv::MatConstIterator::seek(int const*, bool)'
D:/ProgramFiles/Android/Projects/OpenCV-android-sdk/sdk/native/jni/include/opencv2/core/mat.inl.hpp:2686: error: undefined reference to 'cv::MatConstIterator::seek(long, bool)'
D:/ProgramFiles/Android/Projects/OpenCV-android-sdk/sdk/native/jni/include/opencv2/core/mat.inl.hpp:717: error: undefined reference to 'cv::Mat::copySize(cv::Mat const&)'
D:/ProgramFiles/Android/Projects/OpenCV-android-sdk/sdk/native/jni/include/opencv2/core/mat.inl.hpp:717: error: undefined reference to 'cv::Mat::copySize(cv::Mat const&)'
D:\ProgramFiles\Android\Projects\OpencvTest\app\src\main\jni\src\lib/PAW.cc:167: error: undefined reference to 'cv::remap(cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&, cv::_InputArray const&, int, int, cv::Scalar_<double> const&)'
collect2.exe: error: ld returned 1 exit status**
ninja: build stopped: subcommand failed.
my android.mk
LOCAL_PATH := $(call my-dir)
MY_PATH := $(LOCAL_PATH)
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
include $(CLEAR_VARS)
CVROOT := D:/ProgramFiles/Android/Projects/OpenCV-android-sdk/sdk/native/jni
LOCAL_MODULE := FaceTracker
LOCAL_SRC_FILES := libFaceTracker.a #$(wildcard /src/lib/*.cc)
#LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_LDLIBS = -lz -lm
LOCAL_CFLAGS = -Wall -pedantic -g -O3 -ffast-math -funroll-loops -march=armv7-a -mfloat-abi=softfp -mfpu=neon
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
OPENCV_INSTALL_MODULES:=on
include $(CVROOT)/OpenCV.mk
LOCAL_MODULE := opencv_java3
LOCAL_SRC_FILES := native-lib.cpp
LOCAL_C_FLAGS+= -DNDEBUG -Wall -pedantic -g -O3 -ffast-math -funroll-loops -march=armv7-a -mfloat-abi=softfp -mfpu=neon
#LOCAL_C_INCLUDES+= $(NDK_APP_PROJECT_PATH)/stasm4.1.0/stasm
#LOCAL_SRC_FILES += $(NDK_APP_PROJECT_PATH)/libstasm.a
#LOCAL_SRC_FILES += $(wildcard $(NDK_APP_PROJECT_PATH)/stasm/*.cpp)
LOCAL_LDLIBS += -lm -llog -landroid
#LOCAL_SHARED_LIBRARIES += libandroid
LOCAL_STATIC_LIBRARIES += android_native_app_glue
LOCAL_STATIC_LIBRARIES += FaceTracker
LOCAL_ARM_NEON := true
LOCAL_ARM_MODE := arm
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
endif
my build.gradle
import org.apache.tools.ant.taskdefs.condition.Os
def getNdkBuildPath() {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def command = properties.getProperty('ndk.dir')
if(Os.isFamily(Os.FAMILY_WINDOWS)) {
command +="\\ndk-build.cmd"
} else {
command +="/ndk-build"
}
return command
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.duru.opencvtest"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
arguments '-DANDROID_TOOLCHAIN=gcc',
'-DANDROID_STL=gnustl_static'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':openCVLibrary342')
}
my application.mk
APP_PLATFORM := android-28
APP_ABI := armeabi-v7a
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions -std=c++11
APP_OPTIM := release
and CMakeList.txt
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
set(pathOPENCV D:/ProgramFiles/Android/Projects/OpenCV-android-sdk)
set(pathPROJECT D:/ProgramFiles/Android/Projects/OpencvTest)
set(pathLIBOPENCV_JAVA ${pathPROJECT}/app/src/main/JniLibs/${ANDROID_ABI}/libopencv_java3.so)
set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
include_directories(${pathOPENCV}/sdk/native/jni/include)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/jni/native-lib.cpp)
add_library( lib_opencv SHARED IMPORTED )
add_library( Tracker SHARED src/main/jni/src/lib/Tracker.cpp )
add_library( PDM SHARED src/main/jni/src/lib/PDM.cc )
add_library( PAW SHARED src/main/jni/src/lib/PAW.cc )
add_library( Patch SHARED src/main/jni/src/lib/Patch.cc )
add_library( IO SHARED src/main/jni/src/lib/IO.cc )
add_library( FDet SHARED src/main/jni/src/lib/FDet.cc )
add_library( FCheck SHARED src/main/jni/src/lib/FCheck.cc )
add_library( CLM SHARED src/main/jni/src/lib/CLM.cc )
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${pathLIBOPENCV_JAVA})
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
Tracker
PDM
PAW
Patch
IO
FDet
FCheck
CLM
lib_opencv
# Links the target library to the log library
# included in the NDK.
${log-lib} )
opensource are composed of 7 header, 6 .cc files and a .cpp file.
Related
My app run perfectly on 32bit android devices when I try to run on 64bit devices
its gives me error on build time.
Error:
Build command failed.
Error while executing process D:\Software\sdk\NDK\android-ndk-r17\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=E:\Projects\TestProjects\VirtualApp-master\VirtualApp\lib\src\main\jni\Android.mk NDK_APPLICATION_MK=E:\Projects\TestProjects\VirtualApp-master\VirtualApp\lib\src\main\jni\Application.mk APP_ABI=arm64-v8a NDK_ALL_ABIS=arm64-v8a NDK_DEBUG=1 APP_PLATFORM=android-21 NDK_OUT=E:/Projects/TestProjects/VirtualApp-master/VirtualApp/lib/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=E:\Projects\TestProjects\VirtualApp-master\VirtualApp\lib\build\intermediates\ndkBuild\debug\lib E:/Projects/TestProjects/VirtualApp-master/VirtualApp/lib/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/libva++.so}
Android NDK: WARNING: APP_STL gnustl_static is deprecated and will be removed in the next release. Please switch to either c++_static or c++_shared. See https://developer.android.com/ndk/guides/cpp-support.html for more information.
Android NDK: WARNING: Ignoring unknown import directory: :E:/Projects/TestProjects/VirtualApp-master/VirtualApp/lib/src/main/jni
Android NDK: WARNING:E:/Projects/TestProjects/VirtualApp-master/VirtualApp/lib/src/main/jni/fb/Android.mk:fb: LOCAL_LDLIBS is always ignored for static libraries
[arm64-v8a] Compile++ : va++ <= IOUniformer.cpp
E:/Projects/TestProjects/VirtualApp-master/VirtualApp/lib/src/main/jni/Foundation/IOUniformer.cpp:130:23: error: use of undeclared identifier '__NR_chmod'
int ret = syscall(__NR_chmod, redirect_path, mode);
^
E:/Projects/TestProjects/VirtualApp-master/VirtualApp/lib/src/main/jni/Foundation/IOUniformer.cpp:140:23: error: use of undeclared identifier '__NR_fstatat64'
int ret = syscall(__NR_fstatat64, dirfd, redirect_path, buf, flags);
^
E:/Projects/TestProjects/VirtualApp-master/VirtualApp/lib/src/main/jni/Foundation/IOUniformer.cpp:149:23: error: use of undeclared identifier '__NR_fstatat64'
int ret = syscall(__NR_fstatat64, dirfd, redirect_path, buf, flags);
^
E:/Projects/TestProjects/VirtualApp-master/VirtualApp/lib/src/main/jni/Foundation/IOUniformer.cpp:159:23: error: use of undeclared identifier '__NR_fstat64'
int ret = syscall(__NR_fstat64, redirect_path, buf);
^
....
....
...
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [E:/Projects/TestProjects/VirtualApp-master/VirtualApp/lib/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs/va++/Foundation/IOUniformer.o] Error 1
I have build app on 64bit device using following steps.
Add "arm64-v8a" in abiFilters
update APP_ABI in Application.mk
but
Android.mk
LOCAL_PATH := $(call my-dir)
MAIN_LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := va++
LOCAL_CFLAGS := -Wno-error=format-security -fpermissive -DLOG_TAG=\"VA++\"
LOCAL_CFLAGS += -fno-rtti -fno-exceptions
LOCAL_C_INCLUDES += $(MAIN_LOCAL_PATH)
LOCAL_C_INCLUDES += $(MAIN_LOCAL_PATH)/Foundation
LOCAL_C_INCLUDES += $(MAIN_LOCAL_PATH)/Jni
LOCAL_SRC_FILES := Jni/VAJni.cpp \
Foundation/IOUniformer.cpp \
Foundation/VMPatch.cpp \
Foundation/SymbolFinder.cpp \
Foundation/Path.cpp \
Foundation/SandboxFs.cpp \
Substrate/hde64.c \
Substrate/SubstrateDebug.cpp \
Substrate/SubstrateHook.cpp \
Substrate/SubstratePosixMemory.cpp \
LOCAL_LDLIBS := -llog -latomic
LOCAL_STATIC_LIBRARIES := fb
include $(BUILD_SHARED_LIBRARY)
include $(MAIN_LOCAL_PATH)/fb/Android.mk
LOCAL_SHORT_COMMANDS := true
Application.mk
APP_ABI := arm64-v8a
APP_PLATFORM := android-24
APP_STL := gnustl_static
APP_OPTIM := release
VA_ROOT := $(call my-dir)
NDK_MODULE_PATH := $(NDK_MODULE_PATH):$(VA_ROOT)
Gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
externalNativeBuild {
ndkBuild {
abiFilters "armeabi-v7a", "x86","arm64-v8a"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
ndkBuild {
path file("src/main/jni/Android.mk")
}
}
lintOptions {
//IJobService need NewApi
warning 'NewApi','OnClick'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
}
[CXX1405] error when building with ndkBuild using C:\Users\IT RENTAL\AndroidStudioProjects\appcloner\lib\src\main\jni\Android.mk: Build command failed.
Error while executing process C:\Users\IT RENTAL\AppData\Local\Android\Sdk\ndk\21.4.7075529\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\IT RENTAL\AndroidStudioProjects\appcloner\lib\src\main\jni\Android.mk NDK_APPLICATION_MK=C:\Users\IT RENTAL\AndroidStudioProjects\appcloner\lib\src\main\jni\Application.mk APP_ABI=arm64-v8a NDK_ALL_ABIS=arm64-v8a NDK_DEBUG=1 APP_PLATFORM=android-16 NDK_OUT=C:\Users\IT RENTAL\AndroidStudioProjects\appcloner\lib\build\intermediates\cxx\Debug\591uu4n4/obj NDK_LIBS_OUT=C:\Users\IT RENTAL\AndroidStudioProjects\appcloner\lib\build\intermediates\cxx\Debug\591uu4n4/lib APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}
'C:\Users\IT' is not recognized as an internal or external command,
operable program or batch file.
any idea on this issue ?
*EDIT June 2020: Unbelievably I came to my own (3 year old) question here from google after trying to help a coworker debug native code in our app on his new mac. AndroidStudio 4.0 with Gradle 6 and debugging native code is still something like sorcery! We have 3 developers, only 1 machine is this working. Same code base, same version of AndroidStudio, all 3 running Catalina. I'm just baffled.
EDIT: This is still unresolved. I suspected based on the comments that my use of an old NDK (10d) might be a problem so I upgraded to 15c and dealt with all the issues to get my stuff to compile with clang and the new c++ library. Unfortunately ndk-gdb is broken in 15c and my attempts to hack the python to make it work didn't get me anywhere. I then used Android Studio 3.0 preview and I'm back to where I was before - I can see stack information but all the code is assembly in lldb. Work must go on - I am back to using logcat for debugging :(
I come to you with a bruised forehead from numerous hits on the wall.
I'll try to be concise and provide all relevant information at the same time. If there is any relevant info I haven't included please let me know.
Synopsis:
I am maintaining an Android app as part of my job. I have had to resort to logging to debug native code because although I can set breakpoints and hit them, I can't view the source or variable information.
I've spent many hours and google searches trying to understand what I'm missing, yet still no luck.
My build environment is OSX using Android NDK r10D, and gradle 3.2 to build the APK.
I'm trying to use AndroidStudio 3.0 beta 6 to install and debug the APK.
My Android.manifest includes in the tag:
android:debuggable="true"
Native Code:
This is sample output from compiling one of the native c++ files with -v for verbosity:
~/src/libraries/cBase$ make android
Building obj/Binary.ao
Using built-in specs.
COLLECT_GCC=arm-linux-androideabi-g++
Target: arm-linux-androideabi
Configured with: /s/ndk-toolchain/src/build/../gcc/gcc-4.8/configure --prefix=/tmp/ndk-User/build/toolchain/prefix --target=arm-linux-androideabi --host=x86_64-apple-darwin --build=x86_64-apple-darwin --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --with-gmp=/tmp/ndk-User/build/toolchain/temp-install --with-mpfr=/tmp/ndk-User/build/toolchain/temp-install --with-mpc=/tmp/ndk-User/build/toolchain/temp-install --with-cloog=/tmp/ndk-User/build/toolchain/temp-install --with-isl=/tmp/ndk-User/build/toolchain/temp-install --with-ppl=/tmp/ndk-User/build/toolchain/temp-install --disable-ppl-version-check --disable-cloog-version-check --disable-isl-version-check --enable-cloog-backend=isl --with-host-libstdcxx='-static-libgcc -lstdc++ -lm' --disable-libssp --enable-threads --disable-nls --disable-libmudflap --disable-libgomp --disable-libstdc__-v3 --disable-sjlj-exceptions --disable-shared --disable-tls --disable-libitm --with-float=soft --with-fpu=vfp --with-arch=armv5te --enable-target-optspace --enable-initfini-array --disable-nls --prefix=/tmp/ndk-User/build/toolchain/prefix --with-sysroot=/tmp/ndk-User/build/toolchain/prefix/sysroot --with-binutils-version=2.24 --with-mpfr-version=3.1.1 --with-mpc-version=1.0.1 --with-gmp-version=5.0.5 --with-gcc-version=4.8 --with-gdb-version=7.6 --with-python=/Users/User/mydroid/ndk/prebuilt/darwin-x86_64/bin/python-config.sh --with-gxx-include-dir=/tmp/ndk-User/build/toolchain/prefix/include/c++/4.8 --with-bugurl=http://source.android.com/source/report-bugs.html --enable-languages=c,c++ --disable-bootstrap --enable-plugins --enable-libgomp --disable-libsanitizer --enable-gold --enable-graphite=yes --with-cloog-version=0.18.0 --with-isl-version=0.11.1 --enable-eh-frame-hdr-for-static --with-arch=armv5te --program-transform-name='s&^&arm-linux-androideabi-&' --enable-gold=default
Thread model: posix
gcc version 4.8 (GCC)
COLLECT_GCC_OPTIONS='-Wextra' '-Wall' '-g' '-v' '-D' 'ANDROID' '-O0' '-g' '-c' '-MMD' '-MP' '-I' '/Users/spartygw/src/libraries' '-I' '/Users/spartygw/src/libraries/thirdparty' '-I' '/Users/spartygw/src/libraries/thirdparty/jpeg' '-I' '/Users/spartygw/src/libraries/thirdparty/zlib' '-I' '/Users/spartygw/src/include' '-I' '/Users/spartygw/android-toolchain/sysroot/usr/include' '-D' '__ARM_ARCH_5__' '-D' '__ARM_ARCH_5T__' '-D' '__ARM_ARCH_5E__' '-D' '__ARM_ARCH_5TE__' '-D' '__ANDROID__' '-D' 'DEBUG' '-o' 'obj/Binary.ao' '-march=armv5te' '-mfloat-abi=soft' '-mfpu=vfp' '-mtls-dialect=gnu'
/Users/spartygw/android-toolchain/bin/../libexec/gcc/arm-linux-androideabi/4.8/cc1plus -quiet -v -I /Users/spartygw/src/libraries -I /Users/spartygw/src/libraries/thirdparty -I /Users/spartygw/src/libraries/thirdparty/jpeg -I /Users/spartygw/src/libraries/thirdparty/zlib -I /Users/spartygw/src/include -I /Users/spartygw/android-toolchain/sysroot/usr/include -iprefix /Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/ -isysroot /Users/spartygw/android-toolchain/bin/../sysroot -MMD obj/Binary.d -MP -MQ obj/Binary.ao -D_GNU_SOURCE -D ANDROID -D __ARM_ARCH_5__ -D __ARM_ARCH_5T__ -D __ARM_ARCH_5E__ -D __ARM_ARCH_5TE__ -D __ANDROID__ -D DEBUG Binary.cc -mbionic -fpic -quiet -dumpbase Binary.cc -march=armv5te -mfloat-abi=soft -mfpu=vfp -mtls-dialect=gnu -auxbase-strip obj/Binary.ao -g -g -O0 -Wextra -Wall -version -fexceptions -frtti -o /var/folders/03/hpjtv8c969scgcc5121ybrwr0000gn/T//ccciFNCN.s
GNU C++ (GCC) version 4.8 (arm-linux-androideabi)
compiled by GNU C version 4.2.1 (Apple Inc. build 5666) (dot 3), GMP version 5.0.5, MPFR version 3.1.1, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/include"
ignoring nonexistent directory "/Users/spartygw/android-toolchain/bin/../lib/gcc/../../include/c++/4.8/backward"
ignoring duplicate directory "/Users/spartygw/android-toolchain/bin/../lib/gcc/../../lib/gcc/arm-linux-androideabi/4.8/include"
ignoring nonexistent directory "/Users/spartygw/android-toolchain/bin/../sysroot/usr/local/include"
ignoring duplicate directory "/Users/spartygw/android-toolchain/bin/../lib/gcc/../../lib/gcc/arm-linux-androideabi/4.8/include-fixed"
ignoring nonexistent directory "/Users/spartygw/android-toolchain/bin/../lib/gcc/../../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/include"
ignoring nonexistent directory "/Users/spartygw/src/include"
ignoring duplicate directory "/Users/spartygw/android-toolchain/sysroot/usr/include"
as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
/Users/spartygw/src/libraries
/Users/spartygw/src/libraries/thirdparty
/Users/spartygw/src/libraries/thirdparty/jpeg
/Users/spartygw/src/libraries/thirdparty/zlib
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/include
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/include-fixed
/Users/spartygw/android-toolchain/bin/../lib/gcc/../../include/c++/4.8
/Users/spartygw/android-toolchain/bin/../lib/gcc/../../include/c++/4.8/arm-linux-androideabi
/Users/spartygw/android-toolchain/bin/../sysroot/usr/include
End of search list.
GNU C++ (GCC) version 4.8 (arm-linux-androideabi)
compiled by GNU C version 4.2.1 (Apple Inc. build 5666) (dot 3), GMP version 5.0.5, MPFR version 3.1.1, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 7c7303e2f21bf352ab9993b8ba84df0b
^
COLLECT_GCC_OPTIONS='-Wextra' '-Wall' '-g' '-v' '-D' 'ANDROID' '-O0' '-g' '-c' '-MMD' '-MP' '-I' '/Users/spartygw/src/libraries' '-I' '/Users/spartygw/src/libraries/thirdparty' '-I' '/Users/spartygw/src/libraries/thirdparty/jpeg' '-I' '/Users/spartygw/src/libraries/thirdparty/zlib' '-I' '/Users/spartygw/src/include' '-I' '/Users/spartygw/android-toolchain/sysroot/usr/include' '-D' '__ARM_ARCH_5__' '-D' '__ARM_ARCH_5T__' '-D' '__ARM_ARCH_5E__' '-D' '__ARM_ARCH_5TE__' '-D' '__ANDROID__' '-D' 'DEBUG' '-o' 'obj/Binary.ao' '-march=armv5te' '-mfloat-abi=soft' '-mfpu=vfp' '-mtls-dialect=gnu'
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/as -v -I /Users/spartygw/src/libraries -I /Users/spartygw/src/libraries/thirdparty -I /Users/spartygw/src/libraries/thirdparty/jpeg -I /Users/spartygw/src/libraries/thirdparty/zlib -I /Users/spartygw/src/include -I /Users/spartygw/android-toolchain/sysroot/usr/include -march=armv5te -mfloat-abi=soft -mfpu=vfp -meabi=5 --noexecstack -o obj/Binary.ao /var/folders/03/hpjtv8c969scgcc5121ybrwr0000gn/T//ccciFNCN.s
GNU assembler version 2.24 (arm-linux-androideabi) using BFD version (GNU Binutils) 2.24
COMPILER_PATH=/Users/spartygw/android-toolchain/bin/../libexec/gcc/arm-linux-androideabi/4.8/:/Users/spartygw/android-toolchain/bin/../libexec/gcc/:/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/
LIBRARY_PATH=/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/:/Users/spartygw/android-toolchain/bin/../lib/gcc/:/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/lib/:/Users/spartygw/android-toolchain/bin/../sysroot/usr/lib/
COLLECT_GCC_OPTIONS='-Wextra' '-Wall' '-g' '-v' '-D' 'ANDROID' '-O0' '-g' '-c' '-MMD' '-MP' '-I' '/Users/spartygw/src/libraries' '-I' '/Users/spartygw/src/libraries/thirdparty' '-I' '/Users/spartygw/src/libraries/thirdparty/jpeg' '-I' '/Users/spartygw/src/libraries/thirdparty/zlib' '-I' '/Users/spartygw/src/include' '-I' '/Users/spartygw/android-toolchain/sysroot/usr/include' '-D' '__ARM_ARCH_5__' '-D' '__ARM_ARCH_5T__' '-D' '__ARM_ARCH_5E__' '-D' '__ARM_ARCH_5TE__' '-D' '__ANDROID__' '-D' 'DEBUG' '-o' 'obj/Binary.ao' '-march=armv5te' '-mfloat-abi=soft' '-mfpu=vfp' '-mtls-dialect=gnu'
Android.mk:
My Android.mk in the jni directory looks like this:
LOCAL_PATH := $(call my-dir)
############## libGabObjs ##################
include $(CLEAR_VARS)
LOCAL_MODULE = libGabObjs
LOCAL_SRC_FILES := libGabObjs_android.a
ifneq (,$(wildcard $(LOCAL_SRC_FILES)))
include $(PREBUILT_STATIC_LIBRARY)
endif
######################################
#####################################
############## libavcodec ##############
include $(CLEAR_VARS)
LOCAL_MODULE := libavcodec
LOCAL_SRC_FILES := ../../../../lib/third-party/arm-android/libavcodec.so
include $(PREBUILT_SHARED_LIBRARY)
#####################################
############## libavutil ##############
include $(CLEAR_VARS)
LOCAL_MODULE := libavutil
LOCAL_SRC_FILES := ../../../../lib/third-party/arm-android/libavutil.so
include $(PREBUILT_SHARED_LIBRARY)
#####################################
############## libswscale ##############
include $(CLEAR_VARS)
LOCAL_MODULE := libswscale
LOCAL_SRC_FILES := ../../../../lib/third-party/arm-android/libswscale.so
include $(PREBUILT_SHARED_LIBRARY)
#####################################
############## libspeex ##############
include $(CLEAR_VARS)
LOCAL_MODULE := libspeex
LOCAL_SRC_FILES := ../../../../lib/third-party/arm-android/libspeex.a
include $(PREBUILT_STATIC_LIBRARY)
#####################################
############## libspeexdsp ##############
include $(CLEAR_VARS)
LOCAL_MODULE := libspeexdsp
LOCAL_SRC_FILES := ../../../../lib/third-party/arm-android/libspeexdsp.a
include $(PREBUILT_STATIC_LIBRARY)
#####################################
############## libjpeg ##############
include $(CLEAR_VARS)
LOCAL_MODULE := libjpeg
LOCAL_SRC_FILES := ../../../../lib/third-party/arm-android/libjpeg.a
include $(PREBUILT_STATIC_LIBRARY)
#####################################
############## libcrypto ############
include $(CLEAR_VARS)
LOCAL_MODULE := libcrypto
LOCAL_SRC_FILES := ../../../../lib/third-party/arm-android/libcrypto.a
include $(PREBUILT_STATIC_LIBRARY)
#####################################
############## libssl #############
include $(CLEAR_VARS)
LOCAL_MODULE := libssl
LOCAL_SRC_FILES := ../../../../lib/third-party/arm-android/libssl.a
include $(PREBUILT_STATIC_LIBRARY)
#####################################
############## libcutils #############
#include $(CLEAR_VARS)
#LOCAL_MODULE := libcutils
#LOCAL_SRC_FILES := ../../../../lib/third-party/arm-android/libcutils.so
#include $(PREBUILT_SHARED_LIBRARY)
#####################################
############## libs ############
include $(CLEAR_VARS)
LOCAL_MODULE := vhc_jnilib
LOCAL_SRC_FILES := video_codec_jni.cpp \
MyBaseThread.cc \
MicMonitor.cpp \
framework.cpp \
GabrielJni.cpp
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/../../../libraries/ \
$(LOCAL_PATH)/../../../libraries/thirdparty/
LOCAL_STATIC_LIBRARIES := \
libGabObjs \
libssl \
libcrypto \
libjpeg \
libspeex \
libspeexdsp
LOCAL_SHARED_LIBRARIES := \
libavcodec libavutil libswscale
A_DEFINES := -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -D__ANDROID__ -DDEBUG $(ADDDEF)
DEFINES :=$(DEFINES)
LOCAL_LDLIBS = -lOpenSLES -lz -llog -landroid
LOCAL_CPPFLAGS := -D_FILE_OFFSET_BITS=64 -DDEBUG -D__ANDROID__
LOCAL_CFLAGS = -DFIXED_POINT -DEXPORT="" -g -O0 -fexceptions -funroll-loops -UHAVE_CONFIG_H -I../../libraries
include $(BUILD_SHARED_LIBRARY)
####
####
#### now build older vhcjnilib for lollipop and older
####
####
#####################################
############## libavcodec_lollipop ##############
include $(CLEAR_VARS)
LOCAL_MODULE := libavcodec_lollipop
LOCAL_SRC_FILES := ../../../../lib/third-party/arm-android/libavcodec_lollipop.so
include $(PREBUILT_SHARED_LIBRARY)
#####################################
############## libavutil_lollipop ##############
include $(CLEAR_VARS)
LOCAL_MODULE := libavutil_lollipop
LOCAL_SRC_FILES := ../../../../lib/third-party/arm-android/libavutil_lollipop.so
include $(PREBUILT_SHARED_LIBRARY)
#####################################
############## libswscale_lollipop ##############
include $(CLEAR_VARS)
LOCAL_MODULE := libswscale_lollipop
LOCAL_SRC_FILES := ../../../../lib/third-party/arm-android/libswscale_lollipop.so
include $(PREBUILT_SHARED_LIBRARY)
#####################################
############## libs ############
include $(CLEAR_VARS)
LOCAL_MODULE := vhc_jnilib_lollipop
LOCAL_SRC_FILES := video_codec_jni.cpp \
MyBaseThread.cc \
MicMonitor.cpp \
framework.cpp \
GabrielJni.cpp
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/../../../libraries/ \
$(LOCAL_PATH)/../../../libraries/thirdparty/
LOCAL_STATIC_LIBRARIES := \
libGabObjs \
libssl \
libcrypto \
libjpeg \
libspeex \
libspeexdsp
LOCAL_SHARED_LIBRARIES := \
libavcodec_lollipop libavutil_lollipop libswscale_lollipop
A_DEFINES := -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -D__ANDROID__ -DDEBUG $(ADDDEF)
DEFINES :=$(DEFINES)
LOCAL_LDLIBS = -lOpenSLES -lz -llog -landroid
LOCAL_CPPFLAGS := -D_FILE_OFFSET_BITS=64 -DDEBUG -D__ANDROID__
LOCAL_CFLAGS = -DFIXED_POINT -DEXPORT="" -g -fexceptions -funroll-loops -UHAVE_CONFIG_H -I../../libraries
include $(BUILD_SHARED_LIBRARY)
Application.mk:
APP_STL := stlport_static
APP_PLATFORM := android-10
APP_ABI := armeabi-v7a
APP_OPTIM := debug
My build.gradle file:
//////////////////////////////////////////////////////////////////////////////
// need this for password dialog
import groovy.swing.SwingBuilder
buildscript {
System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true'
repositories {
jcenter()
}
dependencies {
// Current Gradle version.
final GradleVersion gradleVersion = GradleVersion.current()
// Gradle version 3.0+ requires a different classpath
final GradleVersion gradle3 = GradleVersion.version('3.0')
// Compare versions.
if (gradleVersion >= gradle3) {
println "Your Gradle version is at least 3.0"
classpath 'com.android.tools.build:gradle:2.2.0'
} else {
println "Your Gradle version is older than 3.0"
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
}
apply plugin: 'com.android.application'
android {
lintOptions {
disable 'LongLogTag','ProtectedPermissions','AppLinksAutoVerifyError','MangledCRLF'
}
defaultConfig {
applicationId "com.mycompany.myapp.myclass"
}
compileSdkVersion 23
buildToolsVersion "23.0.2"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
signingConfigs {
release {
// We can leave these in environment variables
storeFile file(String.valueOf(System.getenv("PKCS12_FILE")))
keyAlias "mykey"
// These two lines make gradle believe that the signingConfigs
// section is complete. Without them, tasks like installRelease
// will not be available!
storePassword "notYourRealPassword"
keyPassword "notYourRealPassword"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
debug {
debuggable true
jniDebuggable true
}
}
}
dependencies {
compile 'com.android.support:support-v4:23.1.1'
compile 'com.google.android.gms:play-services:8.4.0'
}
task askForPasswords {
doLast {
def pw = ''
if(System.console() == null) {
new SwingBuilder().edt {
dialog(modal: true, title: 'Enter password', alwaysOnTop: true, resizable: false, locationRelativeTo: null, pack: true, show: true) {
vbox { // Put everything below each other
label(text: "Signing the APK...Enter the keystore password:")
def input1 = passwordField()
button(defaultButton: true, text: 'OK', actionPerformed: {
pw = new String(input1.password);
dispose();
})
}
}
}
} else {
// Must create String because System.readPassword() returns char[]
// (and assigning that below fails silently)
pw = new String(System.console().readPassword("Keystore password: "))
}
android.signingConfigs.release.storePassword = pw
android.signingConfigs.release.keyPassword = pw
}
}
tasks.whenTaskAdded { theTask ->
if (theTask.name.equals("packageRelease")) {
theTask.dependsOn "askForPasswords"
}
}
task getVersion() {
println GradleVersion.current().getVersion()
}
I am trying to extend this project, but it has been built using ANT and these days we are using Android Studio and Gradle in practice. I want to move it on Android Studio for further implementations. So here's my project structure...
app/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "tum.andrive"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi", "armeabi-v7a"
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/cpp']
}
}
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.3.1'
compile project(':opencv')
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.4.1)
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp )
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
SET(OpenCV_DIR $ENV{OPENCVSDK}/native/jni)
message(STATUS "opencv found: ${OpenCV_LIBS}")
include_directories( ${OpenCV_DIR}/include/)
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#OpenCv
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
include $(OPENCVSDK)/native/jni/OpenCV.mk
LOCAL_MODULE := AndriveNative
LOCAL_SRC_FILES := native-lib.cpp
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_LIBRARY)
But getting error while building project, have a look on this...
Message View
Gradle Console
D:\Android\workspace\Local\Andrive\app\.externalNativeBuild\cmake\debug\armeabi
--target
native-lib
jvmArgs :
Starting process 'command 'Z:\Android\sdk\cmake\3.6.4111459\bin\cmake.exe''. Working directory: D:\Android\workspace\Local\Andrive\app Command: Z:\Android\sdk\cmake\3.6.4111459\bin\cmake.exe --build D:\Android\workspace\Local\Andrive\app\.externalNativeBuild\cmake\debug\armeabi --target native-lib
Successfully started process 'command 'Z:\Android\sdk\cmake\3.6.4111459\bin\cmake.exe''
[1/1] Linking CXX shared library ..\..\..\..\build\intermediat
es\cmake\debug\obj\armeabi\libnative-lib.so
FAILED: cmd.exe /C "cd . && Z:\Android\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv5te-none-linux-androideabi --gcc-toolchain=Z:/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 --sysroot=Z:/Android/sdk/ndk-bundle/sysroot -fPIC -isystem Z:/Android/sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=14 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -frtti -fexceptions -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a --sysroot Z:/Android/sdk/ndk-bundle/platforms/android-14/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\armeabi\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -llog -lm "Z:/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/libgnustl_static.a" "-latomic" && cd ."
D:\Android\workspace\Local\Andrive\app\src\main\cpp/native-lib.cpp:27: error: undefined reference to 'DetectionBasedTracker::Parameters::Parameters()'
D:\Android\workspace\Local\Andrive\app\src\main\cpp/native-lib.cpp:30: error: undefined reference to 'DetectionBasedTracker::DetectionBasedTracker(std::string const&, DetectionBasedTracker::Parameters const&)'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o(.ARM.extab.text.Java_tum_andrive_DetectionBasedTracker_nativeCreateObject+0xe4): error: undefined reference to 'typeinfo for cv::Exception'
D:\Android\workspace\Local\Andrive\app\src\main\cpp/native-lib.cpp:54: error: undefined reference to 'DetectionBasedTracker::getParameters()'
D:\Android\workspace\Local\Andrive\app\src\main\cpp/native-lib.cpp:56: error: undefined reference to 'DetectionBasedTracker::setParameters(DetectionBasedTracker::Parameters const&)'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o(.ARM.extab.text.Java_tum_andrive_DetectionBasedTracker_nativeSetDetectionSize+0xa4): error: undefined reference to 'typeinfo for cv::Exception'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o(.ARM.extab.text.Java_tum_andrive_DetectionBasedTracker_nativeDestroyObject+0xa4): error: undefined reference to 'typeinfo for cv::Exception'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o(.ARM.extab.text.Java_tum_andrive_DetectionBasedTracker_nativeStart+0xa4): error: undefined reference to 'typeinfo for cv::Exception'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:188: error: undefined reference to 'cv::_OutputArray::_OutputArray(cv::Mat&)'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:188: error: undefined reference to 'cv::Mat::copyTo(cv::_OutputArray const&) const'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:298: error: undefined reference to 'cv::Mat::copySize(cv::Mat const&)'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:27
8: error: undefined reference to 'cv::fastFree(void*)'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:367: error: undefined reference to 'cv::Mat::deallocate()'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
:app:externalNativeBuildDebug FAILED
:app:externalNativeBuildDebug (Thread[Daemon worker Thread 2,5,main]) completed. Took 8.011 secs.
:app:buildInfoGeneratorDebug (Thread[Daemon worker Thread 2,5,main]) started.
:app:buildInfoGeneratorDebug
Putting task artifact state for task ':app:buildInfoGeneratorDebug' into context took 0.0 secs.
Executing task ':app:buildInfoGeneratorDebug' (up-to-date check took 0.0 secs) due to:
Task has not declared any outputs.
:app:buildInfoGeneratorDebug (Thread[Daemon worker Thread 2,5,main]) completed. Took 0.018 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing process Z:\Android\sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build D:\Android\workspace\Local\Andrive\app\.externalNativeBuild\cmake\debug\armeabi --target native-lib}
[1/1] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\armeabi\libnative-lib.so
FAILED: cmd.exe /C "cd . && Z:\Android\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv5te-none-linux-androideabi --gcc-toolchain=Z:/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 --sysroot=Z:/Android/sdk/ndk-bundle/sysroot -fPIC -isystem Z:/Android/sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=14 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -frtti -fexceptions -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a --sysroot Z:/Android/sdk/ndk-bundle/platforms/android-14/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\armeabi\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -llog -lm "Z:/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/libgnustl_static.a" "-latomic" && cd ."
D:\Android\workspace\Local\Andrive\app\src\main\cpp/native-lib.cpp:27: error: undefined reference to 'DetectionBasedTracker::Parameters::Parameters()'
D:\Android\workspace\Local\Andrive\app\src\main\cpp/native-lib.cpp:30: error: undefined reference to 'DetectionBasedTracker::DetectionBasedTracker(std::string const&, DetectionBasedTracker::Parameters const&)'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o(.ARM.extab.text.Java_tum_andrive_DetectionBasedTracker_nativeCreateObject+0xe4): error: undefined reference to 'typeinfo for cv::Exception'
D:\Android\workspace\Local\Andrive\app\src\main\cpp/native-lib.cpp:54: error: undefined reference to 'DetectionBasedTracker::getParameters()'
D:\Android\workspace\Local\Andrive\app\src\main\cpp/native-lib.cpp:56: error: undefined reference to 'DetectionBasedTracker::setParameters(DetectionBasedTracker::Parameters const&)'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o(.ARM.extab.text.Java_tum_andrive_DetectionBasedTracker_nativeSetDetectionSize+0xa4): error: undefined reference to 'typeinfo for cv::Exception'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o(.ARM.extab.text.Java_tum_andrive_DetectionBasedTracker_nativeDestroyObject+0xa4): error: undefined reference to 'typeinfo for cv::Exception'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o(.ARM.extab.text.Java_tum_andrive_DetectionBasedTracker_nativeStart+0xa4): error: undefined reference to 'typeinfo for cv::Exception'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:188: error: undefined reference to 'cv::_OutputArray::_OutputArray(cv::Mat&)'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:188: error: undefined reference to 'cv::Mat::copyTo(cv::_OutputArray const&) const'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:298: error: undefined reference to 'cv::Mat::copySize(cv::Mat const&)'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:278: error: undefined reference to 'cv::fastFree(void*)'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:367: error: undefined reference to 'cv::Mat::deallocate()'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Anybody please help me to setup this project!
After a lot of searching, I've found this project. So many thanks to Adrien Lescourt. This demo project describes how we can use OpenCV with Android Studio & Gradle. Problem was with jniLibs directory and CMakeLists.txt file. Here's the correct version...
app/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "tum.andrive"
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a"
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'mips64'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.3.1'
compile project(':opencv')
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.4.1)
# OpenCV stuff
include_directories(D:\\Android\\OpenCV-2.4.10-android-sdk\\sdk\\native\\jni\\include)
add_library( lib_opencv SHARED IMPORTED )
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libopencv_java.so)
add_library( native-lib
SHARED
src/main/cpp/native-lib.cpp )
find_library( log-lib
log )
target_link_libraries( native-lib
lib_opencv
${log-lib} )
And at last I've added jniLibs folder to app and copied all .so files in this folder stored in OpenCV-2.4.10-android-sdk/sdk/native/libs.
I hope this solution will help people to setup OpenCV with gradle. Please comment if any other information required.
Thanks
I'm having trouble using native OpenCv 3.0.0 with Android Studio 2.2, with new ndk support i.e usin CMAKE build script. Below is the error which i am getting.Am i missing any thing in my gradle or cmake file? Please let me know.
Error:FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
Build command failed.
Error while executing 'C:\Users\User\AppData\Local\Android\sdk\cmake\3.6.3155560\bin\cmake.exe' with arguments {--build E:\OpenCvAndroid\OPecvTry2CSupport\app.externalNativeBuild\cmake\debug\mips64 --target native-lib}
[1/1] Linking CXX shared library ..\obj\mips64\libnative-lib.so
FAILED: cmd.exe /C "cd . && C:\Users\User\AppData\Local\Android\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe -target mips64el-none-linux-android -gcc-toolchain C:/Users/User/AppData/Local/Android/sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/windows-x86_64 --sysroot=C:/Users/User/AppData/Local/Android/sdk/ndk-bundle/platforms/android-21/arch-mips64 -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -O0 -fno-limit-debug-info -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ..\obj\mips64\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -llog -lm "C:/Users/User/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/mips64/libgnustl_static.a" && cd ."
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o: In function ~Mat':
E:/OpenCVSdk/sdk/native/jni/include\opencv2/core/mat.hpp:278: undefined reference tocv::fastFree(void*)'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o: In function cv::Mat::release()':
E:/OpenCVSdk/sdk/native/jni/include\opencv2/core/mat.hpp:367: undefined reference tocv::Mat::deallocate()'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
And my Cmake.txt
cmake_minimum_required(VERSION 3.4.1)
add_library( native-lib
SHARED
src/main/cpp/native-lib.cpp )
include_directories(E\:\\OpenCVSdk\\sdk\\native\\jni\\include )
find_library( log-lib log )
target_link_libraries(native-lib ${log-lib} )
And my Gradle Build file
{ apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "viki.opecvtry2csupport"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
}
I fixed my problem by add "lib_opencv" lib to target_link_libraries
target_link_libraries(
native-lib lib_opencv #Just add the lib_opencv
${log-lib} )
don't forget to Link Gradle to your native library
my full CMakeList.txt
cmake_minimum_required(VERSION 3.4.1)
add_library( native-lib
SHARED
src/main/cpp/native-lib.cpp )
find_library( log-lib
log )
target_link_libraries(native-lib lib_opencv
${log-lib} )
set(CMAKE_VERBOSE_MAKEFILE on)
add_library(lib_opencv SHARED IMPORTED)
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION /PROJECT_PATH/openCVLibrary320/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)
include_directories(/OpenCV-android-sdk/sdk/native/jni/include)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
Setting OpenCV_DIR has worked for me with OpenCV 3.1 and AS 2.2 and the latest Gradle plugin. This is the relevant bit of my CMakeLists.txt.
cmake_minimum_required(VERSION 3.6)
SET(OpenCV_DIR $ENV{HOME}/AndroidDevelopment/opencv-3.1.0/sdk/native/jni)
find_package(OpenCV REQUIRED)
message(STATUS "opencv found: ${OpenCV_LIBS}")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
${OpenCV_DIR}/include/)
[...]
target_link_libraries(myTarget log ${OpenCV_LIBS} m z android )
I know there was a lot of similar topics but none of them helped and belive I'm trying to run this for over 2 days.
I want to run face detection sample and I'm stuck on ndk build
Application.mk
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-23
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include C:/Users/dpach/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_SRC_FILES := DetectionBasedTracker_jni.cpp
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_LDLIBS += -llog -ldl
LOCAL_MODULE := detection_based_tracker
include $(BUILD_SHARED_LIBRARY)
app.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "threewe.testopencv"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [] //disable automatic ndk-build call
}
task ndkBuild(type: Exec) {
commandLine 'C:\\Users\\dpach\\android-ndk-r12\\ndk-build.cmd', '-C', file('jni').absolutePath
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha2'
compile project(':libraries:opencv')
}
error
System nie moľe odnale«† okre?lonej ?cieľki.
make: *** [C:/Users/dpach/AndroidStudioProjects/TestOpenCv/app/obj/local/armeabi-v7a/objs/detection_based_tracker/DetectionBasedTracker_jni.o] Error 1
make: Leaving directory `C:/Users/dpach/AndroidStudioProjects/TestOpenCv/app/jni'
:app:ndkBuild FAILED
Error:Execution failed for task ':app:ndkBuild'.
> Process 'command 'C:\Users\dpach\android-ndk-r12\ndk-build.cmd'' finished with non-zero exit value 2
Translation of the error: 'System cannot find specified path'
I've checked the path and it exists I even put there file from another project but the result is the same. I've tried also to run ndk-build.cmd manualy from the console but the result is the same so this is not Android Studio issue. I have no idea what more I can do :(
// EDIT
added V=1 parameter
make: Entering directory `C:/Users/dpach/AndroidStudioProjects/TestOpenCv/app/jni'
[armeabi-v7a] "Compile++ thumb": "detection_based_tracker <= DetectionBasedTracker_jni.cpp"
C:/Users/dpach/android-ndk-r12/build//../toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++ -MMD -MP -MF C:/Users/dpach/AndroidStudioProjects/TestOpenCv/app/obj/local/armeabi-v7a/objs/detection_based_tracker/DetectionBasedTracker_jni.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -g -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -fno-exceptions -fno-rtti -mthumb -Os -DNDEBUG -I"C:/Users/dpach/OpenCV-android-sdk/sdk/native/jni/include/opencv" -I"C:/Users/dpach/OpenCV-android-sdk/sdk/native/jni/include" -IC:/Users/dpach/AndroidStudioProjects/TestOpenCv/app/jni -IC:/Users/dpach/android-ndk-r12/build//../sources/cxx-stl/gnu-libstdc++/4.9/include -IC:/Users/dpach/android-ndk-r12/build//../sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -IC:/Users/dpach/android-ndk-r12/build//../sources/cxx-stl/gnu-libstdc++/4.9/include/backward -IC:/Users/dpach/AndroidStudioProjects/TestOpenCv/app/jni -DANDROID -fPIC -DANDROID -fsigned-char -Wa,--noexecstack -Wformat -Werror=format-security -frtti -fexceptions -isystem C:/Users/dpach/android-ndk-r12/build//../platforms/android-23/arch-arm/usr/include -c C:/Users/dpach/AndroidStudioProjects/TestOpenCv/app/jni/DetectionBasedTracker_jni.cpp -o C:/Users/dpach/AndroidStudioProjects/TestOpenCv/app/obj/local/armeabi-v7a/objs/detection_based_tracker/DetectionBasedTracker_jni.o
This is a bug on the download page of NDK, see the issue yours truly opened.
You can use the wiki page on GitHub that is updated more frequently.
In your specific case, your are using 32-bit version on your 64-bit Windows, which is suboptimal. You can download the latest stable version r12b for your OS.