Safeargs 库不生成方向类 [英] Safeargs library doesnt generate direction class

查看:28
本文介绍了Safeargs 库不生成方向类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用导航库和安全参数来传递数据.我将参数定义为这样的片段.

I use navigation library and safeargs for passing data. I define argument to fragment like that.

<fragment
        android:id="@+id/otherFragment"
        android:name="com.asd.navigate.OtherFragment"
        android:label="OtherFragment">
        <argument
            android:name="screenTitle"
            android:defaultValue="0"
            app:type="string" />
    </fragment>

OtherFragmentArgs 已生成,我可以使用它,但是当我单击制作项目"时,OtherFragmentDirection 类不会生成.是那个错误还是我必须做一些不同的事情.

OtherFragmentArgs generated, I can use it but OtherFragmentDirection class doesnt generate when I click "make project". Is that bug or I have to do something different.

感谢您的建议.

buildscript {
    ...
    dependencies {
       ...
        classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha01"

    }
}

build.gradle

build.gradle

apply plugin: "androidx.navigation.safeargs"

MainActivity.kt

MainActivity.kt

推荐答案

查找作为导航源的片段的类.如果您定义从 FragmentA 到 FragmentB 的导航,您将找到 FragmentADirections 类,其中包含您定义的操作(在 nav_graph.xml 中).

Look for the class of the fragment which is the source of navigation. If you define navigation from FragmentA to FragmentB, you will find FragmentADirections class with the actions you defined (in nav_graph.xml) in it.

然后,要生成方向类(也是参数类),您需要转到 Project level gradle 然后单击 build 命令.在这里我附上一个截图,以便清楚地理解.

Then, to generate direction class ( Also argument class) you need to go Project level gradle then click the build command. Here I attached a screenshot to give a clear understanding.

这篇关于Safeargs 库不生成方向类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