Files

331 lines
11 KiB
Groovy

/*
*
* Tencent is pleased to support the open source community by making
* Hippy available.
*
* Copyright (C) 2022 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import java.nio.file.Paths
apply plugin: 'com.android.library'
apply plugin: 'com.kezong.fat-aar'
apply from: './publish.gradle'
def mergeCppDefinitions() {
def cppProps = new Properties()
getAllModules().each {
def propsFile
if (Paths.get(it).isAbsolute()) {
propsFile = file(it)
} else {
propsFile = file(Paths.get("connector", it, "gradle.properties"))
}
if (propsFile.exists()) {
propsFile.withInputStream { cppProps.load(it) }
}
}
project.getProperties().forEach { key, value ->
if (key != null && value != null && value instanceof String) {
cppProps.setProperty(key, value)
}
}
def cppDefinitions = []
cppProps.forEach { key, value ->
if (key.startsWith("CPP_")) {
cppDefinitions.add("-D${key.replaceFirst('^CPP_', '')}=${value}")
}
}
return cppDefinitions
}
android {
archivesBaseName = ARCHIVES_BASE_NAME
compileSdkVersion COMPILE_VERSION as int
ndkVersion = NDK_VERSION
defaultConfig {
minSdkVersion MIN_VERSION as int
targetSdkVersion TARGET_VERSION as int
versionName VERSION_NAME
// 保证app使用aar时,会自动将该proguard文件添加到本身的proguard规则中
consumerProguardFiles 'proguard-rules.pro'
buildConfigField("boolean", "ENABLE_SO_LOAD_EXTERNAL", ENABLE_SO_LOAD_EXTERNAL)
buildConfigField("boolean", "ENABLE_BUGLY_REPORT", ENABLE_BUGLY_REPORT)
buildConfigField("String", "LIBRARY_VERSION", "String.valueOf(\"$VERSION_NAME\")")
packagingOptions {
if (!INCLUDE_ABI_ARMEABI.toBoolean()) {
exclude 'lib/armeabi/*'
}
if (!INCLUDE_ABI_ARMEABI_V7A.toBoolean() && !INCLUDE_ABI_ARMEABI.toBoolean()) {
exclude 'lib/armeabi-v7a/*'
}
if (!INCLUDE_ABI_ARM64_V8A.toBoolean()) {
exclude 'lib/arm64-v8a/*'
}
if (!INCLUDE_ABI_X86.toBoolean()) {
exclude 'lib/x86/*'
}
if (!INCLUDE_ABI_X86_64.toBoolean()) {
exclude 'lib/x86_64/*'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
externalNativeBuild {
cmake {
assert !(INCLUDE_ABI_ARMEABI.toBoolean() && ANDROID_ARM_NEON.toBoolean())
arguments (
"-DCMAKE_BUILD_TYPE=Release",
"-DMODULES=${getAllModules().join(';')}",
*mergeCppDefinitions()
)
if (INCLUDE_ABI_ARMEABI_V7A.toBoolean() || INCLUDE_ABI_ARMEABI.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'
}
}
}
}
debug {
minifyEnabled false
externalNativeBuild {
cmake {
assert !(INCLUDE_ABI_ARMEABI.toBoolean() && ANDROID_ARM_NEON.toBoolean())
arguments (
"-DCMAKE_BUILD_TYPE=Debug",
"-DMODULES=${getAllModules().join(';')}",
"-DENABLE_INSPECTOR=$ENABLE_INSPECTOR",
*mergeCppDefinitions()
)
if (INCLUDE_ABI_ARMEABI_V7A.toBoolean() || INCLUDE_ABI_ARMEABI.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'
}
}
}
}
}
if (!SKIP_CMAKE_AND_NINJA.toBoolean() && System.getenv('skipCmakeAndNinja') == null) {
externalNativeBuild {
cmake {
version CMAKE_VERSION
path "src/main/cpp/CMakeLists.txt"
}
}
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
}
dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
embed project(path: ':serialization', configuration: 'default')
embed project(path: ':hippy-support', configuration: 'default')
embed project(path: ':vfs', configuration: 'default')
embed project(path: ':pool', configuration: 'default')
embed project(path: ':devtools-integration', configuration: 'default')
getAllModules().each {
def module = Paths.get(it)
def path = ['connector']
if (module.isAbsolute()) {
path.push(module.getFileName())
} else {
for (def i = 0; i < module.getNameCount(); i++) {
path.push(module.getName(i))
}
}
embed project(path: ":${path.reverse().join('-')}", configuration: 'default')
if (it == 'renderer/native') {
embed project(path: ':renderer-native', configuration: 'default')
}
}
compileOnly project(path: ':renderer-native')
//noinspection GradleDependency
implementation deps.annotation
testImplementation deps.junit
testImplementation deps.mockito_core
testImplementation deps.mockito_android
testImplementation deps.powermock_module_junit
testImplementation deps.powermock_api_mockito2
testImplementation deps.powermock_core
testImplementation deps.powermock_module_junit4_rule
testImplementation deps.powermock_classloading_xstream
testImplementation deps.robolectric
}
project.tasks.whenTaskAdded { task ->
if (task.name == 'assembleRelease') {
task.finalizedBy dealAfterAssembleRelease
}
if (task.name == 'assembleDebug') {
task.finalizedBy dealAfterAssembleDebug
}
if (task.name == 'mergeReleaseNativeLibs') {
task.finalizedBy dealAfterMergeReleaseNativeLibs
}
if (task.name == 'mergeDebugNativeLibs') {
task.finalizedBy dealAfterMergeDebugNativeLibs
}
if (task.name == 'stripReleaseDebugSymbols') {
task.finalizedBy dealAfterStripReleaseDebugSymbols
}
if (task.name == 'stripDebugDebugSymbols') {
task.finalizedBy dealAfterStripDebugDebugSymbols
}
}
def dealAfterMergeNativeLibs(mergedNativeLibsPath) {
EXCLUDE_LIBRARY_FILES.tokenize(";").each { filename ->
if (INCLUDE_ABI_ARMEABI_V7A.toBoolean() || INCLUDE_ABI_ARMEABI.toBoolean()) {
delete "$mergedNativeLibsPath/armeabi-v7a/$filename"
}
if (INCLUDE_ABI_ARM64_V8A.toBoolean()) {
delete "$mergedNativeLibsPath/arm64-v8a/$filename"
}
if (INCLUDE_ABI_X86.toBoolean()) {
delete "$mergedNativeLibsPath/x86/$filename"
}
if (INCLUDE_ABI_X86_64.toBoolean()) {
delete "$mergedNativeLibsPath/x86_64/$filename"
}
}
}
def MERGED_NATIVE_LIBS_PATH = "$buildDir/intermediates/merged_native_libs"
task dealAfterMergeReleaseNativeLibs() {
doLast {
dealAfterMergeNativeLibs("$MERGED_NATIVE_LIBS_PATH/release/out/lib")
}
}
task dealAfterMergeDebugNativeLibs() {
doLast {
dealAfterMergeNativeLibs("$MERGED_NATIVE_LIBS_PATH/debug/out/lib")
}
}
def dealAfterStripSymbols(strippedNativeLibsPath) {
delete "$strippedNativeLibsPath/armeabi"
if (INCLUDE_ABI_ARMEABI.toBoolean()) {
copy {
from "$strippedNativeLibsPath/armeabi-v7a"
into "$strippedNativeLibsPath/armeabi"
}
if (!INCLUDE_ABI_ARMEABI_V7A.toBoolean()) {
delete "$strippedNativeLibsPath/armeabi-v7a"
}
}
}
def STRIPPED_NATIVE_LIBS_PATH = "$buildDir/intermediates/stripped_native_libs"
task dealAfterStripReleaseDebugSymbols() {
doLast {
dealAfterStripSymbols("$STRIPPED_NATIVE_LIBS_PATH/release/out/lib")
}
}
task dealAfterStripDebugDebugSymbols() {
doLast {
dealAfterStripSymbols("$STRIPPED_NATIVE_LIBS_PATH/debug/out/lib")
}
}
def dealAfterAssemble(outputPath, buildType) {
file("$outputPath/$buildType").deleteDir()
File target = file("$outputPath/$ARCHIVES_BASE_NAME" + ".aar")
delete target
file(outputPath).list().each { fileName ->
if (fileName.contains(buildType + ".aar")) {
copy {
from zipTree("$outputPath/$fileName")
into "$outputPath/$buildType"
}
copy {
from "$outputPath/$buildType"
into outputPath
include 'classes.jar'
rename 'classes.jar', 'hippy.jar'
}
file("$outputPath/$fileName").renameTo(target)
}
}
}
def OUTPUT_PATH = "$buildDir/outputs/aar"
task dealAfterAssembleDebug() {
doLast {
dealAfterAssemble(OUTPUT_PATH, "debug")
}
}
task dealAfterAssembleRelease() {
doLast {
dealAfterAssemble(OUTPUT_PATH, "release")
def fileName = "$OUTPUT_PATH/$ARCHIVES_BASE_NAME" + ".aar"
copy {
from fileName
into "$projectDir.absolutePath/../examples/android-demo/libs"
}
}
}
project.afterEvaluate {
project.android.libraryVariants.all { variant ->
def variantName = variant.name.capitalize()
def taskMergeClasses = project.tasks.named("mergeClasses${variantName}")
project.tasks.named("bundleLibCompileToJar${variantName}").configure {
dependsOn(taskMergeClasses)
}
}
}