PascalGameDevelopment / SDL2-for-Pascal

Unit files for building Free Pascal and Delphi applications using the SDL2 library
https://pascalgamedevelopment.github.io/SDL2-for-Pascal/
Mozilla Public License 2.0
103 stars 20 forks source link

how to get the ARM64 Android libSDL2.so ? #146

Open 13501714030 opened 2 months ago

13501714030 commented 2 months ago

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?

suve commented 2 months ago

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.

13501714030 commented 2 months ago

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?

suve commented 2 months ago

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?

13501714030 commented 2 months ago

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 6989411@qq.com ?

thank you very much.

suve commented 2 months ago

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.

13501714030 commented 2 months ago

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.