如何用JavaScript解码APK中加密的AndroidManifest.xml并修改应用名称
Hey there! Let's start by clearing up a common misconception—your AndroidManifest.xml isn’t actually encrypted. It’s stored in a binary XML format (called Android Binary XML, or AXML) that’s optimized for Android’s runtime, which is why it looks uneditable when you open it directly.
No worries though—there’s a straightforward workflow to decode this binary XML to plain text, make your changes, then re-encode it back to the format Android expects. Here’s how to pull this off in your JavaScript project:
You’ll need a tool or library that can parse Android’s binary XML. For JavaScript/Node.js, here are your best options:
- axmlparser (pure Node.js): This library is built specifically for parsing AXML files. Install it first:
Then use it to read and convert the binary manifest:npm install axmlparserconst AXMLParser = require('axmlparser'); const fs = require('fs'); // Read the binary AndroidManifest.xml from your unzipped APK const manifestBuffer = fs.readFileSync('./unzipped_apk/AndroidManifest.xml'); const parser = new AXMLParser(manifestBuffer); parser.parse(); // Convert to a human-readable XML string const plainXmlManifest = parser.getXml(); fs.writeFileSync('./editable_manifest.xml', plainXmlManifest); - Apktool (via Node.js child process): If you want a more robust, battle-tested tool (even though it’s Java-based), you can run Apktool from your Node.js code. First install Apktool on your system, then use:
This will dump the decoded manifest as plain XML inconst { execSync } = require('child_process'); // Extract and decode the entire APK (including the manifest) execSync('apktool d your_app.apk -o temp_apk_folder');temp_apk_folder/AndroidManifest.xml.
Once you have the editable XML, use standard XML manipulation libraries in JavaScript to update the app name. For example, with cheerio (a jQuery-like library for XML/HTML):
const cheerio = require('cheerio'); const fs = require('fs'); const xmlContent = fs.readFileSync('./editable_manifest.xml', 'utf8'); const $ = cheerio.load(xmlContent, { xmlMode: true }); // Update the android:label attribute in the <application> tag $('application').attr('android:label', 'Your New App Name'); // Save the modified XML fs.writeFileSync('./editable_manifest.xml', $.xml());
Note: If the app name uses a string resource (like @string/app_name instead of plain text), you’ll need to edit the corresponding strings.xml file in the res/values folder instead of the manifest.
Now convert your edited plain XML back to the binary format Android needs:
- axmlencoder (pure Node.js): This library handles encoding plain XML back to AXML. Install it:
Then encode and replace the manifest in your unzipped APK:npm install axmlencoderconst AXMLEncoder = require('axmlencoder'); const fs = require('fs'); const modifiedXml = fs.readFileSync('./editable_manifest.xml', 'utf8'); const encoder = new AXMLEncoder(modifiedXml); const binaryManifest = encoder.encode(); // Write the binary manifest back to the unzipped APK directory fs.writeFileSync('./unzipped_apk/AndroidManifest.xml', binaryManifest); - Apktool (rebuild): If you used Apktool to decode, rebuilding the APK will automatically handle re-encoding all resources:
execSync('apktool b temp_apk_folder -o modified_app.apk');
Android won’t install an unsigned APK, so after re-packaging, you need to sign it. You can use tools like apksigner (from the Android SDK) or Node.js libraries like signapk to generate a keystore and sign the APK.
- Some JavaScript AXML libraries might not handle complex manifest attributes perfectly. If you hit snags, Apktool is the most reliable fallback.
- Always test the modified APK on a device or emulator to make sure your changes work as expected.
内容的提问来源于stack exchange,提问作者Jose Ahías Vargas

