本文介绍了在Java程序中使用android aapt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试通过Java程序执行aapt命令了一段时间了.我的直觉是我应该使用 runtime.exec()命令来实现这一目标.但是,我查看了其他问题和答案,但似乎没有一个对我有用.命令是:

I have been trying to execute the aapt command through a java program for quite some time now. My hunch is that I should be using the runtime.exec() command to make this happen. However, I have looked at other questions and answers and none seem to work for me.The command is:

 aapt package -u -f -F "/home/jay/testing_FILES.apk" "/home/jay/testing_FILES"

其中/home/jay/testing_FILES 是原始文件夹,而/home/jay/testing_FILES.apk 是最终apk的打包名称和位置.谁能向我解释如何使用aapt和java runtime.exec()正确运行此命令?

where the /home/jay/testing_FILES is the original folder and the /home/jay/testing_FILES.apk is the packaged name and location of the final apk. Can anyone explain to me how I can make this command run correctly using the aapt and java runtime.exec()?

推荐答案

我知道这个老问题,但是尝试一下:

Old question, I know, but try this out:

String[] cmd = {"aapt", "package", "-u", "-f", "-F", "/"//home//jay//testing_FILES.apk/"", "/"//home//jay//testing_FILES/""};

Runtime run = Runtime.getRuntime();
Process pr = null;
try {
    pr = run.exec(cmd);
    pr.waitFor();
} catch (IOException e) {
    e.printStackTrace();
} catch (InterruptedException e) {
    e.printStackTrace();
} finally {
    if(pr != null){
        close(pr.getOutputStream());
        close(pr.getInputStream());
        close(pr.getErrorStream());
        pr.destroy();
    }
}

这篇关于在Java程序中使用android aapt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 00:57