Skip to content

Commit

Permalink
feat(android): support abi and v8 gradle setting
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 authored and siguangli committed Feb 17, 2021
1 parent 5651a1e commit 3efe5f1
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 40 deletions.
178 changes: 141 additions & 37 deletions android/sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply from: './bintrayUpload.gradle'

ext {
CMAKE_PATH = "$projectDir.absolutePath/src/main/jni/CMakeLists.txt"
OUTPUT_PATH = "$buildDir/outputs/aar/"
OUTPUT_PATH = "$buildDir/outputs/aar"
THIRD_PARTY_LIBRARY_PATH = "$projectDir.absolutePath/src/main/jni/third_party"
JNI_LIBRARY_PATH = "$projectDir.absolutePath/libs"
}
Expand Down Expand Up @@ -63,7 +63,7 @@ android {
consumerProguardFiles 'proguard-rules.pro'

buildConfigField("String", "PRODUCT_FLAVORS", "\"" + PRODUCT_FLAVORS + "\"")
buildConfigField("boolean", "ENABLE_SO_DOWNLOAD", (PRODUCT_FLAVORS == 'QQ') ? "false" : "true")
buildConfigField("boolean", "ENABLE_SO_DOWNLOAD", ENABLE_SO_DOWNLOAD)

packagingOptions {
pickFirst 'lib/armeabi-v7a/libmtt_shared.so'
Expand Down Expand Up @@ -93,10 +93,17 @@ android {
"-DCMAKE_BUILD_TYPE=Release",
"-DV8_VERSION=$V8_VERSION"

if (PRODUCT_FLAVORS == 'SIMULATOR') {
abiFilters 'x86', 'x86_64'
} else {
abiFilters 'armeabi-v7a', 'arm64-v8a'
if (INCLUDE_ABI_ARMEABI_V7A.toBoolean()) {
abiFilters 'armeabi-v7a'
}
if (INCLUDE_ABI_ARM64_V8A.toBoolean()) {
abiFilters 'arm64-v8a'
}
if (INCLUDE_ABI_X86.toBoolean()) {
abiFilters 'x86'
}
if (INCLUDE_ABI_X86_64.toBoolean()) {
abiFilters 'x86_64'
}
}
}
Expand All @@ -111,11 +118,7 @@ android {
"-DCMAKE_BUILD_TYPE=Debug",
"-DV8_VERSION=$V8_VERSION"

if (PRODUCT_FLAVORS == 'SIMULATOR') {
abiFilters 'x86_64'
} else {
abiFilters 'arm64-v8a'
}
abiFilters 'arm64-v8a'
}
}
}
Expand Down Expand Up @@ -153,49 +156,150 @@ dependencies {
}
}

