### Configure LSPollution Plugin Source: https://github.com/lsposed/lspollution/blob/master/README.md Configure the LSPollution plugin using the 'lspollution' extension object in your build.gradle.kts file. This example shows default values and common configurations. ```kotlin plugins { id("org.lsposed.lspollution") // other plugins... } lspollution { mappingFile = file("mapping.txt").toPath() // Mapping file used for incremental obfuscation whiteList = [ // White list rules "*.R.raw.*", "*.R.drawable.icon" ] obfuscatedBundleFileName = "duplicated-app.aab" // Obfuscated file name, must end with '.aab' mergeDuplicatedRes = true // Whether to allow the merge of duplicate resources enableFilterFiles = true // Whether to allow filter files filterList = [ // file filter rules "*/arm64-v8a/*", "META-INF/*" ] enableFilterStrings = false // switch of filter strings unusedStringPath = file("unused.txt").toPath() // strings will be filtered in this file languageWhiteList = ["en", "zh"] // keep en,en-xx,zh,zh-xx etc. remove others. } ``` -------------------------------- ### Get Obfuscated Bundle Path Source: https://github.com/lsposed/lspollution/blob/master/README.md Retrieve the path to the obfuscated AAB file using Gradle. This requires accessing the LSPollution task and its specific method. ```kotlin val lspollutionPlugin = project.tasks.getByName("lspollution${VARIANT_NAME}") val bundlePath = lspollutionPlugin.getObfuscatedBundlePath() ``` -------------------------------- ### Retrieve Obfuscated Bundle Path Programmatically Source: https://context7.com/lsposed/lspollution/llms.txt Access the obfuscated bundle path from a custom Gradle task or script plugin by getting the LSPollutionTask and calling getObfuscatedBundlePath(). This avoids hardcoding paths in downstream tasks. ```kotlin // In a custom Gradle task or script plugin val lspollutionTask = project.tasks.getByName("lspollutionRelease") as LSPollutionTask val obfuscatedBundlePath: Path = lspollutionTask.getObfuscatedBundlePath() println("Obfuscated bundle: $obfuscatedBundlePath") // Output: .../build/outputs/bundle/release/app-obfuscated.aab ``` -------------------------------- ### Display Help Information Source: https://github.com/lsposed/lspollution/blob/master/wiki/en/COMMAND.md Displays detailed help information for all available parameters and commands of the AabResGuard tool. ```cmd aabresguard help ``` -------------------------------- ### Resource Mapping Rules Source: https://github.com/lsposed/lspollution/blob/master/wiki/en/OUTPUT.md Logs detailing how resource directories, IDs, and file paths are obfuscated. Use this to understand the mapping between original and obfuscated resources. ```txt res dir mapping: res/color-v21 -> res/c res/color-v23 -> res/d res/anim -> res/a res id mapping: 0x7f0c00ba : com.bytedance.android.app.R.style.RtlUnderlay.Widget.AppCompat.ActionButton.Overflow -> com.bytedance.android.app.R.style.eb 0x7f040002 : com.bytedance.android.app.R.color.abc_btn_colored_borderless_text_material -> com.bytedance.android.app.R.color.c 0x7f0c00d5 : com.bytedance.android.app.R.style.TextAppearance.AppCompat.Title -> com.bytedance.android.app.R.style.f2 0x7f040002 : com.bytedance.android.app.R.style.Base.TextAppearance.AppCompat.Small.Inverse -> com.bytedance.android.app.R.style.a8 res entries path mapping: 0x7f060030 : base/res/drawable-xxhdpi-v4/abc_list_selector_disabled_holo_dark.9.png -> res/h/z.9.png 0x7f060022 : base/res/drawable-xxxhdpi-v4/abc_ic_star_half_black_16dp.png -> res/k/o.png ``` -------------------------------- ### Run LSPollution Obfuscation Source: https://context7.com/lsposed/lspollution/llms.txt Trigger the obfuscation process by running the standard Gradle bundle command. LSPollution hooks into this process automatically. The output includes the obfuscated bundle and mapping files. ```bash ./gradlew clean :app:bundleRelease --stacktrace # Output: build/outputs/bundle/release/app-obfuscated.aab # build/outputs/bundle/release/resources-mapping.txt # build/outputs/bundle/release/base-duplicated.txt ``` -------------------------------- ### Obfuscate Bundle with CLI Source: https://context7.com/lsposed/lspollution/llms.txt Use the `obfuscate-bundle` command to obfuscate resources, optionally merge duplicates, filter files, and re-sign the bundle. Configuration is controlled via an XML file. ```bash aabresguard obfuscate-bundle \ --bundle=app.aab \ --output=obfuscated.aab \ --config=config.xml \ --mapping=resources-mapping.txt \ --merge-duplicated-res=true \ --storeFile=release.keystore \ --storePassword=myStorePass \ --keyAlias=myKey \ --keyPassword=myKeyPass ``` ```xml ``` -------------------------------- ### LSPollution DSL Configuration Reference Source: https://context7.com/lsposed/lspollution/llms.txt Reference for all configurable fields within the LSPollution extension in Gradle. All fields have safe defaults, but some like obfuscatedBundleFileName are required. ```kotlin // Full reference with all fields and their defaults lspollution { enableObfuscate = true // Boolean — master switch for resource name obfuscation mappingFile = null // Path? — prior mapping for incremental builds whiteList = emptySet() // Set — glob rules; matched resources are skipped obfuscatedBundleFileName = "out.aab" // String (required) — output .aab filename mergeDuplicatedRes = false // Boolean — deduplicate identical resource files enableFilterFiles = false // Boolean — enable file-level filtering filterList = emptySet() // Set — glob rules for files to remove enableFilterStrings = false // Boolean — enable string/locale filtering unusedStringPath = "" // String — path to unused.txt (one name per line) languageWhiteList = emptySet() // Set — locale prefixes to keep (e.g. "en", "zh") } ``` -------------------------------- ### Execute Bundle Packaging Source: https://github.com/lsposed/lspollution/blob/master/README.md Obfuscate your Android App Bundle (AAB) by executing the original packaging commands after applying and configuring the LSPollution plugin. ```bash ./gradlew clean :app:bundleDebug --stacktrace ``` -------------------------------- ### Gradle Configuration for Whitelist Source: https://context7.com/lsposed/lspollution/llms.txt Configures the LSPollution plugin in a Gradle build script, specifying obfuscated bundle file name and a whitelist for resources that should not be renamed. ```kotlin // build.gradle.kts lspollution { obfuscatedBundleFileName = "app-obfuscated.aab" whiteList = setOf( // Google Services / Firebase "*.R.string.default_web_client_id", "*.R.string.firebase_database_url", "*.R.string.gcm_defaultSenderId", "*.R.string.google_api_key", "*.R.string.google_app_id", "*.R.string.google_crash_reporting_api_key", "*.R.string.google_storage_bucket", "*.R.string.project_id", "*.R.string.com.crashlytics.android.build_id", // App-specific resources that must not be renamed "*.R.raw.*", "*.R.drawable.ic_launcher*" ) } ``` -------------------------------- ### Device-Spec Configuration for AabResGuard Source: https://github.com/lsposed/lspollution/blob/master/wiki/en/DATA.md This JSON configuration specifies supported ABIs, locales, screen density, and SDK version for AabResGuard. Ensure your device meets these specifications for optimal performance. ```json { "supportedAbis": ["armeabi-v7a"], "supportedLocales": ["zh-CN", "en-US", "ja-JP", "zh-HK", "zh-TW"], "screenDensity": 480, "sdkVersion": 16 } ``` -------------------------------- ### Incremental Obfuscation with Gradle Plugin Source: https://context7.com/lsposed/lspollution/llms.txt Configure the `lspollution` block in `build.gradle.kts` for incremental obfuscation. This preserves existing resource name assignments using a mapping file, ensuring small Play Store diffs. It also allows setting the output file name, enabling duplicate resource merging, and defining whitelisted resources. ```kotlin // build.gradle.kts — incremental setup lspollution { obfuscatedBundleFileName = "app-release-obfuscated.aab" mappingFile = file("${rootDir}/obfuscation/resources-mapping.txt").toPath() mergeDuplicatedRes = true whiteList = setOf( "*.R.string.default_web_client_id", "*.R.string.google_app_id", "*.R.string.gcm_defaultSenderId" ) } ``` ```bash ./gradlew :app:bundleRelease # Produces resources-mapping.txt alongside the .aab. ``` -------------------------------- ### Configure LSPollution in app/build.gradle.kts Source: https://context7.com/lsposed/lspollution/llms.txt Configure the LSPollution plugin in your app module's build.gradle.kts. This includes setting the output filename, enabling/disabling obfuscation, defining resource whitelists, and configuring file/string filtering. ```kotlin plugins { id("com.android.application") id("org.lsposed.lspollution") } lspollution { // Output filename for the obfuscated bundle — must end with .aab obfuscatedBundleFileName = "app-obfuscated.aab" // Enable/disable the obfuscation step (default: true) enableObfuscate = true // Mapping file for incremental obfuscation (preserves names across builds) mappingFile = file("mapping.txt").toPath() // Resources that must NOT be obfuscated (supports wildcard patterns) whiteList = setOf( "*.R.raw.*", "*.R.drawable.icon", "*.R.string.app_name" ) // Merge identical files (by MD5) to reduce bundle size mergeDuplicatedRes = true // Remove files from lib/ and META-INF/ directories enableFilterFiles = true filterList = setOf( "*/arm64-v8a/*", // strip arm64 native libs for a specific channel build "META-INF/*.RSA", "META-INF/*.SF" ) // Strip unused string resources and non-whitelisted locales enableFilterStrings = true unusedStringPath = file("unused.txt").toPath().toString() languageWhiteList = setOf("en", "zh") // keep en, en-*, zh, zh-* locales only } ``` -------------------------------- ### Apply LSPollution Plugin in settings.gradle.kts Source: https://context7.com/lsposed/lspollution/llms.txt Apply the LSPollution plugin in your project's settings.gradle.kts file to make it available for module-level configuration. Ensure mavenCentral() is configured. ```kotlin pluginManagement { repositories { mavenCentral() } plugins { id("org.lsposed.lspollution") version "0.2.0" } } ``` -------------------------------- ### Apply LSPollution Gradle Plugin Source: https://github.com/lsposed/lspollution/blob/master/README.md Apply the LSPollution Gradle plugin in your settings.gradle.kts file. Ensure you are using at least Java 17 for the Gradle daemon. ```kotlin pluginManagement { repositories { mavenCentral() } plugins { id("org.lsposed.lspollution") version "0.2.0" } } ``` -------------------------------- ### Filter Files from Bundle with CLI Source: https://context7.com/lsposed/lspollution/llms.txt Use the `filter-file` command to remove specific files from `lib/` or `META-INF/` directories based on glob rules defined in a configuration XML. This is useful for stripping unused ABI libraries from channel-specific bundles. ```bash aabresguard filter-file \ --bundle=app.aab \ --output=filtered.aab \ --config=config.xml \ --storeFile=release.keystore \ --storePassword=myStorePass \ --keyAlias=myKey \ --keyPassword=myKeyPass ``` ```xml ``` -------------------------------- ### Obfuscate Resources in AAB Bundle Source: https://github.com/lsposed/lspollution/blob/master/wiki/en/COMMAND.md Performs resource aliasing on an input AAB file and outputs an obfuscated AAB. Supports merging duplicate resources and file filtering, configured via an XML file with whitelist support. ```cmd aabresguard obfuscate-bundle --bundle=app.aab --output=obfuscated.aab --config=config.xml --mapping=mapping.txt --merge-duplicated-res=true --storeFile=debug.store --storePassword=android --keyAlias=android --keyPassword=android ``` ```xml ``` -------------------------------- ### Merge Duplicated Resources with CLI Source: https://context7.com/lsposed/lspollution/llms.txt The `merge-duplicated-res` command scans for MD5 collisions in resource entries, removes duplicates, and redirects references to a surviving copy, resulting in a smaller bundle without functional changes. Signing flags can be omitted to use the Android default debug keystore. ```bash aabresguard merge-duplicated-res \ --bundle=app.aab \ --output=merged.aab \ --storeFile=debug.store \ --storePassword=android \ --keyAlias=androiddebugkey \ --keyPassword=android # Omit store flags to sign with the Android default debug keystore ``` ```text res filter path mapping: res/drawable-hdpi-v4/btn_bg.9.png -> res/drawable-mdpi-v4/btn_bg.9.png (size 432B) res/drawable-xhdpi-v4/btn_bg.9.png -> res/drawable-mdpi-v4/btn_bg.9.png (size 432B) removed: count(2), totalSize(864B) ``` -------------------------------- ### Mapping File Format Source: https://context7.com/lsposed/lspollution/llms.txt Defines the format for resource mapping files used by LSPollution, including directory and ID mappings. ```plaintext res dir mapping: res/drawable-xxhdpi-v4 -> res/a res/layout -> res/b res id mapping: 0x7f040002 : com.example.R.color.primary_dark -> com.example.R.color.c res entries path mapping: 0x7f060030 : base/res/drawable-xxhdpi-v4/btn_ok.png -> res/a/z.png ``` -------------------------------- ### Deduplicated Resource Files Log Source: https://github.com/lsposed/lspollution/blob/master/wiki/en/OUTPUT.md A log file recording deduplicated resource files, showing the mapping from a source file to a target file and the size difference. This helps identify and manage duplicate resources. ```txt res filter path mapping: res/drawable-hdpi-v4/abc_list_divider_mtrl_alpha.9.png -> res/drawable-mdpi-v4/abc_list_divider_mtrl_alpha.9.png (size 167B) res/color-v23/abc_tint_spinner.xml -> res/color-v23/abc_tint_edittext.xml (size 942B) res/drawable-xhdpi-v4/abc_list_divider_mtrl_alpha.9.png -> res/drawable-mdpi-v4/abc_list_divider_mtrl_alpha.9.png (size 167B) removed: count(3), totalSize(1.2KB) ``` -------------------------------- ### Filter Strings with CLI Source: https://context7.com/lsposed/lspollution/llms.txt The `filter-string` command strips unused string resource values and removes locale configurations for unlisted languages. Unused string names should be provided in a text file, one per line. ```bash aabresguard filter-string \ --bundle=app.aab \ --output=filtered.aab \ --config=config.xml \ --storeFile=release.keystore \ --storePassword=myStorePass \ --keyAlias=myKey \ --keyPassword=myKeyPass ``` ```xml ``` ```text unused_welcome_message legacy_onboarding_title debug_label_foo ``` -------------------------------- ### Filter Strings in AAB Package Source: https://github.com/lsposed/lspollution/blob/master/wiki/en/COMMAND.md Filters out values and translations from string resources based on matched names in a provided file. Configuration is managed through an XML file specifying paths to string lists and desired languages. ```cmd aabresguard filter-string --bundle=app.aab --output=filtered.aab --config=config.xml --storeFile=debug.store --storePassword=android --keyAlias=android --keyPassword=android ``` ```xml ``` -------------------------------- ### Filter Files in AAB Package Source: https://github.com/lsposed/lspollution/blob/master/wiki/en/COMMAND.md Filters specific files within an AAB package, primarily supporting filtering under META-INF/ and lib/ folders. Configuration is done via an XML file using regular expressions. ```cmd aabresguard filter-file --bundle=app.aab --output=filtered.aab --config=config.xml --storeFile=debug.store --storePassword=android --keyAlias=android --keyPassword=android ``` ```xml ``` -------------------------------- ### Merge Duplicated Resources Source: https://github.com/lsposed/lspollution/blob/master/wiki/en/COMMAND.md Merges duplicate files in an AAB package based on MD5 hash to reduce package size. Signature information is optional and defaults to the Android default signature if not provided. ```cmd aabresguard merge-duplicated-res --bundle=app.aab --output=merged.aab --storeFile=debug.store --storePassword=android --keyAlias=android --keyPassword=android ``` -------------------------------- ### Whitelist Google Services Identifiers Source: https://github.com/lsposed/lspollution/blob/master/wiki/en/WHITELIST.md List of common Google Services resource identifiers to be whitelisted. These are typically found in Android resource files. ```plaintext *.R.string.default_web_client_id *.R.string.firebase_database_url *.R.string.gcm_defaultSenderId *.R.string.google_api_key *.R.string.google_app_id *.R.string.google_crash_reporting_api_key *.R.string.google_storage_bucket *.R.string.project_id *.R.string.com.crashlytics.android.build_id ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.