0

我正在尝试在我的项目中添加DeepLinkDispatch库(由 airbnb 提供)以处理深度链接。该项目有不同的模块,一些链接需要由Activity该模块中的 's 处理。

由于我有不同的风格,我想用 BuildConfig in 定义深层链接的 url build.gradle,以便能够执行以下操作:

@DeepLink("${BuildConfig. WEB_BASE_URL}/deepLink/{id}", "${BuildConfig. WEB_BASE_URL}/anotherDeepLink")
class ModuleActivity : AppCompatActivity() {
   // This class is in :module, so it has no access to BuildConfig main :app module
}

但不幸的是,我无法从模块访问 BuildConfig

我还尝试在这样的模块中重现风味:

//module build.gradle
plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
    id 'kotlin-kapt'
}
apply plugin: 'dagger.hilt.android.plugin'

apply from: rootProject.file("buildscripts/android-defaults.gradle")

import dependencies.deps

android {
    defaultPublishConfig "alphaRelease"
    publishNonDefault true

    defaultConfig {

    }
    flavorDimensions "env"
    productFlavors {
        alpha {
            buildConfigField "String", "WEB_BASE_URL", "\"https://staging.example.com\""
            dimension "env"
        }
        production {
            buildConfigField "String", "WEB_BASE_URL", "\"https://example.com\""
            dimension "env"
        }
    }
}
dependencies {
    //...
}

但似乎这是不可能的,我收到了这个错误:

Product Flavor 'alpha' contains custom BuildConfig fields, but the feature is disabled.

有什么方法可以解决这个问题,而无需在@DeepLink注释中对整个 url 进行硬编码?

编辑:这是主要的应用程序build.gradle

apply plugin: 'com.android.application'
//**

android {
    defaultConfig {
        //**
    }
    
    productFlavors {
        alpha {
            applicationIdSuffix '.alpha'
        }
        production {
            applicationIdSuffix '.prod'
        }
    }
    //**
}

dependencies {
    implementation project(':module')
    //**
}
4

0 回答 0