Subject: bug#75809: Hard-coded version code is unsuitable for automated F-Droid Android package builds

From: Peter Oliver <[email-masked]>
Date: Mon, 27 Jan 2025 11:13:12 +0000 (GMT)

Further to the discussion on emacs-devel, here is an updated patch.

-- 
Peter Oliver

From 4ddb22f992df81b39a1286064e4a2ececdc2190c Mon Sep 17 00:00:00 2001
From: Peter Oliver <[email-masked]>
Date: Mon, 27 Jan 2025 10:59:19 +0000
Subject: [PATCH 2/2] Provide an Android version code derived from the Emacs
 version

The version code is intended to be an integer that increments for each
Android package release
(https://developer.android.com/studio/publish/versioning#versioningsettings).

If we keep this updated under version control, then F-Droid (a
third-party Android package repository), can watch for that, and use it
to automatically build Emacs packages for Android each time a new Emacs
release is tagged
(https://f-droid.org/en/docs/Build_Metadata_Reference/#UpdateCheckData).

* admin/admin.el (set-version): Update version code in
java/incrementing-version-code
* java/incrementing-version-code: New file containing an Android version
code corresponding to the current Emacs version.
---
 admin/admin.el                 |  7 +++++++
 java/incrementing-version-code | 12 ++++++++++++
 2 files changed, 19 insertions(+)
 create mode 100644 java/incrementing-version-code

diff --git a/admin/admin.el b/admin/admin.el
index d98b8243f25..58d4245b173 100644
--- a/admin/admin.el
+++ b/admin/admin.el
@@ -116,6 +116,13 @@ set-version
 		       (rx (and "AC_INIT" (1+ (not (in ?,)))
                                 ?, (0+ space) ?\[
                                 (submatch (1+ (in "0-9."))))))
+  (set-version-in-file root "java/incrementing-version-code"
+                       (apply #'format "%02d%02d%02d000"
+                              (mapcar #'string-to-number
+                                      (split-string version "\\.")))
+                       (rx (and line-start
+                                (submatch (1+ (in digit)))
+                                line-end)))
   (set-version-in-file root "nt/README.W32" version
 		       (rx (and "version" (1+ space)
 				(submatch (1+ (in "0-9."))))))
diff --git a/java/incrementing-version-code b/java/incrementing-version-code
new file mode 100644
index 00000000000..fed5b627275
--- /dev/null
+++ b/java/incrementing-version-code
@@ -0,0 +1,12 @@
+; This file contains an Android version code
+; (https://developer.android.com/studio/publish/versioning#versioningsettings)
+; corresponding to the current Emacs version.
+;
+; The version code in AndroidManifest.xml.in is hard-coded to a fixed
+; value, to make package downgrades possible.  Where an incrementing
+; version code is required (for example, for automated F-Droid package
+; builds (https://f-droid.org/packages/org.gnu.emacs/)), the version
+; code in this file should be referred to and patched in to
+; AndroidManifest.xml.
+
+300093000
-- 
2.48.1