ExoPlayer ffmpeg failed to Build library - android-studio

I recently tried add extensions in ExoPlayer like ffmpeg extension to support more audio formats in my app, i followed the extension-ffmpeg Readme.md and i successfully created the library for arm64-v8a, armeabi-v7a, x86 and x86_64 and inside of these folders are libavcodec.so, libavutil.so and libswresample.so, After successfully creating the library i need to build the aar to include it in my app but when i run
cd "${FFMPEG_EXT_PATH}" && \
${NDK_PATH}/ndk-build APP_ABI="armeabi-v7a arm64-v8a x86 x86_64" -j4
i get this error
Android NDK: WARNING: APP_PLATFORM android-16 is higher than android:minSdkVersion 1 in ./AndroidManifest.xml. NDK binaries will *not* be compatible with devices older than android-16. See https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md for more information.
Android NDK: Your APP_BUILD_SCRIPT points to an unknown file: ./jni/Android.mk
/home/oni/Android/Sdk/ndk/20.0.5594570/build/core/add-application.mk:88: *** Android NDK: Aborting... . Stop.
I'm a newbie to this and i have tried to see some examples of Android.mk for exoplayer ffmpeg extensions but i did no find anything and i'm stuck in this part, i'm still searching for some examples that might help me to successful build the extension ffmpeg aar.

Related

libreactnativejni.so is built as elf32-i386 on 64bit android ndk (linux)

EDIT: I managed to built x86_64 version of libreactnativejni.so (see my answer). However it didn't resolved my problem.
To sum up what I learned here is:
You cannot test android components, which are using native libraries on Linux, because "libandroid.so" (core android lib), doesn't exists for Linux.
Original question:
My goal is to run tests on my Linux box using PowerMockito similar to RootViewTest.java.
Not sure how react-native team managed to run this test, but from my experience mocking Arguments.createArray is not possible, without loading jni library reactnativejni. Reason is that Arguments.createArray() calls WritableNativeArray which in static initializer ReactBridge.staticInit() calls SoLoader.loadLibrary("reactnativejni").
So I thought I've no other option, but compile this reactnativejni shared library for linux, using 64bit android-ndk-r10e
I managed to load this jni lib and test my code using:
ndkDir=$(pwd)/react-ndk/all/x86 \
JAVA_OPTS="-Djava.library.path=\".:$ndkDir\"" \
LD_LIBRARY_PATH="$ndkDir:$LD_LIBRARY_PATH" ./gradlew app:test
But test failed with:
libreactnativejni.so: wrong ELF class: ELFCLASS32 (Possible cause: architecture word width mismatch)
Checked platform with objdump:
objdump -s --section .comment libreactnativejni.so
libreactnativejni.so: file format elf32-i386
My question how is possible that 64 bit ndk produced 32 bit library and how to force to produce 64 bit.
Library build script is written as gradle script:
https://github.com/facebook/react-native/blob/26684cf3adf4094eb6c405d345a75bf8c7c0bf88/ReactAndroid/build.gradle#L199
ReactAndroid explicitly requests 32-bit targets. If you wish, you can replace this line to read
APP_ABI := all
I'm going to answer my own question (thank Alex for good APP_ABI lead). To compile x86_64 variant of reactnativejni follow this steps:
Update APP_ABI to APP_ABI := armeabi-v7a x86_64 x86 in file ReactAndroid/src/main/jni/Application.ml
The next problem is dependency jsc-android, which is not build for X86_64 target. There is alternative jsc-android-buildscripts which is also built for X86_64.
Extract folder X86_64 directly from aar and put it in ReactAndroid/build/third-party-ndk/jsc/jni/x86_64
However compilation will be failing on X86_64 with errors: lambda capture initializers only available with -std=c++1y or -std=gnu++1y
Fix that error, by replacing all occurrences of -std=c++1y with -std=c++11 in all Android.mk files.
Now you can start build with: ./gradlew buildReactNdkLib
Optionally you might need to clean build folder with ./gradlew cleanReactNdkLib
Built reactnativejni - libreactnativejni.so will be present in ReactAndroid/build/react-ndk/all/x86_64.
But unfortunately libreactnativejni.so will not work on Linux, as it has dependency on libandroid.so, which doesn't exists for Linux.

build c file with openssl by NDK under cygwin

