Welcome Gradle Kotlin DSL

This commit is contained in:
topjohnwu 2020-07-04 06:53:31 -07:00
parent 67f7935421
commit 7922f65243
17 changed files with 425 additions and 371 deletions

View File

@ -1,145 +0,0 @@
plugins {
id("com.android.application")
id("kotlin-android")
id("kotlin-android-extensions")
id("kotlin-kapt")
id("androidx.navigation.safeargs.kotlin")
}
kapt {
correctErrorTypes = true
useBuildCache = true
mapDiagnosticLocations = true
javacOptions {
option("-Xmaxerrs", 1000)
}
}
android {
defaultConfig {
applicationId 'com.topjohnwu.magisk'
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
versionName props['appVersion']
versionCode props['appVersionCode'] as Integer
buildConfigField 'int', 'LATEST_MAGISK', props['versionCode'] ?: 'Integer.MAX_VALUE'
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.incremental": "true"]
}
}
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
'proguard-rules.pro'
}
}
buildFeatures {
dataBinding = true
}
dependenciesInfo {
includeInApk = false
includeInBundle = false
}
packagingOptions {
exclude '/META-INF/**'
exclude '/androidsupportmultidexversion.txt'
exclude '/org/bouncycastle/**'
exclude '/kotlin/**'
exclude '/kotlinx/**'
exclude '/okhttp3/**'
}
kotlinOptions {
jvmTarget = '1.8'
}
}
androidExtensions {
experimental = true
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':app:shared')
implementation project(':app:signing')
implementation 'com.github.topjohnwu:jtar:1.0.0'
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'com.github.pwittchen:reactivenetwork-rx2:3.0.8'
implementation 'io.reactivex.rxjava2:rxjava:2.2.19'
implementation 'io.reactivex.rxjava2:rxkotlin:2.4.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib:${vKotlin}"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${vKotlin}"
def vBAdapt = '4.0.0'
def bindingAdapter = 'me.tatarka.bindingcollectionadapter2:bindingcollectionadapter'
implementation "${bindingAdapter}:${vBAdapt}"
implementation "${bindingAdapter}-recyclerview:${vBAdapt}"
def vMarkwon = '4.4.0'
implementation "io.noties.markwon:core:${vMarkwon}"
implementation "io.noties.markwon:html:${vMarkwon}"
implementation "io.noties.markwon:image:${vMarkwon}"
implementation 'com.caverock:androidsvg:1.4'
def vLibsu = '2.5.1'
implementation "com.github.topjohnwu.libsu:core:${vLibsu}"
implementation "com.github.topjohnwu.libsu:io:${vLibsu}"
def vKoin = '2.1.6'
implementation "org.koin:koin-core:${vKoin}"
implementation "org.koin:koin-android:${vKoin}"
implementation "org.koin:koin-androidx-viewmodel:${vKoin}"
def vRetrofit = '2.9.0'
implementation "com.squareup.retrofit2:retrofit:${vRetrofit}"
implementation "com.squareup.retrofit2:converter-moshi:${vRetrofit}"
implementation "com.squareup.retrofit2:converter-scalars:${vRetrofit}"
implementation "com.squareup.retrofit2:adapter-rxjava2:${vRetrofit}"
def vOkHttp = '3.12.12'
implementation("com.squareup.okhttp3:okhttp") {
version {
strictly "$vOkHttp"
}
}
implementation "com.squareup.okhttp3:logging-interceptor:${vOkHttp}"
implementation("com.squareup.okhttp3:okhttp-dnsoverhttps:${vOkHttp}")
def vMoshi = '1.9.3'
implementation "com.squareup.moshi:moshi:${vMoshi}"
kapt "com.squareup.moshi:moshi-kotlin-codegen:${vMoshi}"
def vRoom = '2.2.5'
implementation "androidx.room:room-runtime:${vRoom}"
implementation "androidx.room:room-rxjava2:${vRoom}"
kapt "androidx.room:room-compiler:${vRoom}"
implementation "androidx.navigation:navigation-fragment-ktx:${vNav}"
implementation "androidx.navigation:navigation-ui-ktx:${vNav}"
implementation 'androidx.biometric:biometric:1.0.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta7'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.browser:browser:1.2.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.fragment:fragment-ktx:1.2.5'
implementation 'androidx.work:work-runtime:2.3.4'
implementation 'androidx.transition:transition:1.3.1'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'com.google.android.material:material:1.2.0-beta01'
}

153
app/build.gradle.kts Normal file
View File

