ndk-build.cmd failed during compilation (opencv face detect) - 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.

Related

android studio with opencv libraries linking error

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.

Android NDK: unable load arm64-v8a on 64bit device

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 ?

Undefined reference when calling a OpenCL function in Android

I am trying to set a simple project in Android Studio with OpenCL. So I created a new project with NDK support and an empty activity. I have copied the libOpenCL.so from my mobile phone to the folder app\src\main\jniLibs\arm8 and I have downloaded the OpenCL headers from the Khronos webpage and copied them to app\src\main\jni\CL. Furthermore, I have done two modifications to the build.gradle file, I have added a parameter to the cppFlags to include the OpenCL folder and I have set an abi filter to build only for arm8. I copy my build.gradle file here:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "es.um.mompes.testopencl"
minSdkVersion 22
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -fexceptions -I${projectDir}/src/main/jni"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
productFlavors {
arm8 {
ndk {
abiFilter "arm64-v8a"
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
I have also added a three lines to the generated native-lib.cpp file to test if OpenCL is working. This is my native-lib.cpp:
#include <jni.h>
#include <string>
#include <CL/cl.h>
extern "C"
JNIEXPORT jstring JNICALL
Java_es_um_mompes_testopencl_MainActivity_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello from C++";
cl_int err;
// Find the number of OpenCL platforms
cl_uint num_platforms;
err = clGetPlatformIDs(0, NULL, &num_platforms);
return env->NewStringUTF(hello.c_str());
}
However, I must be missing something because I am getting an undefined reference error regarding the OpenCL function when I build the project. This is the complete error:
Execution failed for task ':app:externalNativeBuildArm8Debug'.
Build command failed.
Error while executing process C:\Users\Juan\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build C:\Users\Juan\AndroidStudioProjects\TestOpenCL\app.externalNativeBuild\cmake\arm8Debug\arm64-v8a --target native-lib}
[1/1] Linking CXX shared library ........\build\intermediates\cmake\arm8\debug\obj\arm64-v8a\libnative-lib.so
FAILED: cmd.exe /C "cd . && C:\Users\Juan\AppData\Local\Android\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=aarch64-none-linux-android --gcc-toolchain=C:/Users/Juan/AppData/Local/Android/sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/windows-x86_64 --sysroot=C:/Users/Juan/AppData/Local/Android/sdk/ndk-bundle/sysroot -fPIC -isystem C:/Users/Juan/AppData/Local/Android/sdk/ndk-bundle/sysroot/usr/include/aarch64-linux-android -D__ANDROID_API__=22 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -fexceptions -IC:\Users\Juan\AndroidStudioProjects\TestOpenCL\app/src/main/jni -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a --sysroot C:/Users/Juan/AppData/Local/Android/sdk/ndk-bundle/platforms/android-22/arch-arm64 -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\arm8\debug\obj\arm64-v8a\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -llog -lm "C:/Users/Juan/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/libgnustl_static.a" && cd ."
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o: In function Java_es_um_mompes_testopencl_MainActivity_stringFromJNI':
C:\Users\Juan\AndroidStudioProjects\TestOpenCL\app\src\main\cpp/native-lib.cpp:14: undefined reference toclGetPlatformIDs'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
Do you know what am I missing? I've searching for a few hours over the last two days about how to setup OpenCL in Android Studio but everything I find seems to be outdated and doesn't seem to work for my problem.
Look for Android.mk under jni folder. Then add this:
LOCAL_PATH := $(call my-dir) // should already be there
.
.
LOCAL_LDLIBS := $(LOCAL_PATH)/libOpenCL.so
This example takes the libOpenCL.so from the jni root but you can change this for your needs.
Reference: Getting Started with OpenCL on Android
I would recommend you replace the automatic Android Studio NDK building with your own so you have total control.
Then you can use #RonTLV answer to add the library to the Android.mk and have a proper build.
Android Studio by default ignores Android.mk and generates its own with all the .c/.cpp files in the jni folder.
sourceSets {
debug.jniLibs.srcDir 'src/main/obj/local' //debug builds have symbols
release.jniLibs.srcDir 'src/main/libs' //release builds have cleaned libraries
main.jni.srcDirs = [] //disable automatic ndk-build call with auto-generated Android.mk
}
// call regular ndk-build script manually
task ndkBuild(type: Exec) {
if (System.properties['os.name'].toLowerCase(Locale.ROOT).contains('windows')) {
commandLine 'ndk-build.cmd', '-j8', '-C', file('src/main').absolutePath
} else {
commandLine 'ndk-build', '-j8', '-C', file('src/main').absolutePath
}
}
//Make the NDK task depend on Java build Task
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}

Gradle is not compiling using ndkBuild

