chore: Fail the build if patches use APIs not available on Android

Patches run inside Manager on Android, so check the compiled patch
classes against the Android API 26 signature with Animal Sniffer.
This catches desktop-only JDK classes such as AWT and newer JDK
methods such as InputStream.readAllBytes() or List.of().
This commit is contained in:
LisoUseInAIKyrios committed 2026-11-21 09:05:10 +00:00
1 parent e00dc144a0
commit ca3ebed38b
2 files changed
+24

No files matched your search

+6
View File
@@ -3,9 +3,15 @@ morphe-patcher = "2.4.0"
#noinspection GradleDependency #noinspection GradleDependency
smali = "5eaff5a2c9" smali = "5eaff5a2c9"
gson = "2.15.0" gson = "2.15.0"
animalsniffer = "2.0.1"
android-api-signature = "8.0.0_r2"
[libraries] [libraries]
gson = { module = "com.google.code.gson:gson", version.ref = "gson" } gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
android-api-signature = { module = "net.sf.androidscents.signature:android-api-level-26", version.ref = "android-api-signature" }
# Gradle plugins adds the dependency during build, this declaration is here only for dependabot to provide updates. # Gradle plugins adds the dependency during build, this declaration is here only for dependabot to provide updates.
#noinspection UnusedVersionCatalogEntry #noinspection UnusedVersionCatalogEntry
morphe-patcher = { module = "app.morphe:morphe-patcher", version.ref = "morphe-patcher" } morphe-patcher = { module = "app.morphe:morphe-patcher", version.ref = "morphe-patcher" }
[plugins]
animalsniffer = { id = "ru.vyarus.animalsniffer", version.ref = "animalsniffer" }
+18
View File
@@ -1,3 +1,8 @@
plugins {
// Fails the build if patch code uses JDK APIs that do not exist on Android.
alias(libs.plugins.animalsniffer)
}
group = "app.template" group = "app.template"
patches { patches {
@@ -20,6 +25,14 @@ val patchListGeneratorClasspath = configurations.create("patchListGeneratorClass
dependencies { dependencies {
compileOnly(libs.gson) compileOnly(libs.gson)
patchListGeneratorClasspath(libs.gson) patchListGeneratorClasspath(libs.gson)
// Android API level 26 is the minimum API the patches are compiled for (see buildAndroid).
signature(libs.android.api.signature) { artifact { type = "signature" } }
}
animalsniffer {
// Only the main source set ships in the patches file.
sourceSets = listOf(project.sourceSets["main"])
} }
tasks { tasks {
@@ -32,6 +45,11 @@ tasks {
mainClass.set("util.PatchListGeneratorKt") mainClass.set("util.PatchListGeneratorKt")
} }
// The check task already runs it, but buildAndroid does not depend on check.
named("buildAndroid") {
dependsOn("animalsnifferMain")
}
// Used by gradle-semantic-release-plugin. // Used by gradle-semantic-release-plugin.
publish { publish {
dependsOn("generatePatchesList") dependsOn("generatePatchesList")