@ -0,0 +1,153 @@
import java.util.*
plugins {
id("com.android.application")
kotlin("android")
kotlin("android.extensions")
kotlin("kapt")
id("androidx.navigation.safeargs.kotlin")
}
val props = Properties()
val vKotlin = "1.3.72"
val vNav = "2.3.0"
kapt {
correctErrorTypes = true
useBuildCache = true
mapDiagnosticLocations = true
javacOptions {
option("-Xmaxerrs", 1000)
}
}
android {
defaultConfig {
applicationId = "com.topjohnwu.magisk"
vectorDrawables.useSupportLibrary = true
multiDexEnabled = true
versionName = Config["appVersion"]
versionCode = Config["appVersionCode"]?.toInt()
buildConfigField("int", "LATEST_MAGISK", Config["versionCode"] ?: "Integer.MAX_VALUE")
javaCompileOptions {
annotationProcessorOptions {
arguments = mapOf("room.incremental" to "true")
}
}
}
buildTypes {
getByName("release") {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
buildFeatures {
dataBinding = true
}
dependenciesInfo {
includeInApk = false
includeInBundle = false
}
packagingOptions {
exclude("/META-INF/**")
exclude("/androidsupportmultidexversion.txt")
exclude("/org/bouncycastle/**")
exclude("/kotlin/**")
exclude("/kotlinx/**")
exclude("/okhttp3/**")
}
kotlinOptions {
jvmTarget = "1.8"
}
}
androidExtensions {
isExperimental = true
}
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation(project(":app:shared"))
implementation(project(":app:signing"))
implementation("com.github.topjohnwu:jtar:1.0.0")
implementation("com.jakewharton.timber:timber:4.7.1")
implementation("com.github.pwittchen:reactivenetwork-rx2:3.0.8")
implementation("io.reactivex.rxjava2:rxjava:2.2.19")
implementation("io.reactivex.rxjava2:rxkotlin:2.4.0")
implementation("io.reactivex.rxjava2:rxandroid:2.1.1")
implementation("org.jetbrains.kotlin:kotlin-stdlib:${Deps.vKotlin}")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Deps.vKotlin}")
val vBAdapt = "4.0.0"
val bindingAdapter = "me.tatarka.bindingcollectionadapter2:bindingcollectionadapter"
implementation("${bindingAdapter}:${vBAdapt}")
implementation("${bindingAdapter}-recyclerview:${vBAdapt}")
val vMarkwon = "4.4.0"
implementation("io.noties.markwon:core:${vMarkwon}")
implementation("io.noties.markwon:html:${vMarkwon}")
implementation("io.noties.markwon:image:${vMarkwon}")
implementation("com.caverock:androidsvg:1.4")
val vLibsu = "2.5.1"
implementation("com.github.topjohnwu.libsu:core:${vLibsu}")
implementation("com.github.topjohnwu.libsu:io:${vLibsu}")
val vKoin = "2.1.6"
implementation("org.koin:koin-core:${vKoin}")
implementation("org.koin:koin-android:${vKoin}")
implementation("org.koin:koin-androidx-viewmodel:${vKoin}")
val vRetrofit = "2.9.0"
implementation("com.squareup.retrofit2:retrofit:${vRetrofit}")
implementation("com.squareup.retrofit2:converter-moshi:${vRetrofit}")
implementation("com.squareup.retrofit2:converter-scalars:${vRetrofit}")
implementation("com.squareup.retrofit2:adapter-rxjava2:${vRetrofit}")
val vOkHttp = "3.12.12"
implementation("com.squareup.okhttp3:okhttp") {
version {
strictly(vOkHttp)
}
}
implementation("com.squareup.okhttp3:logging-interceptor:${vOkHttp}")
implementation("com.squareup.okhttp3:okhttp-dnsoverhttps:${vOkHttp}")
val vMoshi = "1.9.3"
implementation("com.squareup.moshi:moshi:${vMoshi}")
kapt("com.squareup.moshi:moshi-kotlin-codegen:${vMoshi}")
val vRoom = "2.2.5"
implementation("androidx.room:room-runtime:${vRoom}")
implementation("androidx.room:room-rxjava2:${vRoom}")
kapt("androidx.room:room-compiler:${vRoom}")
implementation("androidx.navigation:navigation-fragment-ktx:${Deps.vNav}")
implementation("androidx.navigation:navigation-ui-ktx:${Deps.vNav}")
implementation("androidx.biometric:biometric:1.0.1")
implementation("androidx.constraintlayout:constraintlayout:2.0.0-beta7")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
implementation("androidx.browser:browser:1.2.0")
implementation("androidx.preference:preference:1.1.1")
implementation("androidx.recyclerview:recyclerview:1.1.0")
implementation("androidx.fragment:fragment-ktx:1.2.5")
implementation("androidx.work:work-runtime:2.3.4")
implementation("androidx.transition:transition:1.3.1")
implementation("androidx.multidex:multidex:2.0.1")
implementation("androidx.core:core-ktx:1.3.0")
implementation("com.google.android.material:material:1.2.0-beta01")
}

