1、创建一个Android工程
2、新建new module中选择Android Library
3、把我们新建的new module(Android Library)添加到app里面去
备注:可以看app下面的build.gradle是否添加成功
implementation project(path: ':myplayer')
4、把app里面中的build.gradle中的externalNativeBuild 移植到myplayer里面的build.gradle中
externalNativeBuild {
cmake {
cppFlags ""
}
}
5、把app里面中的build.gradle中的externalNativeBuild 移植到myplayer里面的build.gradle中
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
6、最终myplayer里面的build.gradle如下
apply plugin: 'com.android.library'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
externalNativeBuild {
cmake {
cppFlags ""
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
7、我们把app/src/main/下面的cpp文件移到myplayer下面去
8、在myplayer中新建一个Demo类
9、然后把FFmpeg编译生成的include文件拷贝到myplayer中cpp下面
10、在myplayer中main下面创建一个jnilibs文件夹
11、将FFmpeg编译生成的x86和arm文件中的库拷贝到myplayer中jnilibs下面