[TIMOB-27574] Android: Replace SDK "build.properties" with gradle generated "BuildConfig" class
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2020-04-10T21:54:49.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 9.0.1 |
Components | Android |
Labels | android, build, gradle, properties, sdk |
Reporter | Joshua Quick |
Assignee | Joshua Quick |
Created | 2019-11-13T01:35:09.000+0000 |
Updated | 2020-04-10T21:54:49.000+0000 |
Description
*Summary:*
When building the Titanium SDK, we generate a "build.properties" file (similar to an
INI
file) providing the Titanium library's version and build time information. This file is stored under APK "assets" and is read on app startup via the Java method below.
[TiApplication.loadBuildProperties()](https://github.com/appcelerator/titanium_mobile/blob/5fbe78276e04049874e13bcc0a3874593f27254e/android/titanium/src/java/org/appcelerator/titanium/TiApplication.java#L300)
By default, gradle generates a BuildConfig
Java class for all libraries and apps. We should use this feature instead of generating our own "build.properties" file. It will simplify our build process... and access to this info at runtime will be faster.
https://developer.android.com/studio/build/gradle-tips#share-custom-fields-and-resource-values-with-your-app-code
*Example:*
// The "build.gradle" file.
android {
defaultConfig {
buildConfigField('String', 'BUILD_VERSION', '"9.x.x"')
buildConfigField('String', 'BUILD_TIMESTAMP', '"YYYY/MM/DD HH:MM"')
buildConfigField('String', 'BUILD_GIT_HASH', '"HEAD"')
}
}
*Note:*
This information is logged on app startup as...
<AppName> <AppVersion> (Powered by Titanium <Version>.<GitHash>)
The above message gets logged in the code below...
[ti.main.js#L15](https://github.com/appcelerator/titanium_mobile/blob/5fbe78276e04049874e13bcc0a3874593f27254e/common/Resources/ti.main.js#L15)
After upgrading gradle via [TIMOB-27778], the current "master" and "9_0_X" branches are no longer picking up the generated "build.properties" file on the initial build. This means that Jenkins built SDKs for Android will return version "1.0.0". This can be seen in app builds, such as via Jenkin's mocha unit test output. This issue can be corrected with this ticket's proposed changes. This issue was caught before release.
PR (master): https://github.com/appcelerator/titanium_mobile/pull/11605 PR (9.0.x): https://github.com/appcelerator/titanium_mobile/pull/11606
FR Passed. PR's Merged.
Verified on: Mac OS: 10.15.4 SDK: 9.0.1.v20200409100807, 9.1.0.v20200409073825 Appc CLI: 8.0.0 JDK: 11.0.4 Node: 10.17.0 Studio: 6.0.0.202003132109 Device: Pixel3(v10.0) emulator,