Source: GitHub
Question: How to use FFmpeg built by VPlayer (version 0.3.2 at the time I write this Gist) in Android Studio?
Answer This will take the FFmpeg built from here and use it as a library for our project in Android Stuio in Window 10.
- Download NDK from here, uncompress it to anywhere you want (
C:\Users\Viet\AppData\Local\Android\ndk\android-ndk-r11c
in my case). - Copy the whole
VPlayer_lib
folder build from here into the root of your project. - In Android studio, click on
app -> F4 -> SDK Location -> Android NDK location
. - Edit/create
gradle.properties
file in the root folder of your project withandroid.useDeprecatedNdk=true
. - Edit your project's
settings.gradle
and add these two lines at the bottom
include ':VPlayer_library'
project(':VPlayer_library').projectDir = new File(settingsDir, 'VPlayer_lib/VPlayer_library')
- Edit your application's
build.gradle
file to add the dependency by adding this:
dependencies {
...
compile project(':VPlayer_library')
...
}
- After synchronizing your project, follow the below instructions to resolve the errors related to this project in Android Studio.
- Get the dependencies: tropicssl, ffmpeg (headers only) and libyuv (DO ONE of the following):
- Unzip and extract the dependencies to
VPlayer_lib
folder (this should add folders toVPlayer_library/jni/
) - OR Run the script
/{root}/VPlayer_lib/VPlayer_library/jni/setup.sh
.
Your folder structure should look like this under /jni
jni/
|- android-ndk-profiler-3.1/
|- application/
|- ffmpeg/
|- ffmpeg-build/
|- libyuv/
|- tropicssl/
|- Android.mk
|- Android-tropicssl.mk
|- Application.mk
|- setup.sh
- [Optional] Edit the
Application.mk
to change architectures. - [Optional] Edit the
Android.mk
:
FEATURE_NEON
: if you comment this, you need to removeNativeTester
code inVPlayerController.java@LINE292
. (leave this)SUBTITLES
: remove if you do not want subtitle support; if you download the binaries or built one without subtitles you must comment this out. (temporrary leave this as our FFmpeg come with subtitle, need to update it to a version without subtitles).MODULE_ENCRYPT
: remove if you do not want encryption for networking. (comment out)LIBRARY_PROFILER
: remove if you do not want the profiler. (leave this, I dont even know what this is).
- If you get a
Are you sure your NDK_MODULE_PATH variable is properly defined ?
error, add the following toAndroid.mk
:
...
$(call import-add-path,C:\Users\Viet\AppData\Local\Android\ndk\android-ndk-r11c\sources\android)
$(call import-module,cpufeatures)
of course this will need to be your path to the NDK, TRIPLE CHECK it don't be lazy.
- If the build fail because gradle heap size too small try uncomment this line in the project's
gradle.properties
:
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
- Another possible error you may encouter is
UnsatisfiedLinkError, libffmpeg-neon.so: has text relocations
. Temporary solution is to change the targetSDK of your app to anything smaller than 23.
I hv done all the steps u explained but i face this problem can u help me? Android NDK: ERROR:jni/Android.mk:ffmpeg-prebuilt: LOCAL_SRC_FILES points to a missing file