JAVA解析APK包

JAVA解析APK包,获取APP版本名称,版本号,包名,已经是否是调试模式

1.添加依赖

        <!-- https://mvnrepository.com/artifact/net.dongliu/apk-parser -->
        <dependency>
            <groupId>net.dongliu</groupId>
            <artifactId>apk-parser</artifactId>
            <version>2.6.9</version>
        </dependency>

2.解析APK

    /**
     * 读取apk
     *
     * @param
     * @return
     */
    public static Map<String, Object> readAPK(File file) {
        Map<String, Object> map = new HashMap<>();
        try {
            ApkFile apkFile = new ApkFile(file);
            ApkMeta apkMeta = apkFile.getApkMeta();
            map.put("appName", apkMeta.getLabel());
            map.put("appId", apkMeta.getPackageName());
            map.put("versionCode", apkMeta.getVersionCode());
            map.put("versionName", apkMeta.getVersionName());
            map.put("debuggable", ReadXMLUtils.getRateCodeFromXmlString(apkFile.getManifestXml()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }