Files
Hippy/framework/js/android/build.gradle
T

287 lines
7.9 KiB
Groovy

apply plugin: 'com.android.library'
apply from: './mavencentral.gradle'
ext {
CMAKE_PATH = "$projectDir.absolutePath/src/main/jni/CMakeLists.txt"
OUTPUT_PATH = "$buildDir/outputs/aar"
THIRD_PARTY_LIBRARY_PATH = "$projectDir.absolutePath/src/main/jni/third_party"
skipCmakeAndNinja = System.getenv('skipCmakeAndNinja') != null
}
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
ext {
MAVEN_USER = System.getenv('maven_username')
MAVEN_PWD = System.getenv('maven_password')
MAVEN_URL = System.getenv('maven_url')
println("MAVEN_USER=" + MAVEN_USER + ", MAVEN_PWD=" + MAVEN_PWD)
}
repositories {
if (MAVEN_URL != null) {
maven {
url MAVEN_URL
credentials {
username MAVEN_USER
password MAVEN_PWD
}
}
}
google()
mavenCentral()
}
}
android {
archivesBaseName = ARCHIVES_BASE_NAME
compileSdkVersion COMPILE_SDK_VERSION as int
ndkVersion = NDK_VERSION
defaultConfig {
minSdkVersion MIN_SDK_VERSION as int
targetSdkVersion TARGET_SDK_VERSION as int
versionCode VERSION_CODE as int
versionName VERSION_NAME
// 保证app使用aar时,会自动将该proguard文件添加到本身的proguard规则中
consumerProguardFiles 'proguard-rules.pro'
buildConfigField("boolean", "ENABLE_SO_DOWNLOAD", ENABLE_SO_DOWNLOAD)
buildConfigField("boolean", "INCLUDE_SUPPORT_UI", INCLUDE_SUPPORT_UI)
packagingOptions {
if (!INCLUDE_ABI_ARMEABI.toBoolean()) {
exclude 'lib/armeabi/*'
}
if (!INCLUDE_ABI_ARMEABI_V7A.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/*'
}
}
}
def V8_COMPONENT_DEBUG
def V8_COMPONENT_RELEASE
if (V8_COMPONENT == 'auto') {
V8_COMPONENT_DEBUG = 'third_party/v8/stable/official-release'
V8_COMPONENT_RELEASE = 'third_party/v8/stable/x5-lite'
} else {
V8_COMPONENT_DEBUG = V8_COMPONENT
V8_COMPONENT_RELEASE = V8_COMPONENT
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
externalNativeBuild {
cmake {
arguments "-DJS_ENGINE=V8",
"-DANDROID_CPP_FEATURES=rtti exceptions",
"-DANDROID_PLATFORM=android-21",
"-DCMAKE_BUILD_TYPE=Release",
"-DANDROID_STL=$ANDROID_STL",
"-DV8_COMPONENT=$V8_COMPONENT_RELEASE",
"-DHIDDEN_LIBRARY_SYMBOL=$HIDDEN_LIBRARY_SYMBOL"
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 {
arguments "-DJS_ENGINE=V8",
"-DANDROID_CPP_FEATURES=rtti exceptions",
"-DANDROID_PLATFORM=android-21",
"-DCMAKE_BUILD_TYPE=Debug",
"-DANDROID_STL=$ANDROID_STL",
"-DV8_COMPONENT=$V8_COMPONENT_DEBUG",
"-DHIDDEN_LIBRARY_SYMBOL=$HIDDEN_LIBRARY_SYMBOL"
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() || !skipCmakeAndNinja) {
externalNativeBuild {
cmake {
path CMAKE_PATH
}
}
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
sourceSets{
main {
if (INCLUDE_SUPPORT_UI.toBoolean() == false) {
java.exclude("com/tencent/mtt/supportui/**")
}
jniLibs.srcDirs = ["${THIRD_PARTY_LIBRARY_PATH}/layout"]
}
}
}
dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
compileOnly project(path: ':hippy-support')
compileOnly project(path: ':renderer-native')
compileOnly project(path: ':serialization')
//noinspection GradleDependency
implementation 'androidx.annotation:annotation:1.0.0'
if (!INCLUDE_SUPPORT_UI.toBoolean()) {
compileOnly('com.tencent.mtt:support-ui:99.2.3')
}
testImplementation "junit:junit:4.13.2"
testImplementation "org.mockito:mockito-core:2.8.9"
testImplementation "org.mockito:mockito-android:2.8.9"
testImplementation "org.powermock:powermock-module-junit4:2.0.7"
testImplementation "org.powermock:powermock-api-mockito2:2.0.7"
testImplementation 'org.powermock:powermock-core:2.0.7'
testImplementation "org.powermock:powermock-module-junit4-rule:2.0.7"
testImplementation "org.powermock:powermock-classloading-xstream:2.0.7"
testImplementation "org.robolectric:robolectric:4.4"
}
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
}
}
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"
}
}
delete "$mergedNativeLibsPath/armeabi"
if (INCLUDE_ABI_ARMEABI.toBoolean()) {
copy {
from "$mergedNativeLibsPath/armeabi-v7a"
into "$mergedNativeLibsPath/armeabi"
}
if (!INCLUDE_ABI_ARMEABI_V7A.toBoolean()) {
delete "$mergedNativeLibsPath/armeabi-v7a"
}
}
}
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 dealAfterAssemble(buildType) {
file("$OUTPUT_PATH/$buildType").deleteDir()
file(OUTPUT_PATH).list().each{fileName ->
if (fileName.contains(buildType + ".aar")) {
copy {
from zipTree("$OUTPUT_PATH/$fileName")
into "$OUTPUT_PATH/$buildType"
}
copy {
from "$OUTPUT_PATH/$buildType"
into OUTPUT_PATH
include 'classes.jar'
rename 'classes.jar', 'hippy.jar'
}
}
}
}
task dealAfterAssembleDebug() {
doLast {
dealAfterAssemble("debug")
}
}
task dealAfterAssembleRelease() {
doLast {
dealAfterAssemble("release")
copy {
from "$OUTPUT_PATH/$ARCHIVES_BASE_NAME-release.aar"
into "$projectDir.absolutePath/../examples/android-demo/example/libs"
}
}
}