using android aapt in java program

不打扰是莪最后的温柔 提交于 2019-12-12 10:24:49

问题


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"

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()?


回答1:


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();
    }
}



回答2:


I don't know if you have tried the below format, but just in case:

aapt  package -f -M ${manifest.file} -F ${packaged.resource.file} -I ${path.to.android-jar.library} -S ${android-resource-directory} [-m -J ${folder.to.output.the.R.java}]

Also just in case you have not looked at this website: how to build Android application

hope that helps.



来源:https://stackoverflow.com/questions/11511206/using-android-aapt-in-java-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!