Files
2026-09-15 15:44:13 +07:00

129 lines
4.3 KiB
Groovy
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
buildscript {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' } // 混淆
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
maven { url 'https://maven.aliyun.com/nexus/content/repositories/google' }
maven { url 'https://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }
}
dependencies {
classpath "com.github.CodingGay:BlackObfuscator-ASPlugin:3.9"
classpath 'com.github.Petterpx.walle:plugin:1.0.5'
}
}
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
maven { url 'https://maven.aliyun.com/nexus/content/repositories/google' }
maven { url 'https://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
def ensureAndroidNamespace = { project ->
def androidExtension = project.extensions.findByName("android")
if (androidExtension == null || !androidExtension.hasProperty("namespace") || androidExtension.namespace != null) {
return
}
def manifestFile = project.file("src/main/AndroidManifest.xml")
if (manifestFile.exists()) {
def manifestPackage = new XmlSlurper(false, false).parse(manifestFile).@package?.text()
if (manifestPackage) {
androidExtension.namespace = manifestPackage
return
}
}
if (project.group) {
androidExtension.namespace = project.group.toString()
}
}
def setLibraryCompileSdk = { project ->
def androidExtension = project.extensions.findByName("android")
if (androidExtension == null) {
return
}
try {
if (androidExtension.hasProperty("compileSdk")) {
androidExtension.compileSdk = 36
} else if (androidExtension.hasProperty("compileSdkVersion")) {
androidExtension.compileSdkVersion 36
}
} catch (Exception ignored) {
// AGP 已锁定 compileSdk,跳过;该模块用自己声明的值即可
}
}
def alignAndroidJvmTargets = { project ->
def androidExtension = project.extensions.findByName("android")
if (androidExtension == null) {
return
}
try {
if (androidExtension.hasProperty("compileOptions")) {
androidExtension.compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}
} catch (Exception ignored) {}
try {
if (androidExtension.hasProperty("kotlinOptions")) {
androidExtension.kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}
}
} catch (Exception ignored) {}
}
def finalizeAndroidAlignment = { project ->
if (project.plugins.hasPlugin("com.android.application") || project.plugins.hasPlugin("com.android.library")) {
ensureAndroidNamespace(project)
alignAndroidJvmTargets(project)
}
// afterEvaluate 阶段再强制一次 library 的 compileSdk,覆盖个别老插件
// (如 flutter_custom_dialog 在自身 build.gradle 写死 compileSdkVersion 28)
// 在 plugin apply 之后声明的低版本,否则配 Java 17 编译会报需 compileSdk≥30
if (project.plugins.hasPlugin("com.android.library")) {
setLibraryCompileSdk(project)
}
}
subprojects {
plugins.withId("com.android.application") {
ensureAndroidNamespace(project)
// app 自己 build.gradle 已声明 compileSdk 36,这里不再重设(AGP 8.x 在 plugin apply 后会立即锁定 compileSdk
}
plugins.withId("com.android.library") {
ensureAndroidNamespace(project)
setLibraryCompileSdk(project)
}
if (project.state.executed) {
finalizeAndroidAlignment(project)
} else {
afterEvaluate {
finalizeAndroidAlignment(project)
}
}
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}