I need to build the R.java file from resource using the command line. I do this using the following Java program. I get the Errors:
invalid resource directory name: C:\Users\Muzammil-Husnain\testing\Soothing-snow-fall\res/drawable-tvdpi
and
invalid resource directory name: C:\Users\Muzammil-Husnain\testing\Soothing-snow-fall\res/drawable-xhdpi
If I remove these two folders from my res folder it says
ERROR: input directory 'Files' does not exist
Here is my code:
public static String ProjectPath = "C:\\Users\\Muzammil-Husnain\\testing\\Soothing-snow-fall";
public static String ANDROID_HOME = "C:/Program Files (x86)/Android/android-sdk";
public static void generateRfile() {
try {
File projectDirectoryFile = new File(ProjectPath);
String command = "aapt package -v -f -m "+
" -S \""+projectDirectoryFile.getCanonicalPath()+"/res\"" +
" -J \""+projectDirectoryFile.getCanonicalPath()+"/gen\"" +
" -M \""+projectDirectoryFile.getCanonicalPath()+"/AndroidManifest.xml\"" +
" -I C:\\Program Files (x86)\\Android\\android-sdk\\platforms\\android-21\\android.jar\"";
System.out.println("Directory Path : "+projectDirectoryFile.getCanonicalPath());
System.out.println(command);
ProcessBuilder processBuilder = new ProcessBuilder("cmd.exe", "/c", command);
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();
BufferedReader r = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while (true) {
line = r.readLine();
if (line == null) {
break;
}
System.out.println(line);
}
} catch (IOException ex) {
Logger.getLogger(RunApplicationOnPrject.class.getName()).log(Level.SEVERE, null, ex);
}
}

You are mounting a command line to call cmd.exe, and the directory isn't within double quotes, so the cmd.exe is interpreting the "Files" in C:\Program Files as different arguments. Try to place the directories/files specifications between double quotes, as this:
String command = "aapt package -v -f -m "+
" -S \""+projectDirectoryFile.getCanonicalPath()+"/res\"" +
" -J \""+projectDirectoryFile.getCanonicalPath()+"/gen\"" +
" -M \""+projectDirectoryFile.getCanonicalPath()+"/AndroidManifest.xml\"" +
" -I \""+ANDROID_HOME+"/platforms/android-18/android.jar\"";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With