Move config to buildSrc

This commit is contained in:
vvb2060 2021-09-08 00:45:15 +08:00 committed by John Wu
parent 9bf835e810
commit 810cf4dee8
8 changed files with 103 additions and 120 deletions

View File

@ -20,6 +20,8 @@ kapt {
}
}
setupApp()
android {
defaultConfig {
applicationId = "com.topjohnwu.magisk"
@ -30,7 +32,7 @@ android {
}
buildTypes {
getByName("release") {
release {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles("proguard-rules.pro")
@ -135,7 +137,9 @@ val syncResources by tasks.registering(Sync::class) {
}
}
tasks["preBuild"]?.dependsOn(syncResources)
tasks.preBuild {
dependsOn(syncResources)
}
android.applicationVariants.all {
val keysDir = rootProject.file("tools/keys")
@ -203,7 +207,7 @@ dependencies {
implementation("androidx.room:room-ktx:${vRoom}")
kapt("androidx.room:room-compiler:${vRoom}")
val vNav: String by rootProject.extra
val vNav = "2.4.0-alpha07"
implementation("androidx.navigation:navigation-fragment-ktx:${vNav}")
implementation("androidx.navigation:navigation-ui-ktx:${vNav}")

View File

@ -2,9 +2,10 @@ plugins {
id("com.android.library")
}
setupCommon()
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
consumerProguardFiles("proguard-rules.pro")
}
}

View File

@ -1,105 +1,7 @@
import com.android.build.gradle.BaseExtension
plugins {
id("MagiskPlugin")
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
val vNav = "2.4.0-alpha06"
extra["vNav"] = vNav
dependencies {
classpath("com.android.tools.build:gradle:7.0.2")
classpath(kotlin("gradle-plugin", version = "1.5.30"))
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:${vNav}")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
fun Project.android(configuration: BaseExtension.() -> Unit) =
extensions.getByName<BaseExtension>("android").configuration()
subprojects {
repositories {
google()
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
afterEvaluate {
if (plugins.hasPlugin("com.android.library") ||
plugins.hasPlugin("com.android.application")
) {
android {
compileSdkVersion(31)
buildToolsVersion = "31.0.0"
ndkPath = "${System.getenv("ANDROID_SDK_ROOT")}/ndk/magisk"
defaultConfig {
if (minSdk == null)
minSdk = 21
targetSdk = 31
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}
}
if (plugins.hasPlugin("java")) {
tasks.withType<JavaCompile> {
// If building with JDK 9+, we need additional flags to generate compatible bytecode
if (JavaVersion.current() > JavaVersion.VERSION_1_8) {
options.compilerArgs.addAll(listOf("--release", "8"))
}
}
}
if (name == "app" || name == "stub") {
android {
signingConfigs {
create("config") {
Config["keyStore"]?.also {
storeFile = rootProject.file(it)
storePassword = Config["keyStorePass"]
keyAlias = Config["keyAlias"]
keyPassword = Config["keyPass"]
}
}
}
buildTypes {
signingConfigs.getByName("config").also {
getByName("debug") {
signingConfig = if (it.storeFile?.exists() == true) it
else signingConfigs.getByName("debug")
}
getByName("release") {
signingConfig = if (it.storeFile?.exists() == true) it
else signingConfigs.getByName("debug")
}
}
}
lintOptions {
disable += "MissingTranslation"
}
}
}
}
}

View File

@ -2,6 +2,7 @@ plugins {
`kotlin-dsl`
}
repositories {
google()
mavenCentral()
}
@ -15,5 +16,9 @@ gradlePlugin {
}
dependencies {
implementation(kotlin("gradle-plugin", "1.5.30"))
implementation("com.android.tools.build:gradle:7.0.2")
implementation("androidx.navigation:navigation-safe-args-gradle-plugin:2.4.0-alpha07")
implementation("io.michaelrocks:paranoid-gradle-plugin:0.3.5")
implementation("org.eclipse.jgit:org.eclipse.jgit:5.12.0.202106070339-r")
}

View File

@ -0,0 +1,68 @@
import com.android.build.gradle.BaseExtension
import org.gradle.api.Action
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.kotlin.dsl.withType
private fun Project.android(configure: Action<BaseExtension>) = extensions.configure("android", configure)
fun Project.setupCommon() {
android {
compileSdkVersion(31)
buildToolsVersion = "31.0.0"
ndkPath = "${System.getenv("ANDROID_SDK_ROOT")}/ndk/magisk"
defaultConfig {
minSdk = 21
targetSdk = 31
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}
if (plugins.hasPlugin("java")) {
tasks.withType<JavaCompile> {
// If building with JDK 9+, we need additional flags to generate compatible bytecode
if (JavaVersion.current() > JavaVersion.VERSION_1_8) {
options.compilerArgs.addAll(listOf("--release", "8"))
}
}
}
}
fun Project.setupApp() {
setupCommon()
android {
signingConfigs {
create("config") {
Config["keyStore"]?.also {
storeFile = rootProject.file(it)
storePassword = Config["keyStorePass"]
keyAlias = Config["keyAlias"]
keyPassword = Config["keyPass"]
}
}
}
buildTypes {
signingConfigs.getByName("config").also {
getByName("debug") {
signingConfig = if (it.storeFile?.exists() == true) it
else signingConfigs.getByName("debug")
}
getByName("release") {
signingConfig = if (it.storeFile?.exists() == true) it
else signingConfigs.getByName("debug")
}
}
}
lintOptions {
disable += "MissingTranslation"
}
}
}

View File

@ -2,8 +2,9 @@ plugins {
id("com.android.library")
}
android {
setupCommon()
android {
externalNativeBuild {
ndkBuild {
path("jni/Android.mk")
@ -15,7 +16,7 @@ android {
ndkBuild {
// Pass arguments to ndk-build.
arguments("B_MAGISK=1", "B_INIT=1", "B_BOOT=1", "B_TEST=1",
"MAGISK_DEBUG=1", "MAGISK_VERSION=debug", "MAGISK_VER_CODE=INT_MAX")
"MAGISK_DEBUG=1", "MAGISK_VERSION=debug", "MAGISK_VER_CODE=INT_MAX")
}
}
}

View File

@ -1 +1,11 @@
@Suppress("UnstableApiUsage")
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven("https://jitpack.io")
}
}
rootProject.name = "Magisk"
include(":app", ":app:shared", ":native", ":stub")

View File

@ -1,5 +1,3 @@
import io.michaelrocks.paranoid.plugin.ParanoidExtension
import org.gradle.internal.os.OperatingSystem
import java.io.OutputStream
import java.io.PrintStream
@ -7,24 +5,16 @@ import java.nio.file.Paths
plugins {
id("com.android.application")
id("io.michaelrocks.paranoid")
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("io.michaelrocks:paranoid-gradle-plugin:0.3.5")
}
}
apply(plugin = "io.michaelrocks.paranoid")
extensions.configure<ParanoidExtension>("paranoid") {
paranoid {
obfuscationSeed = if (RAND_SEED != 0) RAND_SEED else null
includeSubprojects = true
}
setupApp()
android {
val canary = !Config.version.contains(".")
@ -40,7 +30,7 @@ android {
}
buildTypes {
getByName("release") {
release {
isMinifyEnabled = true
isShrinkResources = false
proguardFiles("proguard-rules.pro")
@ -63,7 +53,9 @@ val ensureManifest by tasks.registering {
}
}
tasks["preBuild"]?.dependsOn(ensureManifest)
tasks.preBuild {
dependsOn(ensureManifest)
}
android.applicationVariants.all {
val manifest = file("src/main/AndroidManifest.xml")