Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use applicationId outside defaultConfig in gradle?

This is possibly a silly quiestion, but I want to have a debug and release versions of app working at the same time on device.

The problem I had is a content resolver authority. So I did the usual applicationId jazz, but now i want to avoid having code like this

public static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".provider";

laying around, so I figured I would do a BuildConfigField for CONTENT_AUTHORITY which would do the concat in buildfile already like this

buildTypes {
    debug {
        applicationIdSuffix ".debug"
        BuildConfigField "String", "CONTENT_AUTHORITY", "\"${applicationId}.provider\"")
    }
    release {
        ....
    }
}

But it doesnt work, gradle/groovy syntax is confusing for me, help please?

Error:(32, 0) Could not find property 'applicationId' on BuildType_Decorated{name=debug, debuggable=true, testCoverageEnabled=false, jniDebuggable=false, pseudoLocalesEnabled=false, renderscriptDebuggable=false, renderscriptOptimLevel=3, applicationIdSuffix=.debug, versionNameSuffix=null, minifyEnabled=false, zipAlignEnabled=true,...

like image 988
urSus Avatar asked Nov 24 '25 08:11

urSus


1 Answers

Try accessing it as

defaultConfig.applicationId

Instead of just

applicationId

Should get you the value.

like image 189
AndroidMechanic - Viral Patel Avatar answered Nov 27 '25 00:11

AndroidMechanic - Viral Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!