dsdsdsdsd
dsdsdsdsd

Reputation: 2962

How to properly add property to build.gradle to access from java?

I am trying to add a property to build.gradle (so that I can access it from MyActivity.java).

As per SO question this is what I have done:

// ...
buildTypes{ 
    debug {
            debuggable true
            buildConfigField "String"  , "pvs_debuggable", "truez"
          }
// ...

When I do this, a 'Sync Now' option appears, which I select.

But when I select it, BuildConfig.java is automatically opened, and with a warning: Files under the build folder are generated and should not be edited (other similar SO questions do not address my situation as far as I can tell).

Also, two lines of code have been automatically added to BuildConfig.java:

  // Fields from build type: debug
  public static final String pvs_debuggable = truez;

Please notice how truez has no quotes around it even though it is a string (I added the 'z' to ensure that AS wasn't trying to cast 'true' to true).

Also I should mention that the tab for this file has a red squiggly line beneath the name BuildConfig.java indicating a problem. And I am unable to run or debug the app.

So what am I missing?

Upvotes: 2

Views: 1193

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363419

You have to change your build.gradle in this way:

buildTypes{
 debug { 
        debuggable true
        buildConfigField "String"  , "pvs_debuggable", "\"truez\""
    }
}

Upvotes: 3

Related Questions