I have an android project configured in eclipse that works good with ant and ndk-build with some customized Android.mk and Application.mk files. I need to move them to Android Studio and I don't want to use CMake that comes with it, so I just want to keep my old .mk files. To do so I started with a simple hello world example with the following code:
Here the native-lib.cpp:
#include <jni.h>
#include <string>
extern "C"
{
jstring Java_com_comscore_android_app_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++ lalalaaaaaa";
return env->NewStringUTF(hello.c_str());
}
}
and here my gradle file:
android {
compileSdkVersion 23
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.comscore"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
ndkBuild {
arguments "NDK_APPLICATION_MK:=src/main/jni/Application.mk"
}
}
}
externalNativeBuild{
ndkBuild{
path "src/main/jni/Android.mk"
}
}
...
}
Here the Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := native-lib.cpp
LOCAL_MODULE := native-lib
LOCAL_LDLIBS := -llog
LOCAL_CPPFLAGS += -fsigned-char -fexceptions -frtti -g -O0 -std=c++0x -std=gnu++0x
LOCAL_CFLAGS += -fsigned-char -fexceptions -frtti -g -O0 -std=c++0x -std=gnu++0x
include $(BUILD_SHARED_LIBRARY)
And finally the Application.mk:
APP_ABI := all
APP_STL := gnustl_static
But the C code is never compiled, could any body help me with this issue?
Thanks!
it was not compiling anything, that was the problem. Now I solved after cleaning up the build folder manually

Trying to use FFMPEG for android. Compiling but still not working

