Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Multidex support with Qt Android

    Mobile and Embedded
    qtcore android multidex
    2
    2
    1714
    Loading More Posts
    • 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.
    • robolivable
      robolivable last edited by

      Multidex support for Android looks to be like an unlit topic in the Qt community, so I thought I'd share my experiences in a topic post.

      When extending your Qt Android application with custom activities, you may want to take advantage of integrating external libraries. With the number of SDKs/plugins that are available, it can be easy to reach that 65K method limit. This is the issue that multidex support is meant to solve.

      Enabling multidex support on Qt isn't difficult, and can be achieved with the following steps (I'm including the steps required for the legacy multidex library, assuming that most Qt apps will have a minSdkVersion of lower than 20):

      1. Assuming you have already created your Android template files, add the following line to the project's "dependencies" block in your build.gradle file: compile 'com.android.support:multidex:1.0.0'

      2. In the same file, inside the "android" block, add the following: defaultConfig { multiDexEnabled = true }

      3. Add the following import to your application's main activity file: import android.support.multidex.MultiDex;

      4. The last step involves overriding the following method in your application's main activity class (the class that extends QtActivity):

         /* Multidex support */
         @Override
         protected void attachBaseContext(Context base) {
             super.attachBaseContext(base);
             MultiDex.install(this);
         }
        
      5. You're done, go ahead and build your application.

      This was the most common error I ran into:java.lang.ClassNotFoundException: Didn't find class "org.qtproject.qt5.android.QtActivityDelegate" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib]]. This happens when you don't integrate multidex correctly. Specifically, the ClassNotFoundException goes away after calling MultiDex.install() in your main activity class.

      Hope this ends up helping someone.

      1 Reply Last reply Reply Quote 1
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Thanks for sharing this ! Looks it might be worth including in Qt's platform notes for Android

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 1
        • First post
          Last post