0

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

Chimera
  • 5,884
  • 7
  • 49
  • 81
JJJ1106
  • 57
  • 2
  • 8
  • Could you share some information about how it's running incorrectly? – Mike Yockey Jul 16 '12 at 19:31
  • It says that it doesn't know what the aapt is and when I tried to put the entire path to the aapt into the command it says: cannot run program, file/directory doesn't exist – JJJ1106 Jul 16 '12 at 19:36
  • String firstCommand = " /home/jay/andTools/aapt package -u -f -F '/home/jay/testing_FILES.apk' '/home/jay/testing_FILES' "; this is how i have been trying to input it. Originally i tried this without the /home/jay/andTools/ part – JJJ1106 Jul 16 '12 at 19:39
  • Does the same command line succeed from the shell prompt? – Diego Torres Milano Jul 16 '12 at 19:42
  • Yes it does I can't seem to automate this process through java – JJJ1106 Jul 16 '12 at 19:45
  • Have you tried using the String[] version of Runtime.exec(), so you can pass each argument as a separate string? – Ian Ni-Lewis Oct 18 '12 at 00:23

2 Answers2

2

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();
    }
}
Jon F Hancock
  • 3,349
  • 3
  • 23
  • 26
0

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.

0gravity
  • 2,682
  • 4
  • 24
  • 33