From ca3ebed38baf91110ebf0520c414d700ec27cb27 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sat, 21 Nov 2026 09:05:10 +0000 Subject: [PATCH] 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(). --- gradle/libs.versions.toml | 6 ++++++ patches/build.gradle.kts | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index cc4cad9f2..e481bf707 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,9 +3,15 @@ morphe-patcher = "2.4.0" #noinspection GradleDependency smali = "5eaff5a2c9" gson = "2.15.0" +animalsniffer = "2.0.1" +android-api-signature = "8.0.0_r2" [libraries] 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. #noinspection UnusedVersionCatalogEntry morphe-patcher = { module = "app.morphe:morphe-patcher", version.ref = "morphe-patcher" } + +[plugins] +animalsniffer = { id = "ru.vyarus.animalsniffer", version.ref = "animalsniffer" } diff --git a/patches/build.gradle.kts b/patches/build.gradle.kts index cf6c9f69e..dd569a26a 100644 --- a/patches/build.gradle.kts +++ b/patches/build.gradle.kts @@ -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" patches { @@ -20,6 +25,14 @@ val patchListGeneratorClasspath = configurations.create("patchListGeneratorClass dependencies { compileOnly(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 { @@ -32,6 +45,11 @@ tasks { 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. publish { dependsOn("generatePatchesList")