【问题标题】:Navigation Component - Access BuildConfig in nav graph导航组件 - 在导航图中访问 BuildConfig
【发布时间】:2021-07-14 05:36:08
【问题描述】:

我在我的 gradle 文件中定义了基本 url,例如

buildTypes {
    debug {
        applicationIdSuffix ".debug"
        minifyEnabled false
        debuggable true
        buildConfigField("String", "BASE_URL", "\"https://abc.tech/api/\"")
    }
    stag {
        applicationIdSuffix ".stag"
        minifyEnabled false
        debuggable false
        buildConfigField("String", "BASE_URL", "\"https://xyz.tech/api/\"")
    }
}

我希望在我定义了深度链接的导航图中访问BASE_URL。即

<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/navGraph"
    app:startDestination="@id/fragmentX">

     <fragment
        android:id="@+id/fragment1"
        android:name="com.xyz.abc.Fragmen1"
        android:label="Fragmen1">
        <argument
            android:name="userId"
            app:argType="string" />
        <argument
            android:name="code"
            app:argType="string" />

        <deepLink app:uri= "xyz.tech/api/confirm?userId={userId}&amp;code={code}" />

    </fragment>
</navigation>

【问题讨论】:

  • 不可能。到目前为止,Android 导航组件不支持该功能来解析字符串

标签: android android-gradle-plugin android-xml android-navigation-graph


【解决方案1】:

目前任何 XML 文件都不支持 Gradle 文件中的占位符,但根据 this comment

[此功能]目前预定 7.1

当该功能可用时,您希望为该问题加注星标以获取更新。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多