### AndresGuard with Signature and Mapping Options Source: https://github.com/shwenzhang/andresguard/blob/master/doc/how_to_work.md This example shows how to overlay signature and mapping data onto the default configuration by providing paths to the signature and mapping files, along with necessary credentials. ```bash java -jar resourceproguard.jar input.apk -config yourconfig.xml -out output_directory -signature signature_file_path storepass_value keypass_value storealias_value -mapping mapping_file_path ``` -------------------------------- ### Run AndResGuard Standalone CLI Source: https://context7.com/shwenzhang/andresguard/llms.txt Examples of using the AndResGuard JAR file directly from the command line to process APKs, including custom configurations, signing, and path overrides. ```bash java -jar andresguard-1.2.21.jar input.apk java -jar andresguard-1.2.21.jar input.apk -config yourconfig.xml -out output_directory java -jar andresguard-1.2.21.jar input.apk -signature keystore.jks storepass123 keypass123 myalias -mapping old_mapping.txt java -jar andresguard-1.2.21.jar input.apk -signatureType v2 java -jar andresguard-1.2.21.jar input.apk -7zip /usr/local/bin/7za -zipalign /path/to/android-sdk/build-tools/30.0.2/zipalign ``` -------------------------------- ### Basic AndresGuard Execution Source: https://github.com/shwenzhang/andresguard/blob/master/doc/how_to_work.md The simplest way to run AndresGuard is by providing the input APK file. The tool will automatically use default configurations and output to a directory named after the input APK. ```bash java -jar andresguard.jar input.apk ``` -------------------------------- ### Configure and Run AndResGuard Programmatically Source: https://context7.com/shwenzhang/andresguard/llms.txt Demonstrates how to use the InputParam builder pattern in Java to configure APK obfuscation settings, including signing, whitelisting, and compression patterns, before executing the process. ```java import com.tencent.mm.resourceproguard.Configuration; import com.tencent.mm.resourceproguard.InputParam; import com.tencent.mm.resourceproguard.Main; import java.io.File; import java.util.ArrayList; public class AndResGuardRunner { public static void main(String[] args) throws Exception { InputParam.Builder builder = new InputParam.Builder(); builder.setApkPath("/path/to/input.apk") .setOutBuilder("/path/to/output") .setUse7zip(true) .setUseSign(true); ArrayList whiteList = new ArrayList<>(); whiteList.add("R.drawable.icon"); builder.setWhiteList(whiteList); InputParam inputParam = builder.create(); Main.gradleRun(inputParam); } } ``` -------------------------------- ### AndresGuard with Custom Config and Output Source: https://github.com/shwenzhang/andresguard/blob/master/doc/how_to_work.md This command demonstrates how to specify a custom configuration file and an output directory for the AndresGuard tool. If not provided, default paths are used. ```bash java -jar resourceproguard.jar input.apk -config yourconfig.xml -out output_directory ``` -------------------------------- ### Run AndresGuard with Help Option Source: https://github.com/shwenzhang/andresguard/blob/master/doc/how_to_work.md This command executes the AndresGuard JAR file with the -h flag to display the help message, showing all available command-line options and their usage. ```bash java -jar andresguard-x.x.x.jar -h ``` -------------------------------- ### Sign APK with Keystore to New File Source: https://github.com/shwenzhang/andresguard/blob/master/AndResGuard-core/src/main/java/apksigner/help_sign.txt Signs an APK file and outputs the signed APK to a new file, without modifying the original. This method also uses a specified keystore and handles key passwords similarly to in-place signing. ```bash apksigner sign --ks release.jks --in app.apk --out app-signed.apk ``` -------------------------------- ### AndResGuard Gradle Configuration for Production Source: https://context7.com/shwenzhang/andresguard/llms.txt This Groovy script demonstrates a typical production configuration for the AndResGuard Gradle plugin. It includes settings for mapping files, 7zip usage, resource whitelisting, and compression patterns. It also highlights best practices such as not compressing resources.arsc and conditionally disabling 7zip for Google Play distribution. ```groovy // build.gradle - Production configuration example andResGuard { mappingFile = file("./resource_mapping.txt") use7zip = true useSign = true keepRoot = false mergeDuplicatedRes = true whiteList = [ // ALWAYS whitelist your app icon "R.mipmap.ic_launcher", "R.mipmap.ic_launcher_round", // Whitelist all resources accessed via getIdentifier() // Check your code for: resources.getIdentifier("name", "type", package) // Common SDK resources - add as needed "R.string.com.crashlytics.*", "R.string.google_app_id", ] // BEST PRACTICE: Don't compress resources.arsc // - Can cause issues on older devices // - Prevents runtime optimization // - Required uncompressed for targetSdk >= 30 compressFilePattern = [ "*.png", "*.jpg", "*.jpeg", "*.gif", // "resources.arsc" // Don't include unless necessary ] // BEST PRACTICE: Disable 7zip for Google Play distribution // Google Play's file-by-file updates don't work well with 7zip // use7zip = false // Uncomment for Google Play builds sevenzip { artifact = 'com.tencent.mm:SevenZip:1.2.21' } } // Known Issues: // 1. AssetManager.list() returns empty first element with 7zip compressed APKs // Workaround: Filter empty strings from the result // // 2. resources.arsc compression may fail on Android < 2.3 if file > 1MB // Workaround: Don't compress resources.arsc for wide compatibility // // 3. Channel APK rebuilding may break 7zip compression // Workaround: Run repackage mode on each channel APK ``` -------------------------------- ### Configure 7zip Compression with andresguard Source: https://context7.com/shwenzhang/andresguard/llms.txt This section details how to enable and configure 7zip for maximum APK compression within the andresguard build process. It includes specifying the 7zip artifact or path and defining patterns for files to be compressed. ```groovy // build.gradle andResGuard { use7zip = true useSign = true // Required when using 7zip sevenzip { // Option 1: Use Maven artifact (auto-downloads correct binary) artifact = 'com.tencent.mm:SevenZip:1.2.21' // Option 2: Specify local path // path = "/usr/local/bin/7za" // Linux/Mac // path = "C:\\Program Files\\7-Zip\\7za.exe" // Windows } // Files to compress with 7zip (deflate compression) compressFilePattern = [ "*.png", "*.jpg", "*.jpeg", "*.gif", // Note: Don't add resources.arsc unless size is critical // and your minSdk < 30 ] } ``` ```bash # Install 7zip on different platforms # Ubuntu/Debian sudo apt-get install p7zip-full # macOS brew install p7zip # Windows # Download from: https://www.7-zip.org/download.html # Add 7za.exe to PATH ``` -------------------------------- ### Configure AndResGuard with XML Source: https://context7.com/shwenzhang/andresguard/llms.txt Define obfuscation settings, resource whitelists, compression rules, and signing parameters in a config.xml file. This is essential for preventing runtime crashes when resources are accessed dynamically. ```xml ``` -------------------------------- ### Execute AndResGuard via Command Line Source: https://context7.com/shwenzhang/andresguard/llms.txt Run AndResGuard using the JAR file to perform repackaging, specify output paths, or view help documentation. These commands require the Java Runtime Environment. ```bash java -jar andresguard-1.2.21.jar -repackage signed.apk -out output_directory -7zip /usr/local/bin/7za -zipalign /path/to/zipalign java -jar andresguard-1.2.21.jar input.apk -finalApkPath /path/to/final.apk java -jar andresguard-1.2.21.jar --help ``` -------------------------------- ### Configure Whitelist for SDK Resources (XML) Source: https://github.com/shwenzhang/andresguard/blob/master/doc/how_to_work.md This XML configuration defines a whitelist to preserve specific resources from being obfuscated or removed by tools like ProGuard. It's commonly used for SDK resources, such as Umeng or Crashlytics, which require exact naming for proper functionality. The paths support wildcards for flexible matching. ```xml ``` ```xml RANDOM_UUID ``` -------------------------------- ### Repackage APK with 7zip and Zipalign Source: https://github.com/shwenzhang/andresguard/blob/master/doc/how_to_work.md This command is used to repackage an APK that has been compressed with 7zip. It requires specifying the input APK, output directory, and paths to 7zip and zipalign executables. ```bash java -jar resourceproguard.jar -repackage input.apk -out output_directory -7zip /shwenzhang/tool/7za -zipalign /shwenzhang/sdk/tools/zipalign ``` -------------------------------- ### Configure AndResGuard in Gradle Source: https://github.com/shwenzhang/andresguard/blob/master/README.md This snippet demonstrates how to apply the AndResGuard plugin and configure its settings within a build.gradle file. It covers essential options like 7zip usage, resource white-listing, and compression patterns. ```gradle apply plugin: 'AndResGuard' buildscript { repositories { jcenter() google() } dependencies { classpath 'com.tencent.mm:AndResGuard-gradle-plugin:1.2.21' } } andResGuard { mappingFile = null use7zip = true useSign = true keepRoot = false fixedResName = "arg" mergeDuplicatedRes = true whiteList = [ "R.drawable.icon", "R.string.com.crashlytics.*", "R.string.google_app_id" ] compressFilePattern = [ "*.png", "*.jpg", "*.jpeg", "*.gif", ] sevenzip { artifact = 'com.tencent.mm:SevenZip:1.2.21' } } ``` -------------------------------- ### Configure Incremental Resource Mapping with andresguard Source: https://context7.com/shwenzhang/andresguard/llms.txt This snippet shows how to configure andresguard in your build.gradle file to use a mapping file for consistent resource obfuscation across app versions. It also illustrates the format of the generated mapping file, which includes resource path and ID mappings. ```groovy // build.gradle configuration andResGuard { // Point to mapping file from previous build mappingFile = file("./resource_mapping.txt") // ... } // The mapping file format (generated automatically): // res path mapping: // res/mipmap-hdpi-v4 -> res/mipmap-hdpi-v4 // res/mipmap-mdpi-v4 -> res/mipmap-mdpi-v4 // res/drawable-hdpi -> r/d // res/drawable-xhdpi -> r/e // // res id mapping: // com.example.app.R.drawable.background -> com.example.app.R.drawable.a // com.example.app.R.drawable.icon -> com.example.app.R.drawable.b // com.example.app.R.string.app_name -> com.example.app.R.string.a ``` ```text # Example resource_mapping.txt content # Copy this to your project and modify as needed res path mapping: res/mipmap-hdpi-v4 -> res/mipmap-hdpi-v4 res/mipmap-mdpi-v4 -> res/mipmap-mdpi-v4 res/mipmap-xhdpi-v4 -> res/mipmap-xhdpi-v4 res/mipmap-xxhdpi-v4 -> res/mipmap-xxhdpi-v4 res/mipmap-xxxhdpi-v4 -> res/mipmap-xxxhdpi-v4 res id mapping: com.example.app.R.drawable.splash_background -> com.example.app.R.drawable.a com.example.app.R.layout.activity_main -> com.example.app.R.layout.a com.example.app.R.string.welcome_message -> com.example.app.R.string.a ``` -------------------------------- ### Sign APK with Keystore Source: https://github.com/shwenzhang/andresguard/blob/master/AndResGuard-core/src/main/java/apksigner/help_sign.txt Signs an APK file in-place using a specified keystore. If the key within the keystore is password-protected, the tool will prompt for the password if --key-pass is not provided. ```bash apksigner sign --ks release.jks app.apk ``` -------------------------------- ### Sign APK with Private Key and Certificate Files Source: https://github.com/shwenzhang/andresguard/blob/master/AndResGuard-core/src/main/java/apksigner/help_sign.txt Signs an APK using separate private key (PKCS #8 DER format) and certificate chain (X.509 PEM or DER format) files. If the private key is password-protected, the tool will prompt for the password unless --key-pass is specified. ```bash apksigner sign --key release.pk8 --cert release.x509.pem app.apk ``` -------------------------------- ### AndresGuard with Custom 7zip and Zipalign Paths Source: https://github.com/shwenzhang/andresguard/blob/master/doc/how_to_work.md This command allows specifying custom paths for the 7zip and zipalign executables, which can be useful if they are not in the system's default PATH. ```bash java -jar resourceproguard.jar input.apk -7zip /shwenzhang/tool/7za -zipalign /shwenzhang/sdk/tools/zipalign ``` -------------------------------- ### Define Resource Mapping File Source: https://github.com/shwenzhang/andresguard/blob/master/README.md This snippet shows the format for a resource mapping file used to preserve specific resource paths during the obfuscation process. ```text res path mapping: res/mipmap-hdpi-v4 -> res/mipmap-hdpi-v4 res/mipmap-mdpi-v4 -> res/mipmap-mdpi-v4 res/mipmap-xhdpi-v4 -> res/mipmap-xhdpi-v4 res/mipmap-xxhdpi-v4 -> res/mipmap-xxhdpi-v4 res/mipmap-xxxhdpi-v4 -> res/mipmap-xxxhdpi-v4 ``` -------------------------------- ### Execute AndResGuard Gradle Tasks Source: https://context7.com/shwenzhang/andresguard/llms.txt Commands to trigger the resource obfuscation process for specific Android build variants and flavors via the Gradle wrapper. ```bash ./gradlew resguardRelease ./gradlew resguardDebug ./gradlew resguardFlavor1Release ./gradlew resguardUseApk ./gradlew tasks | grep resguard ``` -------------------------------- ### AndResGuard Output Directory Structure Source: https://context7.com/shwenzhang/andresguard/llms.txt Describes the expected file structure and log contents produced by AndResGuard after processing an APK, including mapping files and obfuscation statistics. ```bash output_directory/ ├── input-aligned.apk ├── input-aligned-signed.apk ├── input-signed-7zip-aligned.apk ├── resource_mapping.txt ├── log.txt └── resources_mapping_detailed.txt ``` -------------------------------- ### Sign APK with Multiple Signers Source: https://github.com/shwenzhang/andresguard/blob/master/AndResGuard-core/src/main/java/apksigner/help_sign.txt Signs an APK using multiple keys, specified sequentially. Each signer can be defined using a keystore or individual key/certificate files. The --next-signer flag separates the definitions for each subsequent signer. ```bash apksigner sign --ks release.jks --next-signer --ks magic.jks app.apk ``` -------------------------------- ### Configure AndResGuard Gradle Plugin Source: https://context7.com/shwenzhang/andresguard/llms.txt This snippet demonstrates how to apply the AndResGuard plugin and configure its extension block in an Android build.gradle file, including settings for 7zip, signing, and resource whitelisting. ```groovy apply plugin: 'AndResGuard' buildscript { repositories { jcenter() google() } dependencies { classpath 'com.tencent.mm:AndResGuard-gradle-plugin:1.2.21' } } andResGuard { mappingFile = file("./resource_mapping.txt") use7zip = true useSign = true keepRoot = false fixedResName = "arg" mergeDuplicatedRes = true whiteList = [ "R.drawable.icon", "R.mipmap.ic_launcher", "R.string.com.crashlytics.*", "R.string.google_app_id" ] compressFilePattern = [ "*.png", "*.jpg", "*.jpeg", "*.gif", ] sevenzip { artifact = 'com.tencent.mm:SevenZip:1.2.21' } finalApkBackupPath = "${project.rootDir}/final.apk" digestalg = "SHA-256" } ``` -------------------------------- ### Define Whitelist Patterns in Gradle Source: https://context7.com/shwenzhang/andresguard/llms.txt Use the andResGuard block in build.gradle to specify resources that should be excluded from obfuscation. Supports exact matches and wildcard patterns to handle SDK-specific resources. ```groovy whiteList = [ "R.drawable.icon", "R.string.umeng*", "R.layout.umeng*", "R.drawable.emoji_?", "R.string.com.crashlytics.*", "R.string.google_app_id" ] ``` -------------------------------- ### Verify APK signature against supported platforms Source: https://github.com/shwenzhang/andresguard/blob/master/AndResGuard-core/src/main/java/apksigner/help_verify.txt This command checks if the APK signatures are valid for all Android versions declared in the AndroidManifest.xml file. It is the standard way to verify an APK's integrity. ```bash apksigner verify app.apk ``` -------------------------------- ### Verify APK signature with custom API level range Source: https://github.com/shwenzhang/andresguard/blob/master/AndResGuard-core/src/main/java/apksigner/help_verify.txt This command validates the APK signatures against a specific range of Android API levels. By setting --min-sdk-version, you can ensure compatibility with older or newer Android versions as required. ```bash apksigner verify --min-sdk-version 15 app.apk ``` -------------------------------- ### apksigner verify Source: https://github.com/shwenzhang/andresguard/blob/master/AndResGuard-core/src/main/java/apksigner/help_verify.txt Verifies if an APK will verify on Android platforms. Allows specifying a custom range of API levels for verification. ```APIDOC ## apksigner verify ### Description Verifies whether the provided APK will verify on Android. By default, this checks whether the APK will verify on all Android platform versions supported by the APK (as declared using minSdkVersion in AndroidManifest.xml). Use --min-sdk-version and/or --max-sdk-version to verify the APK against a custom range of API Levels. ### Method N/A (Command-line tool) ### Endpoint N/A (Command-line tool) ### Parameters #### Command Arguments - **apk** (string) - Required - The APK file to verify. #### Options - **--print-certs** - Show information about the APK's signing certificates. - **-v, --verbose** - Verbose output mode. - **--min-sdk-version** (integer) - Lowest API Level on which this APK's signatures will be verified. By default, the value from AndroidManifest.xml is used. - **--max-sdk-version** (integer) - Highest API Level on which this APK's signatures will be verified. By default, the highest possible value is used. - **-Werr** - Treat warnings as errors. - **--in** (string) - APK file to verify. This is an alternative to specifying the APK as the very last parameter, after all options. - **-h, --help** - Show help about this command and exit ### Request Example ```bash apksigner verify --min-sdk-version 15 --max-sdk-version 25 app.apk ``` ### Response #### Success Response (0) - **Verification Status** (boolean) - Indicates if the APK signatures verify successfully for the specified conditions. #### Response Example ``` Verifying app.apk ... (certificate information if --print-certs is used) Result: ”.apk” verifies on Android API level 15 or higher ``` #### Error Response - **Non-zero exit code** - Indicates an error during verification or an invalid APK/options. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.