View File

@ -1,12 +0,0 @@
apply plugin: 'com.android.library'
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
consumerProguardFiles 'proguard-rules.pro'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}

View File

@ -0,0 +1,14 @@
plugins {
id("com.android.library")
}
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
consumerProguardFiles("proguard-rules.pro")
}
}
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
}

View File

@ -1,39 +0,0 @@
apply plugin: 'java-library'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
jar {
manifest {
attributes 'Main-Class': 'com.topjohnwu.signing.ZipSigner'
}
}
shadowJar {
baseName = 'zipsigner'
classifier = null
version = 3.0
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
}
}
repositories {
jcenter()
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
api "org.bouncycastle:bcprov-jdk15on:1.65.01"
api "org.bouncycastle:bcpkix-jdk15on:1.65"
}

View File

@ -0,0 +1,35 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
id("java-library")
id("java")
id("com.github.johnrengelman.shadow") version "6.0.0"
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
val jar by tasks.getting(Jar::class) {
manifest {
attributes["Main-Class"] = "com.topjohnwu.signing.ZipSigner"
}
}
val shadowJar by tasks.getting(ShadowJar::class) {
baseName = "zipsigner"
classifier = null
version = "3.0"
}
repositories {
jcenter()
}
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
api("org.bouncycastle:bcprov-jdk15on:1.65.01")
api("org.bouncycastle:bcpkix-jdk15on:1.65")
}

View File

@ -1,128 +0,0 @@
import java.nio.file.Paths
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.vKotlin = '1.3.72'
ext.vNav = '2.3.0'
repositories {
google()
jcenter()
maven { url 'http://storage.googleapis.com/r8-releases/raw' }
maven { url 'https://kotlin.bintray.com/kotlinx' }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${vKotlin}"
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
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
String.metaClass.toFile = { new File(delegate) }
def configFile = rootProject.findProperty('configPath')?.toFile() ?: rootProject.file('config.prop')
if (!configFile.exists())
throw new GradleException("Please setup config.prop")
def props = new Properties()
configFile.withInputStream { is -> props.load(is) }
ext.props = props
subprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
maven { url "http://oss.sonatype.org/content/repositories/snapshots" }
}
afterEvaluate { module ->
if (getPlugins().hasPlugin('com.android.library') ||
getPlugins().hasPlugin('com.android.application')) {
android {
compileSdkVersion 30
buildToolsVersion '30.0.0'
defaultConfig {
if (minSdkVersion == null)
minSdkVersion 17
targetSdkVersion 28
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
}
tasks.whenTaskAdded { task ->
if (task.name == 'processReleaseResources') {
task.finalizedBy tasks.create('optimizeReleaseResources') {
doLast {
def aapt2 = Paths.get(android.sdkDirectory.path,
'build-tools', android.buildToolsVersion, 'aapt2')
def zip = Paths.get(project.buildDir.path, 'intermediates',
'processed_res', 'release', 'out', 'resources-release.ap_')
def optimized = new File("${zip}.opt")
def cmd = exec {
commandLine aapt2, 'optimize', '--collapse-resource-names',
'--shorten-resource-paths', '-o', optimized, zip
ignoreExitValue true
}
if (cmd.exitValue == 0) {
optimized.renameTo("$zip")
}
}
}
}
}
if (getPlugins().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 += ['--release', '8']
}
}
}
if (module.name == 'app' || module.name == 'stub') {
android {
signingConfigs {
config {
if (props.containsKey('keyStore')) {
storeFile new File(props['keyStore'])
storePassword props['keyStorePass']
keyAlias props['keyAlias']
keyPassword props['keyPass']
}
}
}
buildTypes {
debug {
// If keystore exists, sign the APK with custom signature
if (signingConfigs.config.storeFile?.exists())
signingConfig signingConfigs.config
}
release {
signingConfig signingConfigs.config
}
}
lintOptions {
disable 'MissingTranslation'
}
}
}
}
}

125
build.gradle.kts Normal file
View File

@ -0,0 +1,125 @@
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("http://storage.googleapis.com/r8-releases/raw") }
maven { url = uri("https://kotlin.bintray.com/kotlinx") }
}
dependencies {
classpath("com.android.tools.build:gradle:4.0.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Deps.vKotlin}")
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:${Deps.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",
"processed_res", "release", "out", "resources-release.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) {
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.0"
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 == "processReleaseResources") {
finalizedBy(tasks.create("optimizeReleaseResources").applyOptimize())
}
}
if (name == "app" || name == "stub") {
android.apply {
signingConfigs {
create("config") {
Config["keyStore"]?.also {
storeFile = File(it)
storePassword = Config["keyStorePass"]
keyAlias = Config["keyAlias"]
keyPassword = Config["keyPass"]
}
}
}
buildTypes {
signingConfigs.getByName("config").also {
getByName("debug") {
// If keystore exists, sign the APK with custom signature
if (it.storeFile?.exists() == true)
signingConfig = it
}
getByName("release") {
signingConfig = it
}
}
}
lintOptions {
disable("MissingTranslation")
}
}
}
}
}

1
buildSrc/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

15
buildSrc/build.gradle.kts Normal file
View File

@ -0,0 +1,15 @@
plugins {
`kotlin-dsl`
}
repositories {
jcenter()
}
gradlePlugin {
plugins {
register("MagiskPlugin") {
id = "MagiskPlugin"
implementationClass = "MagiskPlugin"
}
}
}

View File

@ -0,0 +1,29 @@
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import java.io.File
import java.util.*
object Deps {
const val vKotlin = "1.3.72"
const val vNav = "2.3.0"
}
private val props = Properties()
object Config {
operator fun get(key: String) = props[key] as? String
fun contains(key: String) = props.containsKey(key)
}
class MagiskPlugin : Plugin<Project> {
override fun apply(project: Project) {
val file = project.findProperty("configPath")?.let { File(it as String) }
?: project.file("config.prop")
if (!file.exists())
throw GradleException("Please setup config.prop")
file.inputStream().use { props.load(it) }
}
}

View File

@ -1,22 +0,0 @@
apply plugin: 'com.android.library'
android {
ndkVersion '99.99.99'
externalNativeBuild {
ndkBuild {
path 'jni/Android.mk'
}
}
defaultConfig {
externalNativeBuild {
ndkBuild {
// Pass arguments to ndk-build.
arguments('B_MAGISK=1', 'B_INIT64=1', 'B_BOOT=1', 'B_TEST=1',
'MAGISK_DEBUG=1', 'MAGISK_VERSION=debug', 'MAGISK_VER_CODE=INT_MAX')
}
}
}
}

24
native/build.gradle.kts Normal file
View File

@ -0,0 +1,24 @@
plugins {
id("com.android.library")
}
android {
ndkVersion = "99.99.99"
externalNativeBuild {
ndkBuild {
path("jni/Android.mk")
}
}
defaultConfig {
externalNativeBuild {
ndkBuild {
// Pass arguments to ndk-build.
arguments("B_MAGISK=1", "B_INIT64=1", "B_BOOT=1", "B_TEST=1",
"MAGISK_DEBUG=1", "MAGISK_VERSION=debug", "MAGISK_VER_CODE=INT_MAX")
}
}
}
}

View File

@ -1 +0,0 @@
include ':app', ':app:signing', ':app:shared', ':native', ':stub'

1
settings.gradle.kts Normal file
View File

@ -0,0 +1 @@
include(":app", ":app:signing", ":app:shared", ":native", ":stub")

View File

@ -1,24 +0,0 @@
apply plugin: 'com.android.application'
android {
defaultConfig {
applicationId 'com.topjohnwu.magisk'
versionCode 1
versionName props['appVersion']
buildConfigField 'String', 'DEV_CHANNEL', props['DEV_CHANNEL'] ?: 'null'
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':app:shared')
}

28
stub/build.gradle.kts Normal file
View File

@ -0,0 +1,28 @@
plugins {
id("com.android.application")
}
android {
defaultConfig {
applicationId = "com.topjohnwu.magisk"
versionCode = 1
versionName = Config["appVersion"]
buildConfigField("String", "DEV_CHANNEL", Config["DEV_CHANNEL"] ?: "null")
}
buildTypes {
getByName("release") {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
}
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation(project(":app:shared"))
}