Magisk/build.gradle.kts
topjohnwu ec8fffe61c Merge Magisk install zip into Magisk Manager
Distribute Magisk directly with Magisk Manager APK. The APK will
contain all required binaries and scripts for installation and
uninstallation. App versions will now align with Magisk releases.

Extra effort is spent to make the APK itself also a flashable zip that
can be used in custom recoveries, so those still prefer to install
Magisk with recoveries will not be affected with this change.

As a bonus, this makes the whole installation and uninstallation
process 100% offline. The existing Magisk Manager was not really
functional without an Internet connection, as the installation process
was highly tied to zips hosted on the server.

An additional bonus: since all binaries are now shipped as "native
libraries" of the APK, we can finally bump the target SDK version
higher than 28. The target SDK version was stuck at 28 for a long time
because newer SELinux restricts running executables from internal
storage. More details can be found here: https://github.com/termux/termux-app/issues/1072
The target SDK bump will be addressed in a future commit.

Co-authored with @vvb2060
2021-01-22 02:29:54 -08:00

130 lines
4.2 KiB
Plaintext

import com.android.build.gradle.BaseExtension
import java.nio.file.Paths
plugins {
id("MagiskPlugin")
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven { url = uri("https://kotlin.bintray.com/kotlinx") }
}
val vNav = "2.3.2"
extra["vNav"] = vNav
dependencies {
classpath("com.android.tools.build:gradle:4.1.2")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.21")
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)
}
val Project.android get() = extensions.getByName<BaseExtension>("android")
fun Task.applyOptimize() = doLast {
val aapt2 = Paths.get(project.android.sdkDirectory.path,
"build-tools", project.android.buildToolsVersion, "aapt2")
val zip = Paths.get(project.buildDir.path, "intermediates",
"shrunk_processed_res", "release", "resources-release-stripped.ap_")
val optimized = File("${zip}.opt")
val cmd = exec {
commandLine(aapt2, "optimize", "--collapse-resource-names",
"--shorten-resource-paths", "-o", optimized, zip)
isIgnoreExitValue = true
}
if (cmd.exitValue == 0) {
zip.toFile().delete()
optimized.renameTo(zip.toFile())
}
}
subprojects {
repositories {
google()
jcenter()
maven { url = uri("https://jitpack.io") }
maven { url = uri("http://oss.sonatype.org/content/repositories/snapshots") }
}
afterEvaluate {
if (plugins.hasPlugin("com.android.library") ||
plugins.hasPlugin("com.android.application")) {
android.apply {
compileSdkVersion(30)
buildToolsVersion = "30.0.2"
ndkPath = "${System.getenv("ANDROID_SDK_ROOT")}/ndk/magisk"
defaultConfig {
if (minSdkVersion == null)
minSdkVersion(17)
targetSdkVersion(28)
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
}
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"))
}
}
}
tasks.whenTaskAdded {
if (name == "shrinkReleaseRes") {
finalizedBy(tasks.create("optimizeReleaseRes").applyOptimize())
}
}
if (name == "app" || name == "stub") {
android.apply {
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")
}
}
}
}
}