SDL2-for-Pascal icon indicating copy to clipboard operation
SDL2-for-Pascal copied to clipboard

how to get the ARM64 Android libSDL2.so ?

Open 13501714030 opened this issue 1 year ago • 6 comments

I have been searching for the ARM64 SDL2.so library file for Android for a long time, and I have downloaded several versions of the SDL2 source code and compiled libSDL2.so myself, but none of them can be used directly in Delphi. After some research, I found that some people say SDL2 for Android can only be called using Java in Android Studio. Is that true?

13501714030 avatar Sep 17 '24 15:09 13501714030

What I do for Android ports of my Pascal games is I build SDL2 from source using the Android NDK. This works fine for FPC; no idea about Delphi.

suve avatar Sep 17 '24 15:09 suve

I also compiled it using the Android NDK, and after compilation, a libMain.so file is generated. Do you have this file generated as well? If this file is generated, it cannot be called using languages other than Java.

Could you send me the libSDL2.so file you generated so I can test it?

13501714030 avatar Sep 18 '24 00:09 13501714030

After building, I get libSDL2.so, as expected (plus libSDL2_image.so and libSDL2_mixer.so, since I'm building those as well). How do you build the lib? Manually with ndk-build or CMake? Through Gradle?

suve avatar Sep 18 '24 07:09 suve

i built it with ndk-build

I developed an Android application using Delphi development tool, but after directly calling the libSDL2.so, SDL cannot be initialized, and the application crashes unexpectedly. It's strange, I've tried many different versions of libSDL2.so, including compiling the official SDL source code with NDK to generate libSDL2.so, but none of them can be called by other Android development tools except for Java in Android Studio. I don't understand why this is happening.

my code is :

{$IFDEF ANDROID}

FixupStub(ALibFile, AHandle, 'JNI_OnLoad', Addr(JNI_OnLoad));

if Assigned(JNI_OnLoad) then JNI_OnLoad(PJavaVM(System.JavaMachine), nil);

{$ENDIF} SDLLoader.Refresh;

the issue comes from here, when i call JNI_OnLoad(), it will rasie an exception and the app will crash.

the log information is :

JNI DETECTED ERROR IN APPLICATION: JNI FindClass called with pending exception java.lang.ClassNotFoundException: Didn't find class "org.libsdl.app.SDLActivity" on path: DexPathList...

attention, i am not using Android Studio and not using java, i am using Delphi, it is Pascal language

i think your libSDL2.so is only for java using, can not be called via the other development tool and language

so i hope can use your built file , try it again , if possible could you send your libSDL2.so file to [email protected] ?

thank you very much.

13501714030 avatar Sep 18 '24 07:09 13501714030

I think the issue here is that libSDL2.so isn't meant to be used purely by itself. If you look at the SDL sources, specifically inside android-project/, you'll see that there's a directory with a whole bunch of Java classes inside it, including SDLActivity.java. ^1 What I do with my game is that I compile the game itself to an .so file, then include all of the Java code in the .apk and edit AndroidManifest.xml to treat the SDLActivity as the entry point. ^2 SDL's java code then takes care of initializing the library and calling into my game's code.

suve avatar Sep 18 '24 10:09 suve

yes, i am clear , but i have another libSDL2.so file which is v2.0.0 and it was compiled to armeabi-v7a, it can be called by Delphi directly. :( only use System.LoadLibrary and every functions in libSDL2.so can be called with not any problems.

13501714030 avatar Sep 18 '24 11:09 13501714030