android - Resources$NotFoundException 与包含动态导航图

标签 android android-jetpack android-architecture-navigation android-jetpack-navigation dynamic-feature-module

我有一个动态功能模块,它有自己的嵌套导航图。我还有一个动态功能模块,它只是一个 fragment 。如果您有一个带有自己导航图的动态功能模块,我知道您需要使用 包含动态标签。当我构建应用程序并将应用程序部署到 Play 商店进行内部测试时,动态模块会正确下载。但是,如果我在本地构建/运行 - 当我尝试导航到包含导航图的动态功能模块时,应用程序崩溃。我以为在本地运行时所有东西都 bundle 了?有什么我想念的吗?
我得到的错误是 android.content.res.Resources$NotFoundException: com.xyz.app_name.two:navigation/two_navigation main_navigation_graph

<!-- this works locally. module does not contain a nav graph -->
<fragment
    android:id="@+id/OneFragment"
    android:name="com.xyz.app_name.one.OneFragment"
    android:label="{nickname}"
    app:moduleName="one"
    tools:layout="@layout/one_fragment">
    <argument
        android:name="nickname"
        app:argType="string" />
</fragment>

<!-- this doesn't work locally -->
<include-dynamic
    android:id="@+id/two_graph"
    app:graphPackage="com.xyz.app_name.two"
    app:graphResName="two_navigation"
    app:moduleName="two" />
feature_two_graph
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@id/two_graph"
    app:moduleName="two"
    app:startDestination="@id/twoFragment">

    <fragment
        android:id="@+id/twoFragment"
        android:name="com.xyz.app_name.two.TwoFragment"
        android:label="{nickname}"
        tools:layout="@layout/two_fragment">
        <argument
            android:name="nickname"
            app:argType="string" />
        <action
            android:id="@+id/action_twoFragment_to_dialogFragment"
            app:destination="@id/dialogFragment" />
    </fragment>

    <dialog
        android:id="@+id/dialogFragment"
        android:name="com.xyz.app_name.two.ui.DialogFragment"
        android:label="bottom_sheet"
        tools:layout="@layout/bottom_sheet" />

</navigation>

最佳答案

我有同样的问题。
当尝试将动态特征图添加为目标时,使用 include-dynamic 如下:

<include-dynamic
    android:id="@+id/nestedMyfeatureGraph"
    app:graphPackage="com.mycompany.myapp.mydynamicfeature"
    app:graphResName="nav_graph_feature"
    app:moduleName="mydynamicfeature"
    />
应该记住 app:graphPackage应该引用动态功能的 applicationId (我知道, it's confusing )。如果您有任何自定义 gradle 脚本将后缀添加到 applicationId 或类似的东西,那么引用该图将失败。
它可能只对你在 playstore 有效,因为我猜你的脚本只为非 prodRelease 构建类型添加了后缀,这是一种常见的模式。
所以,要解决我必须更换的问题
    app:graphPackage="com.mycompany.myapp.mydynamicfeature"
    app:graphPackage="${applicationId}.mydynamicfeature"

关于android - Resources$NotFoundException 与包含动态导航图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64122383/

相关文章:

android - 如何使用 AsyncTasks 安全地访问我的 SQLite 数据库?

android - Activity 泄漏了原本是 android 的窗口

android - 带参数的多模块 Android 架构中的导航

Android:快速双击与导航组件相关的任何 View 会使应用程序崩溃

android - BottomAppBar 与 BottomNavigationDrawer 连接到 NavigationController

java - 返回当前的 android 布局或屏幕宽度以进行调试

java - Volley 没有收到 http 响应,但 postman 收到了

android - 具有多个顶级目的地的导航图

android - Jetpack 撰写 : Exception while analyzing expression

android - 如何在 Camera X 库中以编程方式更改相机镜头朝向?