Qt on Android Runtime error: Invalid package identifier when getting bag for resource number 0x00000000

4

I am getting this strange error after updating my Qt version from 5.13.1 to 5.14.2 and I am not sure what is the cause of it (I also updated my gradle version from 4.1.0 to 5.5.1). The error give the following output message:

W ResourceType: Invalid package identifier when getting bag for resource number 0x00000000 E Qt : Can't create main activity E Qt : android.content.res.Resources$NotFoundException: String array resource ID #0x0 E Qt : at android.content.res.Resources.getStringArray(Resources.java:525) E Qt : at org.qtproject.qt5.android.bindings.QtLoader.startApp(QtLoader.java:423) E Qt : at org.qtproject.qt5.android.bindings.QtActivityLoader.onCreate(QtActivityLoader.java:166) E Qt : at org.qtproject.qt5.android.bindings.QtActivity.onCreateHook(QtActivity.java:266) E Qt : at org.qtproject.qt5.android.bindings.QtActivity.onCreate(QtActivity.java:273)

I have seen that this has been discussed before, but the solution given were unrelated to Qt and required the modification of Java code (which I don't think it is the problem at all in my case since I haven't changed that).

java
android
c++
qt
asked on Stack Overflow Apr 8, 2020 by daljit97

2 Answers

4

Qt 5.14 requires a different AndroidManifest.xml file than Qt 5.13 or earlier. I followed the Qt recommendations and ended up with the following changes to get it to work again:

  1. In AndroidManifest.xml, add attribute android:extractNativeLibs="true" into the <application …> element.

  2. In AndroidManifest.xml, remove the following three lines (shown abbreviated):

    <meta-data android:name="android.app.bundled_in_lib_resource_id" … />
    <meta-data android:name="android.app.bundled_in_assets_resource_id" … />
    <meta-data android:name="android.app.load_local_libs" … />
    
  3. In AndroidManifest.xml, insert the following line among the other <meta-data …/> lines:

    <meta-data android:name="android.app.load_local_libs_resource_id" android:resource="@array/load_local_libs"/>
    
  4. In res/values/libs.xml in your Android config directory, insert the following lines into the <resources> … </resources> element:

    <array name="load_local_libs">
        <!-- %%INSERT_LOCAL_LIBS%% -->
    </array>
    

Using Qt 5.13 in parallel. Some more detail about this issue is available in issue QTBUG-80444. From there, unfortunately it seems that the required changes are not backwards compatible with Qt 5.13 or earlier, means you need one version of AndroidManifest.xml to build for Android with Qt 5.13 and another version to build with Qt 5.14. (Except you never want to look back to Qt 5.13, of course.)

Sources. Derived from the Qt examples diff mentioned by @daljit97 in another answer on this page. That still lead to an error "AndroidManifest.xml:80: error: resource array/load_local_libs (aka com.example.qtws:array/load_local_libs) not found." on deployment, but this comment hinted me into the right direction to fix that.

answered on Stack Overflow May 30, 2020 by tanius • edited Jan 24, 2021 by tanius
1

Ok it turns out that Qt 5.14 requires an updated version of the AndroidManifest.xml file of a project. This is mentioned here Qt for Android known issues. The needed changes can be found at the following link.

After updating the manifest file, my project runs correctly.

answered on Stack Overflow Apr 8, 2020 by daljit97

User contributions licensed under CC BY-SA 3.0