Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

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 complieResources(String projectDir, int packageId) {
        StringBuffer command = new StringBuffer();
        command.append(AAPT_PATH).append(" package -f -M ").append(projectDir).append("\\AndroidManifest.xml ")
                .append("-S ").append(projectDir).append("\\res ").append("-I ").append(ANDROID_JAR_PATH)
                .append(" -A ").append(projectDir).append("\\assets ").append(" -F ").append(projectDir)
                .append("\\bin\\resources.ap_").append(" --non-constant-id -x --package-id ").append(packageId);
        buildExeBatchFiles(command.toString(), "4.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();
    }
}