DexClassLoader unable to open .dm file

259 Views Asked by At

I'm trying to implement a string launch in an Android application as java code. I'm using libgdx, janino compiler and 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();
}

I create a .java class from a string, compile it into a .class file, then compile it into a .dex, the .dex file is created, but the class does not start and an error occurs "ziparchive unable to open 'ScriptClass.dm' no such file or directory" (System.err) What is this .dm file, why is it needed and how to create it?

1

There are 1 best solutions below

1
Yagiz_ebil On

I have never heard of ".dm" in the Android development environment. There might be a typo in your code that causing this unusual file extension error. Or I don't know if it is specific for you project setup.