Safe args: cannot resolve symbol 'string'

问题: I'm using Navigation Architecture Components, and I wanted to take advantage of the safe args plugin. I want to add some arguments to one of my fragments in the navigati...

问题:

I'm using Navigation Architecture Components, and I wanted to take advantage of the safe args plugin.

I want to add some arguments to one of my fragments in the navigation graph. The arguments code is generated via the Design editor. Here's a snippet:

<fragment
    android:id="@+id/inAppPurchaseFragment"
    android:name="purchaseFragment" >
    <argument
        android:name="attribution_id"
        app:type="string" />
</fragment>

However, I'm getting an error in Android Studio (3.2 Canary 16) that says it cannot resolve the symbol 'string', or any type I try to use. Have any of you had this issue & do you know why it's occurring?

Update for more context; I get this error during build on the line that has app:type="string":

error: 'string' is incompatible with attribute type (attr) integer.


回答1:

Your code looks good, make sure you add a defaultValue to it

android:defaultValue="something"

And by the way, have you implemented Navigation Architecture Components as it says on adding-components documentation ?

dependencies {
    def nav_version = "1.0.0-alpha02"

    implementation "android.arch.navigation:navigation-fragment:$nav_version" // use -ktx for Kotlin
    implementation "android.arch.navigation:navigation-ui:$nav_version" // use -ktx for Kotlin

    // optional - Test helpers
    androidTestImplementation "android.arch.navigation:navigation-testing:$nav_version" // use -ktx for Kotlin
}

回答2:

Make sure to put

classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha02"

in your project level build.gradle

and put

apply plugin: 'androidx.navigation.safeargs'

in your application level build.gradle.

.................

android:defaultValue is optional

  • 发表于 2018-07-11 14:28
  • 阅读 ( 866 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除