从命令行“无效的资源目录名称”生成 R.java 文件
generating R.java file from command line “invalid resource directory name”
我需要使用命令行从资源构建 R.java 文件。我使用以下 Java 程序执行此操作。
我收到错误:
invalid resource directory name: C:\Users\Muzammil-Husnain\testing\Soothing-snow-fall\res/drawable-tvdpi
和
invalid resource directory name: C:\Users\Muzammil-Husnain\testing\Soothing-snow-fall\res/drawable-xhdpi
如果我从我的 res 文件夹中删除这两个文件夹,它会显示
ERROR: input directory 'Files' does not exist
这是我的代码:
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);
}
}
您正在安装调用 cmd.exe 的命令行,并且该目录不在双引号内,因此 cmd.exe 正在解释 C:\Program Files 中的 "Files"作为不同的论点。尝试将 directories/files 规范放在双引号之间,如下所示:
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\"";
编辑:
我的一个朋友向我指出 gradle. It is a sophisticated build automation tool, which can also be used from the command line. Since setting up resources and assets for Android is always a nightmare you might want to take a look at it. There seem to be a few tutorials for creating Android apps like this one or this one。
根据 this SO post,您可能需要跳过一些步骤才能将资源文件夹正确添加到项目中。
另一个问题是 sometimes comes up 已过时 aapt and/or Android SDK 版本。您应该检查是否可以将它们更新到任何更新的版本。
android aapt 未找到 jar 文件问题是代码中缺少开始引用
" -I C:\Program Files (x86)\Android\android-sdk\platforms\android-21\android.jar\""
虽然结束引用存在,但 url 到 android.jar 被打破所以我改变了。所以我将代码更改为
" -I \"C:\Program Files (x86)\Android\android-sdk\platforms\android-21\android.jar\""
问题已解决 :-)
我需要使用命令行从资源构建 R.java 文件。我使用以下 Java 程序执行此操作。 我收到错误:
invalid resource directory name: C:\Users\Muzammil-Husnain\testing\Soothing-snow-fall\res/drawable-tvdpi
和
invalid resource directory name: C:\Users\Muzammil-Husnain\testing\Soothing-snow-fall\res/drawable-xhdpi
如果我从我的 res 文件夹中删除这两个文件夹,它会显示
ERROR: input directory 'Files' does not exist
这是我的代码:
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);
}
}
您正在安装调用 cmd.exe 的命令行,并且该目录不在双引号内,因此 cmd.exe 正在解释 C:\Program Files 中的 "Files"作为不同的论点。尝试将 directories/files 规范放在双引号之间,如下所示:
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\"";
编辑:
我的一个朋友向我指出 gradle. It is a sophisticated build automation tool, which can also be used from the command line. Since setting up resources and assets for Android is always a nightmare you might want to take a look at it. There seem to be a few tutorials for creating Android apps like this one or this one。
根据 this SO post,您可能需要跳过一些步骤才能将资源文件夹正确添加到项目中。
另一个问题是 sometimes comes up 已过时 aapt and/or Android SDK 版本。您应该检查是否可以将它们更新到任何更新的版本。
android aapt 未找到 jar 文件问题是代码中缺少开始引用
" -I C:\Program Files (x86)\Android\android-sdk\platforms\android-21\android.jar\""
虽然结束引用存在,但 url 到 android.jar 被打破所以我改变了。所以我将代码更改为
" -I \"C:\Program Files (x86)\Android\android-sdk\platforms\android-21\android.jar\""
问题已解决 :-)