Qt在Android上运行时错误:获取资源编号为0x00000000的包时,无效的包标识符。

huangapple go评论80阅读模式
英文:

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

问题

我在将Qt版本从5.13.1更新到5.14.2后遇到了这个奇怪的错误,我不确定是什么原因导致的(我还将gradle版本从4.1.0更新到了5.5.1)。错误输出信息如下:

> W ResourceType:获取资源编号为0x00000000的包时出现无效的包标识符
> E Qt :无法创建主活动 E Qt
> :android.content.res.Resources$NotFoundException:字符串数组
> 资源ID#0x0 E Qt :在
> android.content.res.Resources.java中,.getStringArray(Resources.java:525) E Qt
> :在
> org.qtproject.qt5.android.bindings.QtLoader.startApp(QtLoader.java:423) E Qt :在
> org.qtproject.qt5.android.bindings.QtActivityLoader.onCreate(QtActivityLoader.java:166) E Qt :在
> org.qtproject.qt5.android.bindings.QtActivity.onCreateHook(QtActivity.java:266) E Qt :在
> org.qtproject.qt5.android.bindings.QtActivity.onCreate(QtActivity.java:273)

我注意到以前已经讨论过这个问题,但所提供的解决方案与Qt无关,需要修改Java代码(我认为在我的情况下这绝不是问题,因为我没有进行过更改)。

英文:

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

答案1

得分: 7

Qt 5.14 需要一个不同的 AndroidManifest.xml 文件,与 Qt 5.13 或更早版本不同。我遵循了 Qt 的建议,并做出了以下更改以使其再次正常工作:

  1. AndroidManifest.xml 中,将属性 android:extractNativeLibs="true" 添加到 <application …> 元素中。

  2. AndroidManifest.xml 中,删除以下三行(简写显示):

    <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. AndroidManifest.xml 中,将以下行插入到其他 <meta-data …/> 行之中:

    <meta-data android:name="android.app.load_local_libs_resource_id" android:resource="@array/load_local_libs"/>
    
  4. 在 Android 配置目录中的 res/values/libs.xml 中,在 <resources> … </resources> 元素中插入以下行:

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

同时使用 Qt 5.13。 关于此问题的更多细节可以在问题 QTBUG-80444 中找到。从那里来看,不幸的是,所需的更改与 Qt 5.13 或更早版本不兼容,这意味着你需要一个版本的 AndroidManifest.xml 来构建适用于使用 Qt 5.13 的 Android 应用,而另一个版本则用于使用 Qt 5.14 进行构建。(当然,除非你从不想回退到 Qt 5.13。)

来源。 源自 @daljit97 在此页面的 另一个答案 中提到的 Qt 示例差异。但这仍然会导致一个错误:“AndroidManifest.xml:80: error: resource array/load_local_libs (aka com.example.qtws:array/load_local_libs) not found.”。在部署过程中,这条评论 指引我找到了正确的解决方法。

英文:

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.

答案2

得分: 1

好的,原来Qt 5.14需要一个项目的AndroidManifest.xml文件的更新版本。在这里提到了这一点 Qt for Android已知问题。所需的更改可以在以下链接中找到 链接

更新清单文件后,我的项目可以正常运行。

英文:

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.

huangapple
  • 本文由 发表于 2020年4月8日 17:57:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/61097966.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定