So to start off... Im trying to use ffmpeg to compile an array of images into a video on Android.
I have followed a variety of tutorials online and have gotten as far as being able to compile the lib for Android and still have to project run.
The repo im now using can be found here: https://github.com/Batterii/android-ffmpeg-x264
I made a couple tweaks to the setttings.sh just to correct ndk location. Besides that, I followed the instructions and it seemed to work flawlessly.
After that, I converted the "Project" project into an Android stdio library module.
I am not getting any compile errors, nor am I getting any runtime errors, or any other errors that I can detect... Nothing on logcat... But I am definitely not getting any video called out.mp4.
In an onCreate of a particular activity, I am running this code:
Videokit vk = new Videokit();
vk.run(new String[]{"ffmpeg", "-r", "1/5", "-i", "%d.jpg", "-c:v", "libx264", "-r", "30", "-pix_fmt", "yuv420p", project.getProjectDirectory() + "/out.mp4"});
This command is taken from the command line example found here:
https://trac.ffmpeg.org/wiki/Create%20a%20video%20slideshow%20from%20images
Thank you in advance for anyone taking the time to look through this post... I am pretty baffled at this point, as there are no errors I can find and no video...
Thanks
======================================================================
Update
Turns out it is not actually compiling correctly... but i have found a few things.
here is the make file from the Eclipse version of the project
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := videokit
# These need to be in the right order
FFMPEG_LIBS := $(addprefix ffmpeg/, \
libavdevice/libavdevice.a \
libavformat/libavformat.a \
libavfilter/libavfilter.a \
libavcodec/libavcodec.a \
libswscale/libswscale.a \
libavutil/libavutil.a \
libswresample/libswresample.a \
libpostproc/libpostproc.a )
# ffmpeg uses its own deprecated functions liberally, so turn off that annoying noise
LOCAL_CFLAGS += -g -Iffmpeg -Ivideokit -Wno-deprecated-declarations
LOCAL_LDLIBS += -llog -lz $(FFMPEG_LIBS) x264/libx264.a
LOCAL_SRC_FILES := ffmpeg/cmdutils.c ffmpeg/ffmpeg.c videokit/uk_co_halfninja_videokit_Videokit.c
include $(BUILD_SHARED_LIBRARY)
and here is the make file that gradle is auto-generating for me... thanks to Android Studio...
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := videokit
LOCAL_CFLAGS := -g -Isrc/main/jni/ffmpeg -Isrc/main/jni/videokit -Wno-deprecated-declarations
LOCAL_LDLIBS := \
-lffmpeg/libavformat/libavformat.a \
-lffmpeg/libavcodec/libavcodec.a \
-lffmpeg/libswresample/libswresample.a \
-lffmpeg/libavfilter/libavfilter.a \
-lffmpeg/libpostproc/libpostproc.a \
-lffmpeg/libavdevice/libavdevice.a \
-lx264/libx264.a \
-lffmpeg/libavutil/libavutil.a \
-llog \
-lz \
-lffmpeg/libswscale/libswscale.a \
LOCAL_SRC_FILES := \
Project/Module/src/main/jni/ffmpeg/cmdutils.c \
Project/Module/src/main/jni/ffmpeg/ffmpeg.c \
Project/Module/src/main/jni/videokit/com_t10_project_util_FfmpegHelper.c \
LOCAL_C_INCLUDES += Project/Module/src/main/jni/ffmpeg/cmdutils.c
LOCAL_C_INCLUDES += Project/Module/src/main/jni/ffmpeg/ffmpeg.c
LOCAL_C_INCLUDES += Project/Module/src/main/jni/videokit/com_t10_project_util_FfmpegHelper.c
LOCAL_C_INCLUDES += Project/Module/src/arm/jni
LOCAL_C_INCLUDES += Project/Module/src/debug/jni
LOCAL_C_INCLUDES += Project/Module/src/armDebug/jni
include $(BUILD_SHARED_LIBRARY)
And finally, here is my build.gradle
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
ndk {
moduleName "videokit"
stl "stlport_shared"
ldLibs "log", "z",
"ffmpeg/libavdevice/libavdevice.a",
"ffmpeg/libavformat/libavformat.a",
"ffmpeg/libavfilter/libavfilter.a",
"ffmpeg/libavcodec/libavcodec.a",
"ffmpeg/libswscale/libswscale.a",
"ffmpeg/libavutil/libavutil.a",
"ffmpeg/libswresample/libswresample.a",
"ffmpeg/libpostproc/libpostproc.a",
"x264/libx264.a"
cFlags "-g -Isrc/main/jni/ffmpeg -Isrc/main/jni/videokit -Wno-deprecated-declarations"
}
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = ['src/main/jni/ffmpeg/cmdutils.c',
'src/main/jni/ffmpeg/ffmpeg.c',
'src/main/jni/videokit/com_t10_project_util_FfmpegHelper.c']
}
productFlavors {
x86 {
versionCode Integer.parseInt("6" + defaultConfig.versionCode)
ndk {
abiFilter "x86"
}
}
mips {
versionCode Integer.parseInt("4" + defaultConfig.versionCode)
ndk {
abiFilter "mips"
}
}
armv7 {
versionCode Integer.parseInt("2" + defaultConfig.versionCode)
ndk {
abiFilter "armeabi-v7a"
}
}
arm {
versionCode Integer.parseInt("1" + defaultConfig.versionCode)
ndk {
abiFilter "armeabi"
}
}
fat
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}
As you can see, my build.gradle generates something that is pretty close to the original... but not the same. When i try to run/compile it, gradle spits this out
Executing tasks: [:Project:assembleArmDebug]
:Project:compileArmDebugNdkcc1: warning: Project/Module/src/main/jni/ffmpeg/cmdutils.c: not a directory [enabled by default]
cc1: warning: Project/Module/src/main/jni/ffmpeg/ffmpeg.c: not a directory [enabled by default]
cc1: warning: Project/Module/src/main/jni/videokit/com_t10_project_util_FfmpegHelper.c: not a directory [enabled by default]
In file included from Project/Module/src/main/jni/ffmpeg/cmdutils.c:32:0:
Project/Module/src/main/jni/ffmpeg/libavformat/avformat.h:82:32: fatal error: libavcodec/avcodec.h: No such file or directory
compilation terminated.
make: *** [Project/Module/build/ndk/arm/debug/obj/local/armeabi/objs/videokit/Project/Module/src/main/jni/ffmpeg/cmdutils.o] Error 1
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':Project:compileArmDebugNdk'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
android-ndk-r9d/ndk-build NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=Project/Module/build/ndk/arm/debug/Android.mk APP_PLATFORM=android-19 NDK_OUT=Project/Module/build/ndk/arm/debug/obj NDK_LIBS_OUT=Project/Module/build/ndk/arm/debug/lib APP_STL=stlport_shared APP_ABI=armeabi
Error Code:
2
Output:
cc1: warning: Project/Module/src/main/jni/ffmpeg/cmdutils.c: not a directory [enabled by default]
cc1: warning: Project/Module/src/main/jni/ffmpeg/ffmpeg.c: not a directory [enabled by default]
cc1: warning: Project/Module/src/main/jni/videokit/com_t10_project_util_FfmpegHelper.c: not a directory [enabled by default]
In file included from Project/Module/src/main/jni/ffmpeg/cmdutils.c:32:0:
Project/Module/src/main/jni/ffmpeg/libavformat/avformat.h:82:32: fatal error: libavcodec/avcodec.h: No such file or directory
compilation terminated.
make: *** [Project/Module/build/ndk/arm/debug/obj/local/armeabi/objs/videokit/Project/Module/src/main/jni/ffmpeg/cmdutils.o] Error 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 8.184 secs
I've been messing around with it for a couple hours now and pretty much every time, i get gradle yelling at me about the fact that it can't find some file. I'm beginning to think that maybe it is because my LOCAL_LDLIBS aren't in the same order as the original...? Im not entirely sure... Does anyone else have any ideas...?

Categories

Resources