Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Unable to run SDL on QtAndroid
Forum Updated to NodeBB v4.3 + New Features

Unable to run SDL on QtAndroid

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 3 Posters 670 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SAHIL1804
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • S SAHIL1804

      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

      S Offline
      S Offline
      SAHIL1804
      wrote on last edited by
      #2

      @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!

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qidingshenxian
        wrote on last edited by
        #3

        I have encountered the same problem. Has this problem been solved?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          djhdjwl
          wrote on last edited by
          #4

          @SAHIL1804 @qidingshenxian Hi guys, I have the same problem, have you solved this problem and can you share the solution? Thank you very much!

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved