I'd like to declare an API version my test application uses to build it and also display it in the application.
So I declared the version like that in the project's build.gradle:
buildscript {
ext {
...
api_version = '0.2.9'
}
...
}
Then in my app's build gradle, I use it:
android {
....
buildTypes {
release {
...
buildConfigField "String", "api_version", "$api_version"
}
debug {
...
buildConfigField "String", "api_version", "$api_version"
}
}
}
dependencies {
....
implementation "com.example.service:my_api:$api_version"
}
And finally, I use it in my app:
supportActionBar?.title = """${getString(R.string.app_name)} $VERSION_NAME API:${BuildConfig.api_version}"""
But on build I get the following error in the generated BuildConfig.java
file:
public final class BuildConfig {
// Fields from build type: debug
public static final String api_version = 0.2.9;
}
The error is
......\BuildConfig.java
Error:(14, 54) error: ';' expected
I suppose BuildConfig.java should contain:
public static final String api_version = "0.2.9";
But I don't understand how to write it.