You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用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:

Step 1: Decode the Binary Manifest to Plain XML

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:
    npm install axmlparser
    
    Then use it to read and convert the binary manifest:
    const 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:
    const { execSync } = require('child_process');
    
    // Extract and decode the entire APK (including the manifest)
    execSync('apktool d your_app.apk -o temp_apk_folder');
    
    This will dump the decoded manifest as plain XML in temp_apk_folder/AndroidManifest.xml.
Step 2: Modify the Plain XML Manifest

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.

Step 3: Re-encode the Modified XML to Binary AXML

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:
    npm install axmlencoder
    
    Then encode and replace the manifest in your unzipped APK:
    const 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');
    
Critical Final Step: Sign the Modified 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.

Quick Tips
  • 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:54:31