Dim
Dim

Reputation: 4837

Android build number

I need your help. I wish to add the build name of my app to the gradle file. The thing is I do NOT want it to be visible to user on the market, so this:

versionName "3.1.0.5486"

does not suits me. But I need it in a way so I can read it via code (In the about screen for example) and increment it each build. How can you advise me?

Upvotes: 0

Views: 210

Answers (1)

comrade
comrade

Reputation: 4710

Just use standard versionCode parameter. You can read it from code using

BuildConfig.VERSION_CODE.

You can set the version code and name inside the defaultConfig element in the build.gradle:

defaultConfig {
    versionCode 1
    versionName "1.0"
}

And use it as is:

String.format(getString(R.string.some_text_with_int_placeholder), BuildConfig.VERSION_CODE);

If you want create your own variable just use buildConfigField, something like:

 buildTypes {
        debug {
            buildConfigField "int", "FOO", "42"
            buildConfigField "String", "FOO_STRING", "\"foo\""
            buildConfigField "boolean", "LOG", "true"
        }
}

And access it via BuildConfig.FOO

Upvotes: 1

Related Questions