nikita36078 / J2ME-Loader

A J2ME emulator for Android.
Apache License 2.0
2.07k stars 208 forks source link

Porting J2ME application to Android with MIdlet Project #952

Closed GdGohan closed 1 year ago

GdGohan commented 1 year ago

Description of the issue: I'm trying to make an apk port of a j2me game (SonicRacing) the problem is that I don't know how to load the files inside the jar, what I get is a black screen and "Error reading resource file".

woesss commented 1 year ago

find and check all calls getResourceAsStream(String) - they MUST NOT be called on system classes

InputStream is = "".getClass().getResourceAsStream("/file"); // incorrectly (used system classloader for find resource)
InputStream is = this.getClass().getResourceAsStream("file"); // correctly (used app classloader for find resource)
InputStream is = <MidletOwnClass>.class.getResourceAsStream("file"); // correctly (used app classloader for find resource)
InputStream is = AppClassLoader.getResourceAsStream(null, "/file"); // correctly (used emulator api for find resource)
InputStream is = AppClassLoader.getResourceAsStream(<ReferencedClass>.class, "file"); // correctly (used emulator api for find resource)

If you are using jar (not source code) - you need to patch it via ASM-java like emulator converter:
https://github.com/nikita36078/J2ME-Loader/tree/master/dexlib/src/main/java/org/microemu/android/asm

GdGohan commented 1 year ago

find and check all calls getResourceAsStream(String) - they MUST NOT be called on system classes

InputStream is = "".getClass().getResourceAsStream("/file"); // incorrectly (used system classloader for find resource)
InputStream is = this.getClass().getResourceAsStream("file"); // correctly (used app classloader for find resource)
InputStream is = <MidletOwnClass>.class.getResourceAsStream("file"); // correctly (used app classloader for find resource)
InputStream is = AppClassLoader.getResourceAsStream(null, "/file"); // correctly (used emulator api for find resource)
InputStream is = AppClassLoader.getResourceAsStream(<ReferencedClass>.class, "file"); // correctly (used emulator api for find resource)

If you are using jar (not source code) - you need to patch it via ASM-java like emulator converter: https://github.com/nikita36078/J2ME-Loader/tree/master/dexlib/src/main/java/org/microemu/android/asm

"If you are using jar (not source code) - you need to patch it via ASM-java like emulator converter: https://github.com/nikita36078/J2ME-Loader/tree/master/dexlib/src/main/java/org/microemu/android/asm" example? i'm using android studio so if i can load the class will it be able to detect the other files or do i need to put them in the assets folder? for example: I have the .class and the files "1;2;3;4........." should they be outside or inside the assets folder? And android studio manages to decompile the jar and put the codes in the dex file in the apk

I'm not a programmer, just a curious researcher :)

nikita36078 commented 1 year ago

Probably a bit late here, but still. The most obvious solution for your case is to convert the game in J2ME Loader, put all resources in the project and set it up as said here. Also you need to put converted.dex in the apk too and modify MicroLoader accordingly to load it.