Vivek Modi
04/19/2025, 12:47 PMbuild.gradle.kts
file.Vivek Modi
04/19/2025, 12:49 PMclass AndroidNamespaceConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
plugins.withId("com.android.library") {
configureNamespace()
}
plugins.withId("com.android.application") {
configureNamespace()
}
}
}
private fun Project.configureNamespace() {
val basePackage = "com.hub.vivek"
val modulePath = project.path
val namespaceSuffix = modulePath
.split(":")
.filter { it.isNotBlank() }
.joinToString(".")
val fullNamespace = "$basePackage.$namespaceSuffix"
extensions.configure<com.android.build.gradle.BaseExtension> {
namespace = fullNamespace
}
}
}
In build-logic/build.gradle.kts:
plugins {
`kotlin-dsl`
}
group = "com.hub.vivek.buildlogic"
java {
sourceCompatibility = JavaVersion.toVersion(libs.versions.jvmTarget.get())
targetCompatibility = JavaVersion.toVersion(libs.versions.jvmTarget.get())
}
kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.valueOf("JVM_${libs.versions.jvmTarget.get()}"))
}
}
dependencies {
compileOnly(libs.compose.gradlePlugin)
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.kotlin.gradlePlugin)
}
gradlePlugin {
plugins {
register("androidNameSpace") {
id = libs.plugins.vivek.android.namespace.get().pluginId
implementationClass = "AndroidNamespaceConventionPlugin"
}
}
}
In libs.versions.toml:
[plugins]
vivek-android-namespace = { id = "vivek.android.namespace" }
And in feature/auth/build.gradle.kts:
plugins {
alias(libs.plugins.vivek.android.namespace)
// other plugins
}
Now the problem: when I try to access the generated R
class in the feature:auth
module like this:
import com.hub.vivek.feature.auth.R
val name = R.string.name
Vivek Modi
04/19/2025, 12:49 PMUnresolved reference: R
Vivek Modi
04/19/2025, 12:50 PMVivek Modi
04/19/2025, 12:51 PMChrimaeon
04/19/2025, 2:03 PMChrimaeon
04/19/2025, 2:05 PM