DeepLinkDispatch with different modules (libraries)
Asked Answered
T

0

1

I'm trying to add DeepLinkDispatch library (by airbnb) in my project in order to handle deeplinks. The project has different modules and some links needs to be handled by Activity's in this modules.

As I have different flavors I would like to define the url of deeplinks with BuildConfig in build.gradle, to be able to do something like this:

@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
}

But unfortunately I don't have access to BuildConfig from modules

I also tried to reproduce the flavors in Modules like this:

//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 {
    //...
}

but it seems this is not possible, I'm getting this error:

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

Is there any way to solve this without hardcoding the whole url in the @DeepLink annotation?

EDIT: this is the main app build.gradle

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

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

dependencies {
    implementation project(':module')
    //**
}
Trigraph answered 16/2, 2022 at 17:57 Comment(5)
Can you also add gradle for other modules like app module?Cohlier
ModuleActivity class is in which module? and have you implemented the library module in that module?Cohlier
Thanks @NareshNK for your interest. I edited the question to add app module gradle. ModuleActivity is in the library (:module) that's the problem, from this library I don't have access to main app BuildConfig and, as explained, I'm not able to create buildConfigField's in the library (:module)Trigraph
I was unable to figure out the issue with your code. I have created a repo on GitHub explaining how to use multi module buildConfigField variable share, that might help you achive your goal. Url : github.com/Noddy20/Multi-Module-Gradle-ConfigCohlier
thanks @NareshNK. I tried your test project and it's working. I don't see any difference, so I don't know what's happening in my side. I will try to start a new project from scratch to see what's happening.Trigraph

© 2022 - 2024 — McMap. All rights reserved.