I have some pre-build *.so files for different build flavors like
arm64-v8a, armeabi-v7a, x86, x86_64,
and these files are of android third party library. When I run the project all these *.so files are packaging in apk. But here my question is that how to package different *.SO files in different apks? can you please give build.gradle script for this. any help will be appreciated? Thank you. Sorry for my poor english.
my library.gradle is
apply plugin: 'com.android.library'
import com.android.builder.core.DefaultManifestParser
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
sourceSets {
main {
jni.srcDirs = []
// Prevent gradle from building native code with ndk; we have our own Makefile for it.
jniLibs.srcDirs = ['jni/libs', 'jni/loader/libs', 'private_libs/libs']
// Where generated .so files are placed.
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
// Make per-variant version code
libraryVariants.all { variant ->
def manifestParser = new DefaultManifestParser(android.sourceSets.main.manifest.srcFile)
// get the version code of each flavor
def version = manifestParser.getVersionName()
//Custom APK name
variant.outputs.all { output ->
if (outputFileName != null && outputFileName.endsWith('.aar')) {
outputFileName = "lib-${version}.aar"
}
}
}
}
class BuildNative extends Exec {}
tasks.withType(BuildNative) {
/*
Properties set for Android Studio own shell.
when you run gradlew from cli, OS shell env variables will be used
To be able to build from Android Studio, you have to set ndk.dir & sdk.dir
properties in local.properties in the root folder, like this (for example):
sdk.dir=/home/<username>/SDK/android-sdk-linux
ndk.dir=/home/<username>/SDK/android-ndk-r10b
*/
if (System.getenv('ANDROID_SDK') == null || System.getenv('ANDROID_NDK') == null) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
environment 'ANDROID_NDK', properties.getProperty('ndk.dir')
environment 'ANDROID_SDK', properties.getProperty('sdk.dir')
}
workingDir '..'
commandLine './compile-libvlc.sh'
}
task buildDebugARMv7(type: BuildNative) {
args('-a', "armeabi-v7a")
}
task buildDebugARM64(type: BuildNative) {
args('-a', "arm64-v8a")
}
task buildDebugx86(type: BuildNative) {
args('-a', "x86")
}
task buildDebugx86_64(type: BuildNative) {
args('-a', "x86_64")
}
task buildDebugMIPS(type: BuildNative) {
args('-a', "mips")
}
task buildDebugMIPS64(type: BuildNative) {
args('-a', "mips64")
}
task generateSources(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
clean {
// delete 'build', /*'jni/libs',*/ 'jni/obj'
}
dependencies {
api "com.android.support:support-annotations:$rootProject.ext.appCompatVersion"
api "com.android.support:support-v4:$rootProject.ext.appCompatVersion"
}
and my app.gradle is:
apply plugin: 'com.android.application'
android {
packagingOptions {
}
dexOptions {
maxProcessCount 8
javaMaxHeapSize "2g"
preDexLibraries true
keepRuntimeAnnotatedClasses false
}
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
flavorDimensions "target", "abi"
defaultConfig {
applicationId "com.example"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
vectorDrawables.useSupportLibrary true
multiDexEnabled true
}
signingConfigs {
release {
storeFile file("D:\\Keystore\\aaaaaaaa.jks")
storePassword "aaaaaaa"
keyAlias "avbbaaaaaa"
keyPassword "ababababa"
}
}
buildTypes {
release {
signingConfig null
minifyEnabled true
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
dataBinding {
enabled = true
}
productFlavors {
vanilla {
dimension "target"
versionCode = 1
}
chrome {
minSdkVersion 19
dimension "target"
versionCode = 2
}
ARMv7 {
dimension "abi"
versionCode = 4
}
x86 {
dimension "abi"
versionCode = 5
}
MIPS {
dimension "abi"
versionCode = 6
}
ARMv8 {
dimension "abi"
versionCode = 7
}
x86_64 {
dimension "abi"
versionCode = 8
}
MIPS64 {
dimension "abi"
versionCode = 9
}
}
}