I'm building a simple video app and want to embed a watermark on the recorded videos. I am using ffmpeg for this process and have successfully compiled it. The issue is when I try to link it with my project in Android Studio using ndk-build.cmd command, it gives me the following error:
C:\Users\MyPC\AppData\Local\Temp\ccIRLDZn.s: Assembler messages:
C:\Users\MyPC\AppData\Local\Temp\ccIRLDZn.s:8547: Error: unknown mnemonic `itt' -- `itt gt'
C:\Users\MyPC\AppData\Local\Temp\ccIRLDZn.s:8548: Error: unknown mnemonic `movgt' -- `movgt x25,x0'
C:\Users\MyPC\AppData\Local\Temp\ccIRLDZn.s:8549: Error: unknown mnemonic `movgt' -- `movgt x0,x1'
C:\Users\MyPC\AppData\Local\Temp\ccIRLDZn.s:8551: Error: unknown mnemonic `it' -- `it le'
C:\Users\MyPC\AppData\Local\Temp\ccIRLDZn.s:8552: Error: unknown mnemonic `movle' -- `movle x0,x2'
C:\Users\MyPC\AppData\Local\Temp\ccIRLDZn.s:8554: Error: unknown mnemonic `it' -- `it gt'
C:\Users\MyPC\AppData\Local\Temp\ccIRLDZn.s:8555: Error: unknown mnemonic `movgt' -- `movgt x25,x0'
make: *** [obj/local/arm64-v8a/objs/myProject_Videokit/ffmpeg.o] Error 1
My development environment is
OS : Windows10 x86_64
Command line : Cygwin 64bit
Android NDK version : android-ndk-r11c
ffmpeg version : ffmpeg-3.0.2
Android Studio : 2.1.1
First, I installed Cygwin64bit and added 'make', 'dos2unix', 'c++ gcc' packages. And I decompressed ffmpeg folder in C:/android-ndk-r11c/sources. This is the build script I used.
config.sh
#!/bin/bash
NDK=C:/android-ndk-r11c
SYSROOT=$NDK/platforms/android-9/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64
#I used cygpath to avoid path errors in Cygwin.
CUR="$(cygpath -m "$(pwd)")"
TEMPDIR="$(cygpath -m "/tmp")"
TMP="$(cygpath -m "/tmp")"
TMPDIR="$(cygpath -m "/tmp")"
CPU=arm
PREFIX=$CUR/android/$CPU
ADDI_CFLAGS="-marm"
./configure
--prefix=$PREFIX
--enable-shared
--disable-static
--disable-doc
--disable-ffmpeg
--disable-ffplay
--disable-ffprobe
--disable-ffserver
--disable-doc
--disable-symver
--enable-protocol=concat
--enable-protocol=file
--enable-muxer=mp4
--enable-demuxer=mpegts
--enable-memalign-hack
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi-
--target-os=linux
--arch=arm
--enable-cross-compile
--sysroot=$SYSROOT
--extra-cflags="-Os -fpic $ADDI_CFLAGS"
--extra-ldflags="$ADDI_LDFLAGS"
$ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install
I ran this .sh in Cygwin(as administrator) but it didn't work. So I typed each of those lines on Cygwin and it compiled successfully. I tried both --target-os=android and --target-os=linux, but both didn't solve the problem above.
Then I followed this tutorial (enoent.fr/blog/2014/06/20/compile-ffmpeg-for-android/). Based on that, I made a native method in my project and built header file and c file.(To do that, I followed this video. youtube.com/watch?v=kFtxo7rr2HQ)
After that, I cloned this repo(github.com/HikoQiu/JNI_INVOKE_FFMPEG) and copied - pasted the jni folder into my project. And after making the Android.mk and Application.mk, I ran the C:/android-ndk-r11c/ndk-build.cmd in the Android Studio terminal and it gave me the error above.
These are the Makefiles I used.
myProject/app/src/main/jni/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := com_example_project_Videokit
LOCAL_LDLIBS := -llog -ljnigraphics -lz
LOCAL_CFLAGS := -Wdeprecated-declarations
ANDROID_LIB := -landroid
LOCAL_C_INCLUDES := C:\android-ndk-r11c\sources\ffmpeg-3.0.2
LOCAL_SRC_FILES := com_example_project_Videokit.c ffmpeg.c ffmpeg_filter.c ffmpeg_opt.c cmdutils.c
LOCAL_SHARED_LIBRARIES := libavformat libavcodec libswscale libavutil
include $(BUILD_SHARED_LIBRARY)
$(call import-module,ffmpeg-3.0.2/android/arm)
myProject/app/src/main/jni/Application.mk
APP_ABI := all
C:/android-ndk-r11c/sources/ffmpeg-3.0.2/android/arm/Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= libavcodec
LOCAL_SRC_FILES:= lib/libavcodec-57.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= libavformat
LOCAL_SRC_FILES:= lib/libavformat-57.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= libswscale
LOCAL_SRC_FILES:= lib/libswscale-4.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= libavutil
LOCAL_SRC_FILES:= lib/libavutil-55.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= libavfilter
LOCAL_SRC_FILES:= lib/libavfilter-6.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= libwsresample
LOCAL_SRC_FILES:= lib/libswresample-2.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
And this is my project structure so far. com_example_myProjct.c is the file that I used as a moduleName in build.gradle file and as LOCAL_MODULE in Android.mk .
app
- build
- libs
- src
- androidTest
- main
- java
-com.example.myProject
-MainActivity
-Videokit //this is the class where I called the native method.
- jni
-Android.mk
-Application.mk
-cmdutils.c
-cmdutils.h
-com_example_myProject.c
-com_example_myProject.h
-ffmpeg.c
-ffmpeg.h
-ffmpeg_filter.c
-ffmpeg_opt.c
-ffmpeg_opt.h
-logjam.h
- obj
- res
AndroidManifest.xml
- test
app/gradle.build
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.myProjct"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0.0"
ndk {
moduleName "com_example_myProjet_Videokit"
}
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir 'src/main/libs'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-rules.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
}
Any ideas?
As the last line of your compilation error report says:
make: *** [obj/local/arm64-v8a/objs/myProject_Videokit/ffmpeg.o] Error 1
It's the key. You're trying to build your application for all available ABI's. As I can see your build.gradle file, there's no abiFilter. I'd do it in a next manner (I'm not sure with syntax, but the):
android {
...
ndk {
moduleName "com_example_myProjet_Videokit"
abiFilters = "x86", "armeabi"
}
...
}
If I were you, I'd use gradle-experimental plugin, prebuild ffmpeg libs for all needed ABI's, and then use this approach to load the libraries.
So the main problem - you have one library for all ABI's. It's incorrect.
Related
*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'm new with Android so I don't fully understand how to make Android.mk files.
My project was running fine, following a tutorial online where the Android.mk was provided. But later on I needed to add a missing library and the tutorial for that had another Android.mk, now I'm trying to merge the two together.
Here is my Android.mk :
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#opencv
OPENCVROOT:= C:\OpenCV-2.4.10-android-sdk
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk
LOCAL_SRC_FILES := com_example_adrien_ndkopencvtest4_OpencvNativeClass.cpp
LOCAL_LDLIBS += -llog
LOCAL_MODULE := MyOpencvLibs
include $(BUILD_SHARED_LIBRARY)
Here is the Android.mk I need to add :
LOCAL_PATH := $(call my-dir)
OPENCV_PATH := D:/CODE/OpenCV-2.4.10-android-sdk/sdk/native/jni
include $(CLEAR_VARS)
LOCAL_MODULE := nonfree
LOCAL_SRC_FILES := libnonfree.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
OPENCV_INSTALL_MODULES := on
OPENCV_CAMERA_MODULES := off
include $(OPENCV_PATH)/OpenCV.mk
LOCAL_C_INCLUDES := \
$(LOCAL_PATH) \
$(OPENCV_PATH)/include
LOCAL_SRC_FILES := \
nonfree_jni.cpp
LOCAL_MODULE := nonfree_demo
LOCAL_CFLAGS := -Werror -O3 -ffast-math
LOCAL_LDLIBS := -llog -ldl
LOCAL_SHARED_LIBRARIES += nonfree
include $(BUILD_SHARED_LIBRARY)
What I'm interested in in the last Android.mk is the libnonfree.so only, I don't need the cpp file.
Here is the structure of my project :
EDIT :
Thanks for your answers. I've done what was suggested and my Android.mk looks like that now :
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#opencv
OPENCVROOT:= C:\OpenCV-2.4.10-android-sdk
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk
LOCAL_SRC_FILES := com_example_adrien_ndkopencvtest4_OpencvNativeClass.cpp
LOCAL_LDLIBS += -llog
LOCAL_SHARED_LIBRARIES += nonfree
LOCAL_MODULE := MyOpencvLibs
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := nonfree
LOCAL_SRC_FILES := libnonfree.so
include $(PREBUILT_SHARED_LIBRARY)
But the problem remains. I've got "Undefined reference" to methods libnonfree.so should add. I assumed the problem was from the Android.mk but maybe it's from elsewhere then.
I've added System.loadLibrary("nonfree"); to my MainACtivity and
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/nonfree/features2d.hpp"
I don't know what I'm doing wrong.
EDIT 2 :
Here is the error :
Application.mk :
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-16
I didn't know where to set arguments="V=1" in my build.gradle
My build.gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.adrien.ndkopencvtest4"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets.main {
//jniLibs.srcDirs = ['src/main/jniLibs']
jni.srcDirs = [] //disable automatic ndk-build call
}
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
commandLine "C:/Users/Adrien/AppData/Local/Android/sdk/ndk-bundle/ndk-build.cmd",
'NDK_PROJECT_PATH=build/intermediates/ndk',
'NDK_LIBS_OUT=src/main/jniLibs',
'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
'NDK_APPLICATION_MK=src/main/jni/Application.mk'
}
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')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.github.wseemann:FFmpegMediaMetadataRetriever-armeabi-v7a:1.0.14'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile project(':openCVLibrary2410')
}
EDIT 3 :
Results of "ndk-build V=1" :
C:\Users\Adrien\AndroidStudioProjects\NDKOpencvTest4\app\src\main\jni>ndk-build V=1
[armeabi-v7a] SharedLibrary : libMyOpencvLibs.so
C:/Users/Adrien/AppData/Local/Android/sdk/ndk-bundle/build//../toolchains/llvm/preb
uilt/windows-x86_64/bin/clang++.exe -Wl,-soname,libMyOpencvLibs.so -shared --sysroo
t=C:/Users/Adrien/AppData/Local/Android/sdk/ndk-bundle/build//../platforms/android-
16/arch-arm C:/Users/Adrien/AndroidStudioProjects/NDKOpencvTest4/app/src/main/obj/l
ocal/armeabi-v7a/objs/MyOpencvLibs/com_example_adrien_ndkopencvtest4_OpencvNativeCl
ass.o C:/Users/Adrien/AppData/Local/Android/sdk/ndk-bundle/build//../sources/cxx-st
l/gnu-libstdc++/4.9/libs/armeabi-v7a/libgnustl_static.a -lgcc C:/Users/Adrien/Andro
idStudioProjects/NDKOpencvTest4/app/src/main/obj/local/armeabi-v7a/libopencv_java.s
o C:/Users/Adrien/AndroidStudioProjects/NDKOpencvTest4/app/src/main/obj/local/armea
bi-v7a/libnonfree.so -gcc-toolchain C:/Users/Adrien/AppData/Local/Android/sdk/ndk-
bundle/build//../toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 -no-c
anonical-prefixes -target armv7-none-linux-androideabi -Wl,--fix-cortex-a8 -Wl,--b
uild-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-sh
ared-textrel -Wl,--fatal-warnings -LC:/Users/Adrien/AppData/Local/Android/sdk/ndk
-bundle/build//../platforms/android-16/arch-arm/usr/lib -llog -lc -lm -o C:/Users/A
drien/AndroidStudioProjects/NDKOpencvTest4/app/src/main/obj/local/armeabi-v7a/libMy
OpencvLibs.so
C:/Users/Adrien/AndroidStudioProjects/NDKOpencvTest4/app/src/main/jni/com_example_a
drien_ndkopencvtest4_OpencvNativeClass.cpp:214: error: undefined reference to 'cv::
SURF::SURF(double, int, int, bool, bool)'
C:/Users/Adrien/AndroidStudioProjects/NDKOpencvTest4/app/src/main/jni/com_example_a
drien_ndkopencvtest4_OpencvNativeClass.cpp:222: error: undefined reference to 'cv::
SURF::SURF()'
C:/Users/Adrien/AndroidStudioProjects/NDKOpencvTest4/app/src/main/jni/com_example_a
drien_ndkopencvtest4_OpencvNativeClass.cpp:204: error: undefined reference to 'VTT
for cv::SURF'
C:/Users/Adrien/AndroidStudioProjects/NDKOpencvTest4/app/src/main/jni/com_example_a
drien_ndkopencvtest4_OpencvNativeClass.cpp:204: error: undefined reference to 'VTT
for cv::SURF'
C:/Users/Adrien/AndroidStudioProjects/NDKOpencvTest4/app/src/main/jni/com_example_a
C:/Users/Adrien/AndroidStudioProjects/NDKOpencvTest4/app/src/main/jni/com_example_adrien_ndkopencvtest4_OpencvNativeClass.cpp:204: error: undefined
reference to 'VTT for cv::SURF'
C:/Users/Adrien/AndroidStudioProjects/NDKOpencvTest4/app/src/main/jni/com_example_adrien_ndkopencvtest4_OpencvNativeClass.cpp:449: error: undefined
reference to 'cv::SURF::SURF(double, int, int, bool, bool)'
C:/Users/Adrien/AndroidStudioProjects/NDKOpencvTest4/app/src/main/jni/com_example_adrien_ndkopencvtest4_OpencvNativeClass.cpp:457: error: undefined
reference to 'cv::SURF::SURF()'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [C:/Users/Adrien/AndroidStudioProjects/NDKOpencvTest4/app/src/main/obj/local/armeabi-v7a/libMyOpencvLibs.so] Error 1
SOLUTION :
My libnonfree.so file was not correct, I downloaded another one. I also changed my Application.mk file to :
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-16
If you want to add a prebuilt shared library to your project, you don't need a separate Android.mk
Let's take your script,
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#opencv
OPENCVROOT:= C:\OpenCV-2.4.10-android-sdk
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk
LOCAL_SRC_FILES := com_example_adrien_ndkopencvtest4_OpencvNativeClass.cpp
LOCAL_LDLIBS += -llog
LOCAL_MODULE := MyOpencvLibs
include $(BUILD_SHARED_LIBRARY)
and simply add to the bottom the extra module you need:
include $(CLEAR_VARS)
LOCAL_MODULE := nonfree
LOCAL_SRC_FILES := libnonfree.so
include $(PREBUILT_SHARED_LIBRARY)
Now the file C:\Users\Adrien\AndroidStudioProjects\NDKOpencvTest4\app\src\main\jni\libnonfree.so will be packed into your APK.
If you need this library to link your libMyOpencvLibs.so (this means, if your code in com_example_adrien_ndkopencvtest4_OpencvNativeClass.cpp uses some functions exported from libnonfree.so, you should also refeence it in your module:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#opencv
OPENCVROOT:= C:\OpenCV-2.4.10-android-sdk
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk
LOCAL_SRC_FILES := com_example_adrien_ndkopencvtest4_OpencvNativeClass.cpp
LOCAL_LDLIBS += -llog
LOCAL_SHARED_LIBRARIES += nonfree
LOCAL_MODULE := MyOpencvLibs
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := nonfree
LOCAL_SRC_FILES := libnonfree.so
include $(PREBUILT_SHARED_LIBRARY)
Modify your android.mk as:
LOCAL_PATH := $(call my-dir)
OPENCV_PATH := D:/CODE/OpenCV-2.4.10-android-sdk/sdk/native/jni
include $(CLEAR_VARS)
LOCAL_MODULE := nonfree
LOCAL_SRC_FILES := libnonfree.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
#opencv
OPENCVROOT:= C:\OpenCV-2.4.10-android-sdk
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk
LOCAL_SRC_FILES := com_example_adrien_ndkopencvtest4_OpencvNativeClass.cpp
LOCAL_SHARED_LIBRARIES += nonfree
LOCAL_LDLIBS += -llog
LOCAL_MODULE := MyOpencvLibs
include $(BUILD_SHARED_LIBRARY)
Here the prebuild library i.e. libnonfree.so is declared in the android.mk, and referenced to it later via
LOCAL_SHARED_LIBRARIES += nonfree
Now to use it you need to load the latest built library in yout MainActivity i.e.
System.loadLibrary("MyOpencvLibs");
Thats it, now you have merged both the android.mk files into a new module named: MyOpencvLibs
For better understanding you can read my blog : https://androidtutsweb.wordpress.com/2017/04/04/android-mk-for-ndk-build-using-pre-build-libraries/
I built PCL library for Android with
hcteq.wordpress.com/2014/07/14/compiling-pcl-for-android-in-windows-cmake-gui
I tried to include these library in Android Studio with Project github.com/roomplan/tango-examples-java/tree/master/PointCloudJava_with_PCL
To write .mk and .gradle file, I referred
stackoverflow.com/questions/35491012/issue-running-pcl-library-with-android-project
github.com/kalectro/pcl_groovy/blob/master/mobile_apps/android/OpenNIRecorder/jni/Android.mk
Here is my Android.mk
LOCAL_PATH := $(call my-dir)
PROJECT_ROOT_FROM_JNI := ../../../../..
PROJECT_ROOT := $(LOCAL_PATH)/$(PROJECT_ROOT_FROM_JNI)
PCL_INCLUDE := $(LOCAL_PATH)/../../../../../PCL/pcl-android
BOOST_ANDROID_INCLUDE := $(LOCAL_PATH)/../../../../../PCL/boost-android
FLANN_INCLUDE := $(LOCAL_PATH)/../../../../../PCL/flann-android
EIGEN_INCLUDE := $(LOCAL_PATH)/../../../../../PCL/eigen
NDK_TOOLCHAIN_VERSION=4.9
# PCL libraries
PCL_STATIC_LIB_DIR := $(PCL_INCLUDE)/lib
BOOST_STATIC_LIB_DIR := $(BOOST_ANDROID_INCLUDE)/lib
FLANN_STATIC_LIB_DIR := $(FLANN_INCLUDE)/lib
PCL_STATIC_LIBRARIES := pcl_common pcl_geometry pcl_kdtree pcl_octree pcl_sample_consensus pcl_surface \
pcl_features pcl_keypoints pcl_search pcl_tracking pcl_filters pcl_ml \
pcl_registration pcl_segmentation
BOOST_STATIC_LIBRARIES := boost_date_time boost_iostreams boost_regex boost_system \
boost_filesystem boost_program_options boost_signals boost_thread
FLANN_STATIC_LIBRARIES := flann_s flann_cpp_s
define build_pcl_static
include $(CLEAR_VARS)
LOCAL_MODULE:=$1
LOCAL_SRC_FILES:=$(PCL_STATIC_LIB_DIR)/lib$1.a
include $(PREBUILT_STATIC_LIBRARY)
endef
define build_boost_static
include $(CLEAR_VARS)
LOCAL_MODULE:=$1
LOCAL_SRC_FILES:=$(BOOST_STATIC_LIB_DIR)/lib$1.a
include $(PREBUILT_STATIC_LIBRARY)
endef
define build_flann_static
include $(CLEAR_VARS)
LOCAL_MODULE:=$1
LOCAL_SRC_FILES:=$(FLANN_STATIC_LIB_DIR)/lib$1.a
include $(PREBUILT_STATIC_LIBRARY)
endef
$(foreach module,$(PCL_STATIC_LIBRARIES),$(eval $(call build_pcl_static,$(module))))
$(foreach module,$(BOOST_STATIC_LIBRARIES),$(eval $(call build_boost_static,$(module))))
$(foreach module,$(FLANN_STATIC_LIBRARIES),$(eval $(call build_flann_static,$(module))))
# Project and linking
include $(CLEAR_VARS)
LOCAL_MODULE := helloPcl
LOCAL_CFLAGS := -std=gnu++11
LOCAL_C_INCLUDES := $(PCL_INCLUDE)/include/pcl-1.6 \
$(BOOST_ANDROID_INCLUDE)/include \
$(EIGEN_INCLUDE) \
$(FLANN_INCLUDE)/include
LOCAL_LDFLAGS += -L$(PCL_INCLUDE)/lib \
-L$(BOOST_ANDROID_INCLUDE)/lib \
-L$(FLANN_INCLUDE)/lib
LOCAL_SHARED_LIBRARIES += pcl_common pcl_geometry pcl_search pcl_kdtree pcl_octree pcl_sample_consensus \
pcl_surface pcl_features pcl_filters pcl_keypoints pcl_tracking pcl_ml \
pcl_registration pcl_segmentation
LOCAL_SHARED_LIBRARIES += boost_date_time boost_iostreams boost_regex boost_system \
boost_filesystem boost_program_options boost_signals boost_thread
LOCAL_SHARED_LIBRARIES += flann flann_cpp
LOCAL_SRC_FILES := jni_part.cpp \
pcl_lib.cpp
LOCAL_LDLIBS := -lstdc++ -lc -lm -llog -landroid -ldl -lGLESv2 -lEGL \
-lpcl_common -lpcl_geometry -lpcl_search -lpcl_kdtree -lpcl_octree -lpcl_sample_consensus \
-lpcl_surface -lpcl_features -lpcl_filters -lpcl_keypoints -lpcl_tracking -lpcl_ml \
-lpcl_registration -lpcl_segmentation \
-lflann -lflann_cpp
LOCAL_CFLAGS += -mfloat-abi=softfp -mfpu=neon -march=armv7 -mthumb -O3
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_ABI := armeabi-v7a
APP_PLATFORM := android-19
#APP_STL := stlport_static
APP_CPPFLAGS := -frtti -fexceptions
APP_STL := gnustl_static
and build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.tangoproject.experiments.javapointcloud"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
ndk {
moduleName 'helloPcl'
}
}
sourceSets.main {
jni.srcDirs = [];
jniLibs.srcDir 'src/main/libs'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build.cmd",
'-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
'-j', Runtime.runtime.availableProcessors(),
'all',
'NDK_DEBUG=1'
}
task cleanNative(type: Exec, description: 'Clean JNI object files') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build.cmd",
'-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
'clean'
}
clean.dependsOn 'cleanNative'
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn buildNative
}
dependencies {
compile project(':tangoUtils')
compile files('libs/tango_java_lib.jar')
}
it seems that I have successfully linked the library for .cpp files, but there are errors show like this link
Does anyone know how to resolve this problem? Thanks.
PS There is similar question on Point Cloud Library (PCL) Users mailing list(www.pcl-users.org/Undefined-reference-to-PCDWrite-and-PCDWriteASCII-td4043323.html), but still no answer.
PS2 Or anyone can provide some instructions for using PCL in Android Studio?
Edit
I modified my Android.mk file here
LOCAL_PATH := $(call my-dir)
PROJECT_ROOT_FROM_JNI := ../../../../..
PROJECT_ROOT := $(LOCAL_PATH)/$(PROJECT_ROOT_FROM_JNI)
PCL_INCLUDE := $(LOCAL_PATH)/../../../../../PCL/pcl-android
BOOST_ANDROID_INCLUDE := $(LOCAL_PATH)/../../../../../PCL/boost-android
FLANN_INCLUDE := $(LOCAL_PATH)/../../../../../PCL/flann-android
EIGEN_INCLUDE := $(LOCAL_PATH)/../../../../../PCL/eigen
NDK_TOOLCHAIN_VERSION=4.9
# PCL libraries
PCL_STATIC_LIB_DIR := $(PCL_INCLUDE)/lib
BOOST_STATIC_LIB_DIR := $(BOOST_ANDROID_INCLUDE)/lib
FLANN_STATIC_LIB_DIR := $(FLANN_INCLUDE)/lib
PCL_STATIC_LIBRARIES := pcl_common pcl_geometry pcl_kdtree pcl_octree pcl_sample_consensus pcl_surface \
pcl_features pcl_keypoints pcl_search pcl_tracking pcl_filters pcl_ml \
pcl_registration pcl_segmentation pcl_io pcl_io_ply pcl_recognition
BOOST_STATIC_LIBRARIES := boost_date_time boost_iostreams boost_regex boost_system \
boost_filesystem boost_program_options boost_signals boost_thread
FLANN_STATIC_LIBRARIES := flann_s flann_cpp_s
define build_pcl_static
include $(CLEAR_VARS)
LOCAL_MODULE:=$1
LOCAL_SRC_FILES:=$(PCL_STATIC_LIB_DIR)/lib$1.a
include $(PREBUILT_STATIC_LIBRARY)
endef
define build_boost_static
include $(CLEAR_VARS)
LOCAL_MODULE:=$1
LOCAL_SRC_FILES:=$(BOOST_STATIC_LIB_DIR)/lib$1.a
include $(PREBUILT_STATIC_LIBRARY)
endef
define build_flann_static
include $(CLEAR_VARS)
LOCAL_MODULE:=$1
LOCAL_SRC_FILES:=$(FLANN_STATIC_LIB_DIR)/lib$1.a
include $(PREBUILT_STATIC_LIBRARY)
endef
$(foreach module,$(PCL_STATIC_LIBRARIES),$(eval $(call build_pcl_static,$(module))))
$(foreach module,$(BOOST_STATIC_LIBRARIES),$(eval $(call build_boost_static,$(module))))
$(foreach module,$(FLANN_STATIC_LIBRARIES),$(eval $(call build_flann_static,$(module))))
# Project and linking
include $(CLEAR_VARS)
LOCAL_MODULE := helloPcl
LOCAL_CFLAGS := -std=gnu++11
LOCAL_SRC_FILES := jni_part.cpp \ pcl_lib.cpp
#pcl library
LOCAL_LDFLAGS += -L$(PCL_INCLUDE)/lib \
-L$(BOOST_ANDROID_INCLUDE)/lib \
-L$(FLANN_INCLUDE)/lib
LOCAL_C_INCLUDES += $(PCL_INCLUDE)/include/pcl-1.6 \
$(BOOST_ANDROID_INCLUDE)/include \
$(EIGEN_INCLUDE) \
$(FLANN_INCLUDE)/include
LOCAL_STATIC_LIBRARIES += pcl_common pcl_geometry pcl_kdtree pcl_octree pcl_sample_consensus \
pcl_surface pcl_features pcl_io pcl_keypoints pcl_recognition \
pcl_search pcl_tracking pcl_filters pcl_io_ply pcl_ml \
pcl_registration pcl_segmentation
LOCAL_STATIC_LIBRARIES += boost_date_time boost_iostreams boost_regex boost_system \
boost_filesystem boost_program_options boost_signals \
boost_thread
LOCAL_SHARED_LIBRARIES := tango_client_api tango_support_api
LOCAL_SHARED_LIBRARIES += flann flann_cpp
LOCAL_CFLAGS += -mfloat-abi=softfp -mfpu=neon -march=armv7 -mthumb -O3
LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
include $(BUILD_SHARED_LIBRARY)
$(call import-add-path,$(PROJECT_ROOT))
$(call import-module,tango_client_api)
$(call import-module,tango_support_api)
and now there are different error
D:/Lab/senior/PCL/PointCloudJava_with_PCL_1/pointCloudJava_with_PCL/src/main/jni/../../../../../PCL/pcl-android/lib/libpcl_io.a(pcd_io.cpp.o):pcd_io.cpp:function pcl::PCDWriter::writeBinary(std::string const&, sensor_msgs::PointCloud2 const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, Eigen::Quaternion<float, 0> const&): error: undefined reference to '__page_size'
D:/Lab/senior/PCL/PointCloudJava_with_PCL_1/pointCloudJava_with_PCL/src/main/jni/../../../../../PCL/pcl-android/lib/libpcl_io.a(pcd_io.cpp.o):pcd_io.cpp:function pcl::PCDWriter::writeBinaryCompressedEigen(std::string const&, pcl::PointCloud<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&): error: undefined reference to '__page_size'
D:/Lab/senior/PCL/PointCloudJava_with_PCL_1/pointCloudJava_with_PCL/src/main/jni/../../../../../PCL/pcl-android/lib/libpcl_io.a(pcd_io.cpp.o):pcd_io.cpp:function pcl::PCDWriter::writeBinaryCompressed(std::string const&, sensor_msgs::PointCloud2 const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, Eigen::Quaternion<float, 0> const&): error: undefined reference to '__page_size'
D:/Lab/senior/PCL/PointCloudJava_with_PCL_1/pointCloudJava_with_PCL/src/main/jni/../../../../../PCL/pcl-android/lib/libpcl_io.a(pcd_io.cpp.o):pcd_io.cpp:function pcl::PCDWriter::writeBinaryEigen(std::string const&, pcl::PointCloud<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&): error: undefined reference to '__page_size'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [D:/Lab/senior/PCL/PointCloudJava_with_PCL_1/pointCloudJava_with_PCL/src/main/obj/local/armeabi-v7a/libhelloPcl.so] Error 1
make: Leaving directory `D:/Lab/senior/PCL/PointCloudJava_with_PCL_1/pointCloudJava_with_PCL/src/main/jni'
:pointCloudJava_with_PCL:buildNative FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':pointCloudJava_with_PCL:buildNative'.
> Process 'command 'C:\Users\CAIG\AppData\Local\Android\Sdk\ndk-bundle/ndk-build.cmd'' finished with non-zero exit value 2
If I add the line below in Android.mk, errors will not occur and can compile success
LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
But when run the .apk, Android Monitor shows
java.lang.UnsatisfiedLinkError: dlopen failed: library "libtango_client_api.so" not found
Let me start by saying that I am new to Gradle, Android Studio, and Git. We just migrated from Eclipse and SVN to these technologies and are having a bit of trouble getting our Android project running. We are developing on a Mac. I have inherited this project from another team and am unsure of why they chose to do certain things.
[Unfortunately, I had to censor the name of the project and the user throughout the screenshots.]
We are using c ogg libraries to record audio files in our Android application.
The error we are receiving is:
We've found this blog post and this stackoverflow question which links to this other SO question, but we have been unable to get any of them working.
We are unsure if the project is set up correctly, as there seem to be a lot of Android.mk files floating around.
From the question links above, it seems we need to force Gradle to not overwrite our Android.mk files with it's own, but the suggestions only seemed to put us further down the rabbit hole.
Would anyone kindly point us in the right direction?
jni/Android.mk
LOCAL_PATH := $(call my-dir)
LOCAL_C_INCLUDE := $(LOCAL_PATH)/include
include $(addprefix $(LOCAL_PATH)/, $(addsuffix /Android.mk, \
libogg \
libvorbis \
libvorbis-jni \
))
jni/libogg/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libogg
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../include -ffast-math -fsigned-char
ifeq ($(TARGET_ARCH),arm)
LOCAL_CFLAGS += -march=armv6 -marm -mfloat-abi=softfp -mfpu=vfp
endif
LOCAL_SRC_FILES := \
bitwise.c \
framing.c
include $(BUILD_SHARED_LIBRARY)
jni/libvorbis-jni/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := vorbis-jni
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../include -fsigned-char
ifeq ($(TARGET_ARCH),arm)
LOCAL_CFLAGS += -march=armv6 -marm -mfloat-abi=softfp -mfpu=vfp
endif
LOCAL_SHARED_LIBRARIES := libogg libvorbis
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
LOCAL_SRC_FILES := \
com_*****_android_audio_VorbisEncoder.c
include $(BUILD_SHARED_LIBRARY)
jni/libvorbis/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libvorbis
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../include -ffast-math -fsigned-char
ifeq ($(TARGET_ARCH),arm)
LOCAL_CFLAGS += -march=armv6 -marm -mfloat-abi=softfp -mfpu=vfp
endif
LOCAL_SHARED_LIBRARIES := libogg
LOCAL_SRC_FILES := \
mdct.c \
smallft.c \
block.c \
envelope.c \
window.c \
lsp.c \
lpc.c \
analysis.c \
synthesis.c \
psy.c \
info.c \
floor1.c \
floor0.c \
res0.c \
mapping0.c \
registry.c \
codebook.c \
sharedbook.c \
lookup.c \
bitrate.c \
vorbisfile.c \
vorbisenc.c
include $(BUILD_SHARED_LIBRARY)
build.gradle of the project
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}
build.gradle of the project module
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.*****.android.hud"
minSdkVersion 14
targetSdkVersion 18
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
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...?