安卓(Android) 怎么从windows命令行文件生成r

2019年10月17日21:23:49安卓(Android) 怎么从windows命令行文件生成r已关闭评论 262 1436字阅读4分47秒

1.简介

安卓(Android) 怎么从windows命令行文件生成r?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class Main {
    private static final String ANDROID_JAR_PATH = "D:\\android_sdk_for_studio\\platforms\\android-22\\android.jar";
    private static final String AAPT_PATH = "D:\\mochuan.zhb\\android-sdks\\build-tools\\22.0.1\\aapt_alitrip.exe";
    private static final String batchDir = System.getProperty("user.dir")
            + "\\batch\\";

    private static void generateR(String projectDir, int packageId) {
        StringBuffer command = new StringBuffer();
        command.append(AAPT_PATH).append(" package -f -m -J ")
                .append(projectDir).append("\\gen ").append("-S ")
                .append(projectDir).append("\\res ").append("-M ")
                .append(projectDir).append("\\AndroidManifest.xml ")
                .append(" -A ").append(projectDir).append("\\assets ")
                .append("-I ").append(ANDROID_JAR_PATH)
                .append(" --non-constant-id -x --package-id ")
                .append(packageId);
        buildExeBatchFiles(command.toString(), "1.bat");
    }

    private static void buildExeBatchFiles(String command, String fileName) {
        System.out.println(command);
        if (!new File(batchDir).exists()) {
            new File(batchDir).mkdirs();
        }
        String filePath = batchDir + fileName;
        try {
            writeFile(filePath, command);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void writeFile(String filePath, String content)
            throws IOException {
        FileWriter fw = new FileWriter(filePath);
        PrintWriter out = new PrintWriter(fw);
        out.write(content);
        out.println();
        fw.close();
        out.close();
    }
}

 
继续阅读
编程十万个怎么办