androidgradleandroid-gradle-pluginbuild.gradlegradle-kotlin-dsl

In Android gradle, implementation call to specify dependency for a new build type not defined


I want to specify a new build type (besides debug and release) in Android build.gradle.kts file. Build type is present (as one of the options in Android Studio build variant) but I cannot specify a dependency specifically for this build type. I am not defining any productFlavor or dimension as I do not need them.

I get this error Unresolved reference: stagingImplementation.

plugins {
    id("com.android.application")
    id("kotlin-android")
}

android {
    compileSdk = 33

    defaultConfig {
        applicationId = "com.example.myapp"
        minSdk = 21
        targetSdk = 33
        versionCode = 1
        versionName = "1.0"
    }

    buildTypes {
        debug {
            isDebuggable = true
        }
        release {
            isMinifyEnabled = true
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
        create("staging") {
            initWith(getByName("release"))
            isMinifyEnabled = false
            isDebuggable = true
        }
    }
}

dependencies {
    debugImplementation("com.squareup.leakcanary:leakcanary-android:2.9.1")
    releaseImplementation("com.example:release-library:1.0")
    stagingImplementation("com.example:qa-library:1.0") // <<-- Unresolved reference: stagingImplementation !!!
}

What am I missing? AGP version 8.5.2.


Solution

  • Assuming you are using kotlin as the language in your gradle file, the dependency should be as follows

    "stagingImplementation"("com.example:qa-library:1.0")