Multidex support with Qt Android



  • 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.


  • Lifetime Qt Champion

    Hi,

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.