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")