Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
13501714030 opened this issue Sep 17, 2024 · 6 comments
Open

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

13501714030 opened this issue Sep 17, 2024 · 6 comments

Comments

@13501714030
Copy link

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
Copy link
Collaborator

suve commented Sep 17, 2024

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
Copy link
Author

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
Copy link
Collaborator

suve commented Sep 18, 2024

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
Copy link
Author

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.

@suve
Copy link
Collaborator

suve commented Sep 18, 2024

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.

Footnotes

  1. https://github.com/libsdl-org/SDL/tree/release-2.30.7/android-project/app/src/main/java/org/libsdl/app

  2. https://github.com/suve/LD25/blob/release-2.1/android/app/src/main/AndroidManifest.xml

@13501714030
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants