Search code examples
androidgradleandroid-gradle-plugingradle-kotlin-dsl

Custom build type dependency handler problem


I am trying to add a custom build type for Now In Android project.

I have added the build type like this:

buildTypes {
        debug {
            ...
        }
        release {
           ...
        }
        create("custom") {
            initWith(getByName("release"))
            matchingFallbacks.add("release")
            isDebuggable = true
            isMinifyEnabled = true
        }
    }

And then I want to use it's dependency handler like this:

dependencies {
    customImplementation("something")
    ...
}

but I am getting Unresolved reference: customImplementation after I try gradle sync. The project uses gradle version "8.5" and AGP "8.3.0".


Solution

  • Looks like a syntax issue.

    You appear to be using Kotlin DSL. When a configuration like customImplementation is created outside of a plugin (as you have), no type-safe accessor is generated1. So you need to access it either like:

    dependencies {
        "customImplementation"("something")
    }
    

    Or like:

    dependencies {
        add("customImplementation", "something")
    }
    

    1 Which makes sense because the compiler doesn't know about the definition until the file itself is executed. On the other hand, Groovy doesn't need defined functions in this case because its metaprogramming features are exploited by Gradle.