Switch to lsplugin cmaker

Reduce binary size by configuring right flags with it.

Signed-off-by: GarfieldHan <2652609017@qq.com>
This commit is contained in:
GarfieldHan
2024-07-18 10:56:55 +08:00
parent 55cbe69ad5
commit ee8ef65dc9
3 changed files with 25 additions and 20 deletions

View File

@@ -5,6 +5,7 @@ import java.security.MessageDigest
plugins {
alias(libs.plugins.agp.app)
alias(libs.plugins.lsplugin.cmaker)
}
val moduleId: String by rootProject.extra
@@ -16,9 +17,9 @@ val abiList: List<String> by rootProject.extra
val androidMinSdkVersion: Int by rootProject.extra
val releaseFlags = arrayOf(
"-Oz", "-flto",
"-O3", "-flto",
"-Wno-unused", "-Wno-unused-parameter",
"-Wl,--exclude-libs,ALL", "-Wl,--gc-sections",
"-Wl,--exclude-libs,ALL", "-Wl,-icf=all,--lto-O3", "-Wl,-s,-x,--gc-sections"
)
android {
@@ -26,15 +27,6 @@ android {
ndk {
abiFilters.addAll(abiList)
}
externalNativeBuild {
cmake {
cppFlags("-std=c++23")
arguments(
"-DANDROID_STL=none",
"-DMODULE_NAME=$moduleId"
)
}
}
}
buildFeatures {
@@ -47,13 +39,25 @@ android {
path("src/main/cpp/CMakeLists.txt")
}
}
}
cmaker {
default {
val cmakeArgs = arrayOf(
"-DANDROID_STL=none",
"-DMODULE_NAME=$moduleId",
)
arguments += cmakeArgs
abiFilters("arm64-v8a", "x86_64")
}
buildTypes {
release {
externalNativeBuild.cmake {
cFlags += releaseFlags
when (it.name) {
"release" -> {
cppFlags += releaseFlags
cFlags += releaseFlags
}
}
cppFlags += "--std=c++23"
}
}