DexClassLoader 无法打开 .dm 文件

问题描述 投票:0回答:1

我正在尝试在 Android 应用程序中以 java 代码的形式实现字符串启动。 我正在使用 libgdx、janino 编译器和 dx。

String script = "public class Script{\n}"; //just for example
SimpleCompiler compiler = new SimpleCompiler();

try {

compiler.cook(script);
FileHandle newFile = Gdx.files.external("ScriptClass.class");
if (!newFile.exists())
    newFile.write(false);


newFile.writeBytes(compiler.getBytecodes().get("ScriptClass"), false);

    String scriptPath = Gdx.files.getExternalStoragePath();
    Main.main(new String[]{
                "--output=" +scriptPath +"/ScriptClass.dex", scriptPath +"/./ScriptClass.class"
    });

    PathClassLoader classLoader = new PathClassLoader(scriptPath +"/ScriptClass.dex", ScriptInterface.class.getClassLoader());
classLoader.loadClass("ScriptClass");
        
} catch (CompileException e) {
    e.printStackTrace();
} catch (ClassNotFoundException e) {
    e.printStackTrace();
} catch (IllegalAccessException e) {
    e.printStackTrace();
} catch (InstantiationException e) {
    e.printStackTrace();
}

我从字符串创建一个.java类,将其编译为.class文件,然后将其编译为.dex,创建了.dex文件,但该类未启动并出现错误 “ziparchive 无法打开‘ScriptClass.dm’,没有这样的文件或目录”(System.err) 这个 .dm 文件是什么,为什么需要它以及如何创建它?

java dex
1个回答
0
投票

我从来没有听说过Android开发环境中的“.dm”。您的代码中可能存在拼写错误,导致出现此异常的文件扩展名错误。或者我不知道它是否特定于您的项目设置。

© www.soinside.com 2019 - 2024. All rights reserved.