### Sign APK with SignUtil Source: https://context7.com/abdurazaaqmohammed/axml-editor/llms.txt Provides methods to sign APKs using either the default debug keystore or a custom PKCS12 keystore with configurable signing schemes. ```java import com.abdurazaaqmohammed.androidmanifesteditor.main.SignUtil; import android.content.Context; import java.io.File; import java.io.FileInputStream; // Sign APK with debug keystore (uses bundled debug.keystore with password "android") File inputApk = new File("/path/to/unsigned.apk"); File outputApk = new File("/path/to/signed.apk"); // Sign with all schemes (v1, v2, v3) enabled SignUtil.signDebugKey(context, inputApk, outputApk); // Sign with specific schemes (e.g., only v1 for older Android compatibility) SignUtil.signDebugKey(context, inputApk, outputApk, true, // v1 signing enabled false, // v2 signing disabled false // v3 signing disabled ); // Sign with custom PKCS12 keystore FileInputStream keystoreStream = new FileInputStream("/path/to/keystore.p12"); String password = "keystorePassword"; SignUtil.signApk(keystoreStream, password, inputApk, outputApk); // Sign with custom keystore and specific signing schemes SignUtil.signApk(keystoreStream, password, inputApk, outputApk, true, // v1 signing true, // v2 signing true // v3 signing ); ``` -------------------------------- ### Repackage APK with Modified AndroidManifest.xml Source: https://context7.com/abdurazaaqmohammed/axml-editor/llms.txt Creates a new APK file by copying entries from an input ZIP and replacing the AndroidManifest.xml with provided encoded data. Preserves compression methods for resources. ```java private void repackageApk(Uri inputZipUri, Uri outputUri, byte[] encodedManifest) throws IOException { try (ZipInputStream zis = new ZipInputStream(getContentResolver().openInputStream(inputZipUri)); ZipOutputStream zos = new ZipOutputStream(getContentResolver().openOutputStream(outputUri))) { ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { String filename = entry.getName(); ZipEntry newEntry = new ZipEntry(filename); // Preserve compression method for resources if (filename.startsWith("res/") && !filename.contains(".xml")) { zos.setMethod(ZipOutputStream.STORED); newEntry.setSize(entry.getSize()); newEntry.setCrc(entry.getCrc()); } else { zos.setMethod(ZipOutputStream.DEFLATED); } zos.putNextEntry(newEntry); if ("AndroidManifest.xml".equals(filename)) { // Write modified manifest zos.write(encodedManifest, 0, encodedManifest.length); } else { // Copy original content byte[] buffer = new byte[1024]; int len; while ((len = zis.read(buffer)) > 0) { zos.write(buffer, 0, len); } } zos.closeEntry(); zis.closeEntry(); } } } ``` -------------------------------- ### Sign APK with PseudoApkSigner Source: https://context7.com/abdurazaaqmohammed/axml-editor/llms.txt Performs lightweight v1 JAR signing for older Android versions using a certificate template and private key. ```java import com.aefyr.pseudoapksigner.PseudoApkSigner; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; // Setup signing files from app assets File signingDir = new File(context.getFilesDir(), "signing"); signingDir.mkdir(); File templateFile = new File(signingDir, "testkey.past"); // Certificate template File privateKeyFile = new File(signingDir, "testkey.pk8"); // Private key // Copy signing files from assets if needed IOUtils.copyFileFromAssets(context, "testkey.past", templateFile); IOUtils.copyFileFromAssets(context, "testkey.pk8", privateKeyFile); // Sign the APK FileInputStream apkInput = new FileInputStream("/path/to/unsigned.apk"); FileOutputStream signedOutput = new FileOutputStream("/path/to/signed.apk"); PseudoApkSigner.sign(apkInput, signedOutput, templateFile, privateKeyFile); // Close streams apkInput.close(); signedOutput.close(); ``` -------------------------------- ### Extract AndroidManifest.xml from APK/ZIP Source: https://context7.com/abdurazaaqmohammed/axml-editor/llms.txt Reads an InputStream from an APK or ZIP file to find and extract the AndroidManifest.xml file. Handles nested base.apk for split APKs. ```java private InputStream getAndroidManifestInputStreamFromZip(InputStream zipInputStream) throws IOException { ZipInputStream zipInput = new ZipInputStream(new BufferedInputStream(zipInputStream)); ZipEntry entry; while ((entry = zipInput.getNextEntry()) != null) { if (entry.getName().equals("AndroidManifest.xml")) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int length; while ((length = zipInput.read(buffer)) != -1) { outputStream.write(buffer, 0, length); } return new ByteArrayInputStream(outputStream.toByteArray()); } // Handle split APKs (XAPK format) where base.apk is nested else if (entry.getName().equals("base.apk")) { return getAndroidManifestInputStreamFromZip(zipInput); } zipInput.closeEntry(); } return null; } ``` -------------------------------- ### Clean Manifest XML using Regex Source: https://context7.com/abdurazaaqmohammed/axml-editor/llms.txt Removes specific metadata related to Play Store split APKs and dynamic feature modules from an XML string using a complex regular expression. Also fixes split APK requirement flags. ```java // Replace all occurrences (example: remove Play Store split APK metadata) String cleanManifest = manifestXml.replaceAll( "<[^>]*(AssetPack|assetpack|MissingSplit|" + "com\\.android\\.dynamic\\.apk\\.fused\\.modules|" + "com\\.android\\.stamp.source|com\\.android\\.stamp.type|" + "com\\.android\\.vending.splits|" + "com\\.android\\.vending.derived.apk.id|" + "PlayCoreDialog)[^>]*(.*\\n.*\\n.*(?!.*(application|manifest)).*>|" + ".*\\n.*(?!.*(application|manifest))*>|>", "" ); // Fix split APK requirement flags cleanManifest = cleanManifest .replace("isSplitRequired=\"true", "isSplitRequired=\"false") .replaceAll("(splitTypes|requiredSplitTypes)=\".*\"", ""); ``` -------------------------------- ### Encode Plain XML to Binary Format with aXMLEncoder Source: https://context7.com/abdurazaaqmohammed/axml-editor/llms.txt Utilize aXMLEncoder to convert human-readable XML text back into Android binary XML format. This is necessary for modifying AndroidManifest.xml or layout files before repackaging an APK. Encoding can be done directly from a string or via an XmlPullParser. ```java import com.apk.axml.aXMLEncoder; import android.content.Context; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserFactory; import java.io.StringReader; // Create encoder instance aXMLEncoder encoder = new aXMLEncoder(); // Encode XML string directly (requires Android Context for resource resolution) String xmlContent = "\n" + " ``` ```java ``` ```java ``` ```java ``` ```java "; byte[] binaryXml = encoder.encodeString(context, xmlContent); // Alternative: Encode using XmlPullParser for file-based input XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); XmlPullParser parser = factory.newPullParser(); parser.setInput(new FileInputStream("decoded_manifest.xml"), "UTF-8"); byte[] binaryXml = aXMLEncoder.encode(context, parser); // Write encoded binary to file try (FileOutputStream fos = new FileOutputStream("AndroidManifest.xml")) { fos.write(binaryXml); } ``` -------------------------------- ### Manage String Pool in Android Binary XML Source: https://context7.com/abdurazaaqmohammed/axml-editor/llms.txt Use StringPoolChunk to add strings and retrieve indices for binary encoding. Ensure the correct encoding is configured via aXMLEncoder.Config. ```java import com.apk.axml.utils.StringPoolChunk; // StringPoolChunk is used internally by aXMLEncoder // Strings are added during XML parsing and assigned IDs for binary format // Add simple string stringPool.addString("MainActivity"); // Add namespaced string (for Android attributes) // Namespace is used to resolve resource IDs stringPool.addString("http://schemas.android.com/apk/res/android", "label"); // Get string index for binary encoding int index = stringPool.stringIndex( "http://schemas.android.com/apk/res/android", "exported" ); // Encoding configuration (set in aXMLEncoder.Config) // UNICODE: 2 bytes per character (default) // UTF8: Variable-length encoding public static final StringPoolChunk.Encoding encoding = StringPoolChunk.Encoding.UNICODE; ``` -------------------------------- ### AXMLPrinter - Decode Binary XML to Readable Text Source: https://context7.com/abdurazaaqmohammed/axml-editor/llms.txt The AXMLPrinter class converts Android binary XML (AXML) format to human-readable XML text. It parses the binary format and reconstructs the XML structure with proper formatting, namespaces, and attribute values. ```APIDOC ## AXMLPrinter - Decode Binary XML to Readable Text ### Description The `AXMLPrinter` class converts Android binary XML (AXML) format to human-readable XML text. It parses the binary format and reconstructs the XML structure with proper formatting, namespaces, and attribute values including dimension units, color values, and boolean types. ### Method ```java // Create an AXMLPrinter instance AXMLPrinter printer = new AXMLPrinter(); // Optional: Enable attribute integer-to-string conversion for enum values // Converts numeric values like orientation=1 to orientation="vertical" printer.setAttributeIntConversion(true); // Decode binary XML from InputStream (e.g., AndroidManifest.xml from APK) InputStream binaryXmlStream = new FileInputStream("AndroidManifest.xml"); String decodedXml = printer.convertXml(binaryXmlStream); // Alternatively, decode from byte array byte[] binaryXmlBytes = Files.readAllBytes(Paths.get("AndroidManifest.xml")); String decodedXml = printer.convertXml(binaryXmlBytes); ``` ### Response Example ```xml ``` ``` -------------------------------- ### Decode Binary XML to Readable Text with AXMLPrinter Source: https://context7.com/abdurazaaqmohammed/axml-editor/llms.txt Use AXMLPrinter to convert Android binary XML (AXML) to human-readable XML text. It handles reconstruction of XML structure, namespaces, and attribute values. Enable attribute integer-to-string conversion for enum values. ```java import mt.modder.hub.axml.AXMLPrinter; import java.io.InputStream; import java.io.FileInputStream; // Create an AXMLPrinter instance AXMLPrinter printer = new AXMLPrinter(); // Optional: Enable attribute integer-to-string conversion for enum values // Converts numeric values like orientation=1 to orientation="vertical" printer.setAttributeIntConversion(true); // Decode binary XML from InputStream (e.g., AndroidManifest.xml from APK) InputStream binaryXmlStream = new FileInputStream("AndroidManifest.xml"); String decodedXml = printer.convertXml(binaryXmlStream); // Alternatively, decode from byte array byte[] binaryXmlBytes = Files.readAllBytes(Paths.get("AndroidManifest.xml")); String decodedXml = printer.convertXml(binaryXmlBytes); ``` -------------------------------- ### aXMLEncoder - Encode Plain XML to Binary Format Source: https://context7.com/abdurazaaqmohammed/axml-editor/llms.txt The aXMLEncoder class converts human-readable XML text back to Android binary XML format. This is essential for modifying AndroidManifest.xml or layout files and packaging them back into an APK. ```APIDOC ## aXMLEncoder - Encode Plain XML to Binary Format ### Description The `aXMLEncoder` class converts human-readable XML text back to Android binary XML format. This is essential for modifying AndroidManifest.xml or layout files and packaging them back into an APK. ### Method ```java // Create encoder instance aXMLEncoder encoder = new aXMLEncoder(); // Encode XML string directly (requires Android Context for resource resolution) String xmlContent = "\n" + " " + " " + " \n" + " " + ""; byte[] binaryXml = encoder.encodeString(context, xmlContent); // Alternative: Encode using XmlPullParser for file-based input XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); XmlPullParser parser = factory.newPullParser(); parser.setInput(new FileInputStream("decoded_manifest.xml"), "UTF-8"); byte[] binaryXml = aXMLEncoder.encode(context, parser); // Write encoded binary to file try (FileOutputStream fos = new FileOutputStream("AndroidManifest.xml")) { fos.write(binaryXml); } ``` ``` -------------------------------- ### Convert String to Universal Case Regex Source: https://context7.com/abdurazaaqmohammed/axml-editor/llms.txt Converts a string into a regex pattern that matches both lowercase and uppercase versions of each letter. Non-letter characters are included literally. ```java private String convertToUniversalCase(String input) { StringBuilder regexBuilder = new StringBuilder(); for (char c : input.toCharArray()) { if (Character.isLetter(c)) { regexBuilder.append("["); regexBuilder.append(Character.toLowerCase(c)); regexBuilder.append(Character.toUpperCase(c)); regexBuilder.append("]"); } else { regexBuilder.append(c); } } return regexBuilder.toString(); } ``` -------------------------------- ### Escape Special Regex Characters Source: https://context7.com/abdurazaaqmohammed/axml-editor/llms.txt Escapes special characters in a string so it can be safely used as a literal string within a regular expression. Characters like [, ], (, ), ^, $, |, *, +, ?, . are escaped with a backslash. ```java private String escapeRegex(String input) { String specialChars = "\[]{}()^$|*+?. "; StringBuilder escaped = new StringBuilder(); for (char c : input.toCharArray()) { if (specialChars.indexOf(c) != -1) { escaped.append("\\").append(c); } else { escaped.append(c); } } return escaped.toString(); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.