java代码安卓apk 脚本判断32位和64位兼容,还是纯64位

安卓apk 脚本判断32位和64位兼容,还是纯64位_apk打包兼容32位和64位的-CSDN博客

转java代码:

package cn.silence;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.HashSet;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

public class ApkProcessor {

    public static void main(String[] args) {
        String apkFilePath = "C:\\Users\\12095\\Desktop\\apk\\20241008082912.apk"; // APK文件路径
        String zipFilePath = "C:\\Users\\12095\\Desktop\\apk\\20241008082912.zip"; // 输出的ZIP文件路径
        String targetDir = "lib/"; // 特定子目录的路径

        try {
            // 步骤1:将APK转换为ZIP
            convertApkToZip(apkFilePath, zipFilePath);
            System.out.println("转换完成");

            // 步骤2:在ZIP中查找子目录
            Set<String> uniqueSubDirs = findSubDirsInZip(zipFilePath, targetDir);

            // 步骤3:根据子目录数量复制并重命名APK文件
            copyAndRenameApk(apkFilePath, uniqueSubDirs.size());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void convertApkToZip(String apkFilePath, String zipFilePath) throws IOException {
        try (ZipInputStream apkZip = new ZipInputStream(new FileInputStream(apkFilePath));
             ZipOutputStream zipOutput = new ZipOutputStream(new FileOutputStream(zipFilePath))) {
            ZipEntry entry;
            byte[] buffer = new byte[1024];
            int bytesRead;
            while ((entry = apkZip.getNextEntry()) != null) {
                zipOutput.putNextEntry(new ZipEntry(entry.getName()));
                while ((bytesRead = apkZip.read(buffer)) != -1) {
                    zipOutput.write(buffer, 0, bytesRead);
                }
                zipOutput.closeEntry();
            }
        }
    }

    private static Set<String> findSubDirsInZip(String zipFilePath, String targetDir) throws IOException {
        Set<String> subDirs = new HashSet<>();
        try (ZipInputStream zipInput = new ZipInputStream(new FileInputStream(zipFilePath))) {
            ZipEntry entry;
            while ((entry = zipInput.getNextEntry()) != null) {
                String entryName = entry.getName();
                if (entryName.startsWith(targetDir) && entryName.substring(targetDir.length()).contains("/")) {
                    String subDirName = entryName.substring(targetDir.length()).split("/")[0];
                    subDirs.add(subDirName);
                }
            }
        }
        System.out.println("亲儿子目录数量: " + subDirs.size() + ", 亲儿子目录名称: " + String.join(", ", subDirs));
        return subDirs;
    }

    private static void copyAndRenameApk(String sourceApkPath, int subDirCount) throws IOException {
        String targetDirectory = "C:\\Users\\12095\\Desktop\\apk\\"; // 目标目录
        String targetFileName = (subDirCount == 2) ? "32位_64位.apk" : "64位.apk"; // 根据子目录数量设置文件名
        Path targetApkPath = Paths.get(targetDirectory, targetFileName);

        Files.copy(Paths.get(sourceApkPath), targetApkPath, StandardCopyOption.REPLACE_EXISTING);
        System.out.println("文件已复制并重命名为: " + targetApkPath);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Silence丶你的名字

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值