diff --git a/patches/api/patches.api b/patches/api/patches.api index c8438af90..59535bee9 100644 --- a/patches/api/patches.api +++ b/patches/api/patches.api @@ -96,6 +96,10 @@ public final class app/revanced/patches/all/misc/network/OverrideCertificatePinn public static final fun getOverrideCertificatePinningPatch ()Lapp/revanced/patcher/patch/ResourcePatch; } +public final class app/revanced/patches/all/misc/optimization/StripPlatformLibrariesPatchKt { + public static final fun getStripPlatformLibrariesPatch ()Lapp/revanced/patcher/patch/RawResourcePatch; +} + public final class app/revanced/patches/all/misc/packagename/ChangePackageNamePatchKt { public static field packageNameOption Lapp/revanced/patcher/patch/Option; public static final fun getChangePackageNamePatch ()Lapp/revanced/patcher/patch/ResourcePatch; diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/customcertificates/CustomCertificatesPatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/customcertificates/CustomCertificatesPatch.kt index 009758977..3d3823cc5 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/customcertificates/CustomCertificatesPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/customcertificates/CustomCertificatesPatch.kt @@ -4,7 +4,7 @@ import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.booleanOption import app.revanced.patcher.patch.resourcePatch import app.revanced.patcher.patch.stringsOption -import app.revanced.util.Utils.trimIndentMultiline +import app.revanced.util.trimIndentMultiline import app.revanced.util.getNode import org.w3c.dom.Element import java.io.File diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/hex/HexPatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/hex/HexPatch.kt index 9a9e427ec..2d4788bab 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/hex/HexPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/hex/HexPatch.kt @@ -5,7 +5,7 @@ import app.revanced.patcher.patch.rawResourcePatch import app.revanced.patcher.patch.stringsOption import app.revanced.patches.shared.misc.hex.HexPatchBuilder import app.revanced.patches.shared.misc.hex.hexPatch -import app.revanced.util.Utils.trimIndentMultiline +import app.revanced.util.trimIndentMultiline @Suppress("unused") val hexPatch = rawResourcePatch( diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/network/OverrideCertificatePinningPatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/network/OverrideCertificatePinningPatch.kt index c85f4c3ba..915778a75 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/network/OverrideCertificatePinningPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/network/OverrideCertificatePinningPatch.kt @@ -2,7 +2,7 @@ package app.revanced.patches.all.misc.network import app.revanced.patcher.patch.resourcePatch import app.revanced.patches.all.misc.debugging.enableAndroidDebuggingPatch -import app.revanced.util.Utils.trimIndentMultiline +import app.revanced.util.trimIndentMultiline import org.w3c.dom.Element import java.io.File diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/optimization/StripPlatformLibrariesPatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/optimization/StripPlatformLibrariesPatch.kt new file mode 100644 index 000000000..82042c315 --- /dev/null +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/optimization/StripPlatformLibrariesPatch.kt @@ -0,0 +1,30 @@ +package app.revanced.patches.all.misc.optimization + +import android.os.Build.SUPPORTED_ABIS +import app.revanced.patcher.patch.rawResourcePatch +import app.revanced.patcher.patch.stringsOption +import app.revanced.util.isAndroid + +@Suppress("unused") +val stripPlatformLibrariesPatch = rawResourcePatch( + "Strip platform libraries", + "Removes unused platform-native libraries from the APK to reduce package size" + + "- if detected automatically, the device's unsupported ABIs by default." +) { + val allAbis = listOf("armeabi-v7a", "arm64-v8a", "x86", "x86_64") + val supportedAbis = if (isAndroid) SUPPORTED_ABIS.toList() else allAbis + + val platformsToKeep by stringsOption( + key = "platformsToKeep", + title = "Platforms to keep", + description = "The platforms to keep in the APK.", + default = supportedAbis, + values = mapOf("Keep all" to allAbis) + allAbis.associate { "Only $it" to listOf(it) }, + required = true + ) + + execute { + val platforms = platformsToKeep!! + get("libs").listFiles { it.name !in platforms }?.forEach { it.deleteRecursively() } + } +} diff --git a/patches/src/main/kotlin/app/revanced/patches/instagram/ghost/story/AnonymousStoryViewingPatch.kt b/patches/src/main/kotlin/app/revanced/patches/instagram/ghost/story/AnonymousStoryViewingPatch.kt index 72cae7fd2..a1192059e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/instagram/ghost/story/AnonymousStoryViewingPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/instagram/ghost/story/AnonymousStoryViewingPatch.kt @@ -1,7 +1,7 @@ package app.revanced.patches.instagram.ghost.story import app.revanced.patcher.patch.bytecodePatch -import app.revanced.util.Utils.trimIndentMultiline +import app.revanced.util.trimIndentMultiline import app.revanced.util.returnEarly @Suppress("unused") diff --git a/patches/src/main/kotlin/app/revanced/patches/instagram/misc/devmenu/EnableDeveloperMenuPatch.kt b/patches/src/main/kotlin/app/revanced/patches/instagram/misc/devmenu/EnableDeveloperMenuPatch.kt index e9577477a..c9396697f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/instagram/misc/devmenu/EnableDeveloperMenuPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/instagram/misc/devmenu/EnableDeveloperMenuPatch.kt @@ -1,7 +1,7 @@ package app.revanced.patches.instagram.misc.devmenu import app.revanced.patcher.patch.bytecodePatch -import app.revanced.util.Utils.trimIndentMultiline +import app.revanced.util.trimIndentMultiline import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionReversedOrThrow import app.revanced.util.returnEarly diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/layout/branding/BaseCustomBrandingPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/layout/branding/BaseCustomBrandingPatch.kt index a2b88d7f1..4d12a8071 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/layout/branding/BaseCustomBrandingPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/layout/branding/BaseCustomBrandingPatch.kt @@ -17,7 +17,7 @@ import app.revanced.patches.shared.misc.mapping.resourceMappingPatch import app.revanced.patches.shared.misc.settings.preference.BasePreferenceScreen import app.revanced.patches.shared.misc.settings.preference.ListPreference import app.revanced.util.ResourceGroup -import app.revanced.util.Utils.trimIndentMultiline +import app.revanced.util.trimIndentMultiline import app.revanced.util.addInstructionsAtControlFlowLabel import app.revanced.util.copyResources import app.revanced.util.findElementByAttributeValueOrThrow diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/header/ChangeHeaderPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/header/ChangeHeaderPatch.kt index a7b33cd48..ff7b24093 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/header/ChangeHeaderPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/header/ChangeHeaderPatch.kt @@ -16,7 +16,7 @@ import app.revanced.patches.shared.misc.mapping.resourceMappings import app.revanced.patches.shared.misc.settings.preference.ListPreference import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.util.ResourceGroup -import app.revanced.util.Utils.trimIndentMultiline +import app.revanced.util.trimIndentMultiline import app.revanced.util.copyResources import app.revanced.util.findElementByAttributeValueOrThrow import app.revanced.util.forEachLiteralValueInstruction diff --git a/patches/src/main/kotlin/app/revanced/util/Utils.kt b/patches/src/main/kotlin/app/revanced/util/Utils.kt index ef7d0ef1a..2af407151 100644 --- a/patches/src/main/kotlin/app/revanced/util/Utils.kt +++ b/patches/src/main/kotlin/app/revanced/util/Utils.kt @@ -1,10 +1,15 @@ package app.revanced.util -internal object Utils { - internal fun String.trimIndentMultiline() = - this.split("\n") - .joinToString("\n") { it.trimIndent() } // Remove the leading whitespace from each line. - .trimIndent() // Remove the leading newline. -} +internal fun String.trimIndentMultiline() = + this.split("\n") + .joinToString("\n") { it.trimIndent() } // Remove the leading whitespace from each line. + .trimIndent() // Remove the leading newline. -internal fun Boolean.toHexString(): String = if (this) "0x1" else "0x0" \ No newline at end of file +internal fun Boolean.toHexString(): String = if (this) "0x1" else "0x0" + +internal val isAndroid = try { + Class.forName("android.os.Build") + true +} catch (_: ClassNotFoundException) { + false +} \ No newline at end of file diff --git a/patches/stub/src/main/java/android/os/Build.java b/patches/stub/src/main/java/android/os/Build.java index ddcac8126..8a2aa4e2e 100644 --- a/patches/stub/src/main/java/android/os/Build.java +++ b/patches/stub/src/main/java/android/os/Build.java @@ -16,6 +16,7 @@ public class Build { public static final String MODEL = null; public static final String PRODUCT = null; public static final String RADIO = null; + public static final String[] SUPPORTED_ABIS = null; public static final String TAGS = null; public static final String TYPE = null; public static final String USER = null;