task clearJNILibs() {
File libs = new File(JNI_LIBRARY_PATH);
if (libs.exists()) {
libs.deleteDir()
}
}
task copyJNILibs() {
file("$JNI_LIBRARY_PATH").deleteDir()

task installJNILibs(dependsOn: clearJNILibs) {
def arches = (PRODUCT_FLAVORS == 'SIMULATOR') ? ['x86', 'x86_64'] : ['armeabi-v7a', 'arm64-v8a']
for (arch in arches) {
if (INCLUDE_ABI_ARMEABI_V7A.toBoolean()) {
copy {
from "$THIRD_PARTY_LIBRARY_PATH/$V8_VERSION/v8/armeabi-v7a/libmtt_shared.so",
"$THIRD_PARTY_LIBRARY_PATH/$V8_VERSION/v8/armeabi-v7a/libmttv8.so",
"$THIRD_PARTY_LIBRARY_PATH/layout/armeabi-v7a/libflexbox.so"
into "$JNI_LIBRARY_PATH/armeabi-v7a/"
}
}
if (INCLUDE_ABI_ARM64_V8A.toBoolean()) {
copy {
from "$THIRD_PARTY_LIBRARY_PATH/$V8_VERSION/v8/arm64-v8a/libmtt_shared.so",
"$THIRD_PARTY_LIBRARY_PATH/$V8_VERSION/v8/arm64-v8a/libmttv8.so",
"$THIRD_PARTY_LIBRARY_PATH/layout/arm64-v8a/libflexbox.so"
into "$JNI_LIBRARY_PATH/arm64-v8a/"
}
}
if (INCLUDE_ABI_X86.toBoolean()) {
copy {
from "$THIRD_PARTY_LIBRARY_PATH/$V8_VERSION/v8/$arch/libmtt_shared.so",
"$THIRD_PARTY_LIBRARY_PATH/$V8_VERSION/v8/$arch/libmttv8.so",
"$THIRD_PARTY_LIBRARY_PATH/layout/$arch/libflexbox.so"
into "$JNI_LIBRARY_PATH/$arch/"
from "$THIRD_PARTY_LIBRARY_PATH/$V8_VERSION/v8/x86/libmtt_shared.so",
"$THIRD_PARTY_LIBRARY_PATH/$V8_VERSION/v8/x86/libmttv8.so",
"$THIRD_PARTY_LIBRARY_PATH/layout/x86/libflexbox.so"
into "$JNI_LIBRARY_PATH/x86/"
}
}
if (INCLUDE_ABI_X86_64.toBoolean()) {
copy {
from "$THIRD_PARTY_LIBRARY_PATH/$V8_VERSION/v8/x86_64/libmtt_shared.so",
"$THIRD_PARTY_LIBRARY_PATH/$V8_VERSION/v8/x86_64/libmttv8.so",
"$THIRD_PARTY_LIBRARY_PATH/layout/x86_64/libflexbox.so"
into "$JNI_LIBRARY_PATH/x86_64/"
}
}
}

afterEvaluate {
installJNILibs
android.libraryVariants.each { variant ->
def assembleTask
if (variant.buildType.name == 'release') {
assembleTask = project.tasks.findByName('assembleRelease')
} else {
assembleTask = project.tasks.findByName('assembleDebug')
}
assembleTask.finalizedBy dealAfterBuild
project.tasks.whenTaskAdded { task ->
if (task.name.equals('assembleRelease')) {
task.finalizedBy dealAfterAssembleRelease
}

if (task.name.equals('assembleDebug')) {
task.finalizedBy dealAfterAssembleDebug
}

}

task dealAfterBuild() {
afterEvaluate {
copyJNILibs
}

task dealAfterAssembleDebug() {
doLast {
file("$OUTPUT_PATH/debug").deleteDir()

file(OUTPUT_PATH).list().each{fileName ->
if (fileName.contains(".aar")) {
if (fileName.contains("debug.aar")) {
copy {
from zipTree("$OUTPUT_PATH/$fileName")
into "$OUTPUT_PATH/debug"
}
copy {
from "$OUTPUT_PATH/debug"
into OUTPUT_PATH
include 'classes.jar', 'jni/'
include 'classes.jar'
rename 'classes.jar', 'hippy.jar'
}
}
}
}
}

def releaseOutputFileName = "$ARCHIVES_BASE_NAME-release.aar"

task unzipAar() {
doLast {
file("$OUTPUT_PATH/release").deleteDir()

copy {
from zipTree("$OUTPUT_PATH/$releaseOutputFileName")
into "$OUTPUT_PATH/release"
}
copy {
from "$OUTPUT_PATH/release"
into OUTPUT_PATH
include 'classes.jar'
rename 'classes.jar', 'hippy.jar'
}
}
}

task addArmeabiDir(dependsOn: unzipAar) {
doLast {
if (INCLUDE_ABI_ARMEABI.toBoolean()) {
copy {
from "$OUTPUT_PATH/release/jni/armeabi-v7a"
into "$OUTPUT_PATH/release/jni/armeabi"
}
}
}
}

task excludeV8Libs(dependsOn: addArmeabiDir) {
doLast {
if (EXCLUDE_V8.toBoolean()) {
if (INCLUDE_ABI_ARMEABI.toBoolean()) {
file("$OUTPUT_PATH/release/jni/armeabi/libmttv8.so").delete()
file("$OUTPUT_PATH/release/jni/armeabi/libmtt_shared.so").delete()
}
if (INCLUDE_ABI_ARMEABI_V7A.toBoolean()) {
file("$OUTPUT_PATH/release/jni/armeabi-v7a/libmttv8.so").delete()
file("$OUTPUT_PATH/release/jni/armeabi-v7a/libmtt_shared.so").delete()
}
if (INCLUDE_ABI_ARM64_V8A.toBoolean()) {
file("$OUTPUT_PATH/release/jni/arm64-v8a/libmttv8.so").delete()
file("$OUTPUT_PATH/release/jni/arm64-v8a/libmtt_shared.so").delete()
}
if (INCLUDE_ABI_X86.toBoolean()) {
file("$OUTPUT_PATH/release/jni/x86/libmttv8.so").delete()
file("$OUTPUT_PATH/release/jni/x86/libmtt_shared.so").delete()
}
if (INCLUDE_ABI_X86_64.toBoolean()) {
file("$OUTPUT_PATH/release/jni/x86_64/libmttv8.so").delete()
file("$OUTPUT_PATH/release/jni/x86_64/libmtt_shared.so").delete()
}
}
}
}

task dealAfterAssembleRelease(dependsOn: excludeV8Libs) {
doLast {
if (INCLUDE_ABI_ARMEABI.toBoolean() || EXCLUDE_V8.toBoolean()) {
file("$OUTPUT_PATH/$releaseOutputFileName").delete()
exec {
def arguments = new ArrayList<?>()
arguments.add("a")
arguments.add("-tzip")
arguments.add("-mx=9")
arguments.add("$OUTPUT_PATH/$releaseOutputFileName")
arguments.add("$OUTPUT_PATH/release/*")
executable "7z"
args arguments
}
}
}
}
18 changes: 15 additions & 3 deletions android/sdk/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,28 @@ COMPILE_SDK_VERSION=29
BUILD_TOOLS_VERSION=30.0.3
MIN_SDK_VERSION=21
TARGET_SDK_VERSION=29
ARCHIVES_BASE_NAME=android-sdk

#jCenter sdk version
VERSION_NAME=2.3.4
VERSION_CODE=1

#COMMON QB QQ
PRODUCT_FLAVORS=COMMON

ARCHIVES_BASE_NAME=android-sdk
#ABI
INCLUDE_ABI_ARMEABI=false
INCLUDE_ABI_ARMEABI_V7A=true
INCLUDE_ABI_ARM64_V8A=true
INCLUDE_ABI_X86=false
INCLUDE_ABI_X86_64=false

#V8
V8_VERSION=v8_72
EXCLUDE_V8=false

#COMMON QB QQ SIMULATOR
PRODUCT_FLAVORS=COMMON
#features
ENABLE_SO_DOWNLOAD=false

#bintray publish params
#hippy-snapshot hippy-release
Expand Down

0 comments on commit 3efe5f1

Please sign in to comment.