I use ndk-build to build a static library and compile to a *.so successfully, but Runtime error is thrown when runs in android simulator. The error is
E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.example.kotlin.mixed, PID: 31185
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZNSt6__ndk17codecvtIcc9mbstate_tE2idE" referenced by "/data/app/org.example.kotlin.mixed-2/lib/x86/libtest.so"...
at java.lang.Runtime.loadLibrary(Runtime.java:372)
at java.lang.System.loadLibrary(System.java:1076)
at com.bytedance.lark.sdk.Sdk.<init>(Sdk.kt:15)
at org.example.kotlin.mixed.MyApplication.onCreate(MyApplication.kt:12)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
And I find symbol _ZNSt6__ndk17codecvtIcc9mbstate_tE2idE appears on the static library I build. I can not find reference of ndk in my source code. I am not sure if the ndk-build add this symbol to the static lib.
the ndk-build config goes here.
Application.mk
APP_ABI := x86
APP_PLATFORM := android-21 // I change this to android-14, also not work
APP_STL:=c++_static
APP_CPPFLAGS:=-std=c++11 -fexceptions -frtti -DANDROID -DDEBUG
NDK_TOOLCHAIN_VERSION := clang
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include ../uuid/Android.mk
include mylib.mk
mylib.mk
LOCAL_PATH := $(call my-dir)
MYLIB_CSOURCES := \
// my source code
MYLIB_INCLUDES := \
$(LOCAL_PATH)/../uuid/include \
$(LOCAL_PATH)/../../../../../lib/rapidjson/include \
$(LOCAL_PATH)/../../../../../src
###
### Build mylib.a
###
include $(CLEAR_VARS)
LOCAL_MODULE := mylibc++
LOCAL_SRC_FILES := \
$(addprefix ../../../../../src/,$(MYLIB_CSOURCES))
LOCAL_C_INCLUDES := $(MYLIB_INCLUDES)
LOCAL_CFLAGS += -DANDROID -DDEBUG -D__ANDROID__
LOCAL_WHOLE_STATIC_LIBRARIES := uuid
include $(BUILD_STATIC_LIBRARY)
android build config:
android {
compileSdkVersion 23
buildToolsVersion '26.0.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir 'libs'
}
}
The symbol _ZNSt6__ndk17codecvtIcc9mbstate_tE2idE (which means std::__ndk1::codecvt::id) is available in libc++_shared.so.
If your runtime environment (emulator) is lower than API 21, you must explicitly load this library from Java, before you load libtest.so.
libc++_shared.so should also be packed into the APK together with libtest.so. Make sure that it is present in libs/x86 and also for other relevant ABIs.
In Android Studio, you can let gradle build the NDK libraries for you, and it will take care of the necessary dependencies.
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 ?
We have taken clone of a project and made all settings as per instruction still not able to build app due to following error:
Error:(7, 10) fatal error: 'gst/gst.h' file not found
above error is in tutorial.c file:
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/video/videooverlay.h>
#include <pthread.h>
GST_DEBUG_CATEGORY_STATIC (debug_category);
#define GST_CAT_DEFAULT debug_category
Please find below gradle and Android.mk file which I have added to my project:
Gradle
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.ndktest"
minSdkVersion 19
targetSdkVersion 22
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
arguments '-DANDROID_TOOLCHAIN=clang',
'-DANDROID_PLATFORM=android-19',
'-DANDROID_STL=gnustl_static',
'-DANDROID_ARM_NEON=TRUE',
'-DANDROID_CPP_FEATURES=exceptions rtti'
}
}
ndk {
moduleName "tutorial-5"
}
}
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir new File(buildDir, 'lib')
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
Android.mk
LOCAL_PATH := $(call my-dir)
GSTREAMER_ROOT_ANDROID := D:\ndk-gst1.9.1
SHELL := PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin /bin/bash
include $(CLEAR_VARS)
LOCAL_MODULE := tutorial-5
LOCAL_SRC_FILES := tutorial-5.c
LOCAL_SHARED_LIBRARIES := gstreamer_android
LOCAL_LDLIBS := -llog -landroid
include $(BUILD_SHARED_LIBRARY)
ifndef GSTREAMER_ROOT
ifndef GSTREAMER_ROOT_ANDROID
$(error GSTREAMER_ROOT_ANDROID is not defined!)
endif
GSTREAMER_ROOT := $(GSTREAMER_ROOT_ANDROID)
endif
GSTREAMER_NDK_BUILD_PATH := $(GSTREAMER_ROOT)/share/gst-android/ndk-build
include $(GSTREAMER_NDK_BUILD_PATH)/plugins.mk
GSTREAMER_PLUGINS := $(GSTREAMER_PLUGINS_CORE) $(GSTREAMER_PLUGINS_PLAYBACK) $(GSTREAMER_PLUGINS_CODECS) $(GSTREAMER_PLUGINS_NET) $(GSTREAMER_PLUGINS_SYS) $(GSTREAMER_PLUGINS_CODECS_RESTRICTED)
G_IO_MODULES := gnutls
GSTREAMER_EXTRA_DEPS := gstreamer-video-1.0
include $(GSTREAMER_NDK_BUILD_PATH)/gstreamer-1.0.mk
Please suggest what changes need to be done in above code to make it run.
I already answered a similar question... The problem with the official tutorials from the Gstreamer site is that they are old and made for Eclipse. Maybe your error is because you didn't link your Android Studio project to the C++ files... to do it follow the second step from this answer: Gstreamer examples in Android Studio
Since the linking with C++ files ins't the only error that will occurs I also suggest that you follow all other steps. There's a link for gitlab project with "turorial 5" working in the link above.
I'm trying to reach a break point in a simple C++ code:
Here the .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());
}
}
here the 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"
}
}
...
}
The Android.mk:
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 the Application.mk
APP_ABI := all
APP_STL := gnustl_static
The application compiles and works but I'm not able to stop in any breakpoint in the C++ code while running the debugger. I can see how it loads the native libraries but it doesn't stop any where and Android studio is telling me that the break point has been attached.
I'm using Android Studio 2.2 Preview 6
Can anybody help me?
In my case I have two modules, one with the C++ code (library) and an other one with the application that consumes the library module.
The problem was that I tried to debug the library module uaing the app module, so I just need to specify the folder where the debug symbols are:
Run->Edit configurations... -> Debuggerand in the symbol directories tab add the right path. For instance:
/path_to_my_project/lib_module/build/intermediates/ndkBuild/flavor/debug/obj/local/x86
app.imp file contains "<"facet type="native_android_gradle">", , option=SELECTED_BUILD_VARIANT..
check if value="debug"
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.
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...?