Dmytro Parkhomenko
Dmytro Parkhomenko

Reputation: 134

how to add dalvik vm in android project

Im trying to create a game core and everything is done exept compiler. I tryed to to like that:


package com.ccs.gencorelite.compiler;

import java.io.IOException;

public class ProjectCompiler {

    public static void compileProject(String projectPath, String outputPath) {
        try {
            ProcessBuilder builder = new ProcessBuilder(
                    "aapt", "package", "-f",
                    "-M", projectPath + "/AndroidManifest.xml",
AndroidManifest.xml
                    "-S", projectPath + "/res", 
                    "-I", "file:///resources/android.jar",                    "-F", outputPath + "/app.apk" 
            );

            builder.redirectErrorStream(true);

            Process process = builder.start();

            // Очікування завершення процесу
            int exitCode = process.waitFor();

            // Перевірка статусу завершення
            if (exitCode == 0) {
                System.out.println("Проєкт успішно скомпільовано.");
            } else {
                System.out.println("Помилка під час компіляції проєкту.");
            }
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}

After some errors that i have not permissions to compile. I rewrite this class added some folders to assets folder: build-tools34, platforms, platform-tools, sdk34 and this class is have like this view:

package com.ccs.gencorelite.compiler;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ProjectCompiler {


    public static void compileJavaFiles(String projectPath) {

        String javaCompilerPath = "file:///android_asset/compiler/bt34/javac";
        String[] javacCmd = { javaCompilerPath, "-d", projectPath + "/bin", projectPath + "/src/**/*.java" };
        executeCommand(javacCmd);
    }

    public static void compileResources(String projectPath) {
        String aaptPath = "file:///android_asset/compiler/bt34/aapt";
        String[] aaptCmd = { aaptPath, "package", "-f", "-m", "-J", projectPath + "/gen", "-S", projectPath + "/res", "-I", "file:///android_resources/android.jar" };
        executeCommand(aaptCmd);
    }

    public static void convertToDalvikBytecode(String projectPath) {
        String dxPath = "file:///android_asset/compiler/bt34/dx";
        String[] dxCmd = { dxPath, "--dex", "--output=" + projectPath + "/bin/classes.dex", projectPath + "/bin" };
        executeCommand(dxCmd);
    }

    public static void executeCommand(String[] command) {
        try {
            Process process = new ProcessBuilder(command).start();
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
            reader.close();
            process.waitFor();
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}

And i have errors about this class: ` java.io.IOException: Cannot run program "file:///android_assets/compiler/bt34/javac": error=2, No such file or directory

2024-05-09 22:14:26.305 28386-28386 System.err com.ccs.gencorelite W java.io.IOException: Cannot run program "file:///android_assets/compiler/bt34/aapt": error=2, No such file or directory

2024-05-09 22:14:26.312 28386-28386 System.err com.ccs.gencorelite W java.io.IOException: Cannot run program "file:///android_assets/compiler/bt34/dx": error=2, No such file or directory `

Upvotes: 0

Views: 34

Answers (0)

Related Questions