File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -114,12 +114,22 @@ dependencies {
114114 androidTestImplementation(libs.androidx.espresso.core)
115115}
116116/* *
117- * Computes the version code based on the current system time in minutes since epoch .
117+ * Computes the version code based on the number of git commits on the current branch .
118118 *
119- * This is typically a not a good idea, but it's done so that we always get a unique
120- * version code for every build so that every time we record data from sample app,
121- * it shows up as a separate version on the dashboard.
119+ * This ensures a unique, monotonically increasing version code for each commit so that
120+ * every time we record data from the sample app, it shows up as a separate version on
121+ * the dashboard.
122122 */
123123fun computeVersionCode (): Int {
124- return (System .currentTimeMillis() / (1000 * 60 )).toInt()
124+ val process = ProcessBuilder (" git" , " rev-list" , " --count" , " HEAD" )
125+ .directory(project.rootDir)
126+ .redirectErrorStream(true )
127+ .start()
128+ val output = process.inputStream.bufferedReader().readText().trim()
129+ val exitCode = process.waitFor()
130+ if (exitCode != 0 ) {
131+ logger.warn(" Failed to compute version code from git, falling back to 1" )
132+ return 1
133+ }
134+ return output.toIntOrNull() ? : 1
125135}
You can’t perform that action at this time.
0 commit comments