I am trying to build c file included by ndk under cygwin
In Android.mk, I add -I/usr/include to LOCAL_FLAGS like
LOCAL_FLAGS := -I/usr/include
And I have checked that openssl does under /usr/include
But when I run ndk-build under by project dir, it output
"fatal error: openssl/ssl.h: No such file or directory"
I think I have specified the include directory, but not solve this problem.
Is there any other way can I try?
You seem to have some gaps in your knowledge:
C code compiles to processor's native instruction set. Your desktop/build machine probably has a different architecture from your Android device(thus a different instruction set).
NDK doesn't just compile, it cross-compiles. It means that the NDK runs on the build machine, but the executable it produces cannot run on the build machine(different instruction sets).
All libraries on your desktop are in your desktop's processoer's instruction set. Thus, you cannot link any program build by the NDK using the desktop's libraries. This means:
No includes from '/usr/include/'
No libs from /lib, /usr/lib, /lib64 or /usr/lib64
No Cygwin packages under on Windows
What you need to do is build your own openssl using the NDK and use that to link against when you build your executable.
Please note that the answer is missing a lot of information (at least 3 Bachelor's level Computer Science courses worth of information).

Android NDK - Where to put the .so file which specified in LOCAL_SHARED_LIBRARIES?

I have successfully build libcurl for android as a shared library, both armeabi-v7a and x86, and one of my project depends on it. I have set "LOCAL_SHARED_LIBRARIES := libcurl", the problem is where should I put those libcurl.so files?
I tried putting them under (project)/jni/lib/(platform)/libcurl.so, and ndk-build gives me a whole load of linking error. (project)/lib/(platform)/libcurl.so will not work too because ndk-build will clear this directory before build.
So I tried again, building 1 platform at a time, however I still have no idea where to put it. jni/libcurl.so will not work.
Simple, follow this, download curl source from http://curl.haxx.se/
- prepare the toolchain of the Android NDK for standalone use; this can
be done by invoking the script:
./build/tools/make-standalone-toolchain.sh
which creates a usual cross-compile toolchain. Lets assume that you put
this toolchain below /opt then invoke configure with something like:
export PATH=/opt/arm-linux-androideabi-4.4.3/bin:$PATH
./configure --host=arm-linux-androideabi [more configure options]
make
Done.

Strange openssl build error in android ndk

I am facing some build error for OpenSSL in android ndk. The error is
make: *** No rule to make target `/home/computer/openssl-android-master/crypto/cryptlib.c', needed by `obj/local/armeabi/objs/crypto/cryptlib.o'. Stop.
I don't know where it is targeted.
This is to clarify the users about android ndk r8e- that android ndk r8e sometimes does not clean the previously build files, so one should check and delete the binary files.

ndk-gdb on windows

i m trying to debug my jni section of application by running ngk-gdb on windows machine with android-ndk-r8b.
i am using cygwin and c/c++ plugin for eclipse.my device is galaxy s, android 2.3.7
what i did is followed the instructions on Using Eclipse for Android C/C++ Debugging,
but i am stuck on running ndk-gdb, getting this error:
Device CPU ABIs: armeabi-v7a armeabi
ERROR: The device does not support the application's targetted CPU ABIs!
Device supports: armeabi-v7a armeabi
Package supports:
thx for your help
I encountered the problem recently and in my case it was a cygwin issue. make was not installed in cygwin and this created problems further along in the ndk-gdb script. After installing make using the cygwin setup.exe (select make under Devel - on another recommendation, I also installed tcsh under Shells), the "ABIS targetted by application:" line shows the app's targeted ABI.
Without make:
/cygdrive/c/work/android/android-ndk-r8b-windows/android-ndk-r8b/ndk-gdb: line 105: make: command not found
ABIs targetted by application:
Device API Level: 15
Device CPU ABIs: armeabi-v7a armeabi
ERROR: The device does not support the application's targetted CPU ABIs!
Device supports: armeabi-v7a armeabi
Package supports:
With make properly installed:
ABIs targetted by application: armeabi-v7a
Device API Level: 15
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi-v7a
Application.mk, located in the jni folder, can be used to specify the app's targeted ABI - an example:
APP_ABI := armeabi-v7a
APP_OPTIM := debug
Good luck!
For all others like me with Nexus (devices) updated with Android 4.3 there are bugs that hinder Native code debugging. (I tried everything found on SO :)
Either root your device and try
Or Update nexus 4.3 factory image here (and this is reported working by google android dev)
Or wait for Android 4.4 update to come to your device (as bug is identified and fix in the source tree by Google by not yet packaged
released)

Resources