问题
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