Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Unable to run SDL on QtAndroid



  • I am trying to build an app using SDL2.0.14 for using game controllers. It is to be deployed on an android device.
    Device specs: Android 7.1, Architecture: ARM64-v8a
    Qt specs : Qt 5.15.0
    JDK : AdoptOpenJDK\jdk-11.0.10.9-hotspot
    NDK : 21.1.6352462
    I downloaded the source code for SDL and compiled it using the README-android.me.
    First of all I donot want to use any source code in the NDK build so I commented out the following line from app\jni\src\Android.mk.

    LOCAL_SRC_FILES := YourSourceHere.c
    

    Now after libs were created, I copied libSDL.so, libmain.so and libhidapi.so to android/libs in the Qt project. I also copied the respective .java file in the appropriate locations.

    I provided the links and include paths in the .pro file of the Qt project.
    The app compile properly and the apk is created.
    But on deployment, the app immediately crashes without any error but just saying "W : exit app 0".
    Following is my main.cpp file:

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <SDL.h>
    
    
    int main(int argc, char *argv[])
    {
    #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    #endif
    
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        const QUrl url(QStringLiteral("qrc:/main.qml"));
        QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                         &app, [url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        }, Qt::QueuedConnection);
        engine.load(url);
    
        return app.exec();
    }
    
    

    Now if I change "#include <SDL.h>" to "#include <SDL_joystick.h>" or any other header which is included in the SDL.h file, the app compiles fine and gets deployed correctly.

    I need to use the complete SDL suite.
    I have tried many things on the internet but an really not able to get aroud this.
    Please let me know if anything else is required or if the provided info is insufficient.

    Thanks



  • @SAHIL1804 I was able to solve this crashing issue by defining SDL_MAIN_HANDLED.
    The application now runs fine however on doing SDL_Init(SDL_INIT_EVERYTHING), get the following error through SDL_GetError().

    error initializing SDL: Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?
    

    I tried the following methods:

    • Using #undef main() => Same output
    • #define SDL_main main => Same output
    • Using SDL_SetMainReady() => A lot of errors at run time and application crashes

    I referenced these methods from the SDL documentation and various online forums.

    How can I resolve this issue?

    Thanks!


Log in to reply