Skip to content

Commit

Permalink
Migrate build script to kts
Browse files Browse the repository at this point in the history
  • Loading branch information
yujincheng08 committed Dec 25, 2021
1 parent d9604f1 commit 4172f9a
Show file tree
Hide file tree
Showing 17 changed files with 541 additions and 27 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,21 @@ jobs:
echo 'org.gradle.parallel=true' >> gradle.properties
echo 'org.gradle.vfs.watch=true' >> gradle.properties
echo 'org.gradle.jvmargs=-Xmx2048m' >> gradle.properties
bash ./gradlew -PappVerName=${{ env.VERSION }} assembleRelease
bash ./gradlew -PappVerName=${{ env.VERSION }} assembleRelease assembleDebug
- name: Upload built apk
if: success()
uses: actions/upload-artifact@v2
with:
name: snapshot
path: ${{ github.workspace }}/app/build/outputs/apk/release/BiliRoaming_${{ env.VERSION }}.apk
path: |
${{ github.workspace }}/app/build/outputs/apk
${{ github.workspace }}/app/build/outputs/mapping
- name: Post to channel
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master'
env:
CHANNEL_ID: ${{ secrets.TELEGRAM_TO }}
BOT_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
FILE: ${{ github.workspace }}/app/build/outputs/apk/release/BiliRoaming_${{ env.VERSION }}.apk
FILE: ${{ github.workspace }}/app/release/BiliRoaming_${{ env.VERSION }}.apk
COMMIT_MESSAGE: |+
New push to github\!
```
Expand Down
67 changes: 54 additions & 13 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import com.google.protobuf.gradle.*
import com.android.build.api.artifact.ArtifactTransformationRequest
import com.android.build.api.artifact.SingleArtifact
import com.android.build.api.variant.BuiltArtifact
import com.google.protobuf.gradle.*
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.nio.file.Paths

// https://github.com/google/protobuf-gradle-plugin/issues/540#issuecomment-1001053066
fun com.android.build.api.dsl.AndroidSourceSet.proto(action: SourceDirectorySet.() -> Unit) {
(this as? ExtensionAware)
?.extensions
?.getByName("proto")
?.let { it as? SourceDirectorySet }
?.apply(action)
}


plugins {
id("com.android.application")
id("kotlin-android")
Expand Down Expand Up @@ -61,16 +74,8 @@ android {
jvmTarget = "11"
}

// applicationVariants.all { variant ->
// variant.outputs.all { output ->
// if (variant.buildType.name == 'release') {
// outputFileName = "BiliRoaming_${defaultConfig.versionName}.apk"
// }
// }
// }

sourceSets {
getByName("main").proto {
named("main") {
proto {
srcDir("src/main/proto")
include("**/*.proto")
Expand Down Expand Up @@ -114,14 +119,40 @@ protobuf {
}
}
}
val copyApk = project.tasks.register<Copy>("copyApk") {

abstract class CopyApksTask : DefaultTask() {
@get:Internal
abstract val transformer: Property<(input: BuiltArtifact) -> File>

@get:InputDirectory
abstract val apkFolder: DirectoryProperty

@get:OutputDirectory
abstract val outFolder: DirectoryProperty

@get:Internal
abstract val transformationRequest: Property<ArtifactTransformationRequest<CopyApksTask>>

@TaskAction
fun taskAction() = transformationRequest.get().submit(this) { builtArtifact ->
File(builtArtifact.outputFile).copyTo(transformer.get()(builtArtifact), true)
}
}

androidComponents.onVariants { variant ->
variant.artifacts.use(copyApk).wiredWith(Copy::from)
if (variant.name != "release") return@onVariants
val updateArtifact = project.tasks.register<CopyApksTask>("copy${variant.name.capitalize()}Apk")
val transformationRequest = variant.artifacts.use(updateArtifact)
.wiredWithDirectories(CopyApksTask::apkFolder, CopyApksTask::outFolder)
.toTransformMany(SingleArtifact.APK)
updateArtifact.configure {
this.transformationRequest.set(transformationRequest)
transformer.set { builtArtifact ->
File(projectDir, "${variant.name}/BiliRoaming_${builtArtifact.versionName}.apk")
}
}
}


dependencies {
compileOnly("de.robv.android.xposed:api:82")
compileOnly("de.robv.android.xposed:api:82:sources")
Expand Down Expand Up @@ -183,3 +214,13 @@ tasks.whenTaskAdded {
}
}
}

tasks.withType<KotlinCompile>().all {
if (name.contains("release", true)) {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + listOf(
"-Xassertions=always-disable",
)
}
}
}
467 changes: 467 additions & 0 deletions app/src/main/res/drawable/ic_launcher_foreground.xml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background" />
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
</adaptive-icon>
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>
Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher.png
Binary file not shown.
Binary file not shown.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher.png
Binary file not shown.
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher.png
Binary file not shown.
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Binary file not shown.
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Binary file not shown.
Binary file not shown.
14 changes: 7 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.6.10'
val kotlinVersion by extra ("1.6.10")
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.12'
classpath("com.android.tools.build:gradle:7.0.4")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
classpath("com.google.protobuf:protobuf-gradle-plugin:0.8.18")

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -20,10 +20,10 @@ allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://api.xposed.info/' }
maven(url = "https://api.xposed.info")
}
}

task clean(type: Delete) {
delete rootProject.buildDir
tasks.register<Delete>("clean") {
delete(rootProject.buildDir)
}
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ android.useAndroidX=true
android.enableResourceOptimizations=false
appVerName=1.5.3
appVerCode=53
android.enableAppCompileTimeRClass=true
android.enableR8.fullMode=true
android.experimental.enableNewResourceShrinker=true
android.experimental.enableNewResourceShrinker.preciseShrinking=true
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include ':app'
include(":app")
buildCache { local { removeUnusedEntriesAfterDays = 1 } }

0 comments on commit 4172f9a

Please sign in to comment.