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

From: [email-masked] (GNU bug Tracking System)
Date: Wed, 05 Mar 2025 07:01:02 +0000

Your bug report

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

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
75809: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=75809
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#75809: Hard-coded version code is unsuitable for automated F-Droid Android package builds
From: Po Lu <[email-masked]>
To: Stefan Kangas <[email-masked]>
Cc: Peter Oliver <[email-masked]>, [email-masked]
Date: Wed, 05 Mar 2025 14:59:58 +0800
List-Id: <debbugs-submit.debbugs.gnu.org>

Stefan Kangas <[email-masked]> writes:

> Peter Oliver <[email-masked]> writes:
>
>> On Thu, 20 Feb 2025, Stefan Kangas wrote:
>>
>>> Po Lu <[email-masked]> writes:
>>>
>>>> Peter Oliver <[email-masked]> writes:
>>>>
>>>>> Further to the discussion on emacs-devel, here is an updated patch.
>>>>
>>>> My apologies for having overlooked this for so long.  Is there any
>>>> chance the file name could be shorter?  Or even a comment in
>>>> java/AndroidManifest.xml-in?
>>>
>>> Peter, what are your thought on the above?
>>
>> Anything that can be matched with a regular expression is fine, so a comment
>> would work.  Creating a new file for this purpose seems neater and potentially
>> less fragile to me, but I’m happy to do whatever you think best.
>>
>>> If it can't be put in a comment, instead of "incrementing-version-code",
>>> how about "android-version"?
>>
>> We can call the file whatever we think makes most sense.  We just have to update
>> the patch we send to F-Droid
>> (https://gitlab.com/fdroid/fdroiddata/-/merge_requests/19018/diffs) to contain
>> whatever filename we choose.
>
> Po Lu, could you please install Peter's patch amended to use the file
> and/or comment that you think is suitable here?  Thanks in advance.

Now done.

Closing, and please notify the F-Droid packagers of the fact.

Subject: Hard-coded version code is unsuitable for automated F-Droid Android package builds
From: Peter Oliver <[email-masked]>
To: [email-masked]
Cc: Po Lu <[email-masked]>
Date: Fri, 24 Jan 2025 17:13:10 +0000 (GMT)
List-Id: <debbugs-submit.debbugs.gnu.org>

On Sun, 19 Jan 2025, Peter Oliver wrote:

> I notice that F-Droid is able to automatically build packages when a new Git 
> tag is made.  However, in order to do that, it needs to be given an integer 
> version number (called a version code; 
> https://developer.android.com/studio/publish/versioning#versioningsettings). 
> It can look for that either in the name of a Git tag, by searching in a file 
> within Git, or by fetching some data over HTTP 
> (https://f-droid.org/en/docs/Build_Metadata_Reference/#UpdateCheckData).
>
> Currently, this is hard-coded to 30 in java/AndroidManifest.xml.in, but 
> something like 300093000 would be needed (for 30.0.93).  Could we set that 
> for them?

Attached are two patches addressing this.

-- 
Peter Oliver

From 7002fdc6c64ccaf1a5cb2e8cb8ac698a74ea1b55 Mon Sep 17 00:00:00 2001
From: Peter Oliver <[email-masked]>
Date: Fri, 24 Jan 2025 16:43:34 +0000
Subject: [PATCH 1/2] Note that .apk packages for Android can be installed with
 adb

* java/INSTALL: Suggest the `adb install' command for installing Android
packages.
---
 java/INSTALL | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/java/INSTALL b/java/INSTALL
index 24f5e0c2ad8..d1ac29525dd 100644
--- a/java/INSTALL
+++ b/java/INSTALL
@@ -67,6 +67,10 @@ built for.
 The generated package can be uploaded onto an SD card (or similar
 medium) and installed on-device.
 
+Alternatively, the package can be uploaded to and installed on a device
+in debug mode using the `adb install' command
+(https://developer.android.com/tools/adb).
+
 
 LOCATING NECESSARY FILES
 
-- 
2.48.1

From a4fa082ab9de4265518c337ae1ea0b16b0342850 Mon Sep 17 00:00:00 2001
From: Peter Oliver <[email-masked]>
Date: Fri, 24 Jan 2025 17:05:09 +0000
Subject: [PATCH 2/2] Set android:versionCode as an integer 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 versionCode in
java/AndroidManifest.xml.in.
* java/AndroidManifest.xml.in: Bump versionCode to 300093000.
* java/INSTALL: Note that Android packages can be downgraded with the
`adb install -d' command.
---
 admin/admin.el              | 7 +++++++
 java/AndroidManifest.xml.in | 8 ++------
 java/INSTALL                | 3 ++-
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/admin/admin.el b/admin/admin.el
index d98b8243f25..57335f95d3a 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/AndroidManifest.xml.in"
+                       (apply #'format "%02d%02d%02d000"
+                              (mapcar #'string-to-number
+                                      (split-string version "\\.")))
+		       (rx (and "android:versionCode=\""
+                                (submatch (1+ (in digit)))
+                                "\"")))
   (set-version-in-file root "nt/README.W32" version
 		       (rx (and "version" (1+ space)
 				(submatch (1+ (in "0-9."))))))
diff --git a/java/AndroidManifest.xml.in b/java/AndroidManifest.xml.in
index 6243c5e13ba..e4874b5209b 100644
--- a/java/AndroidManifest.xml.in
+++ b/java/AndroidManifest.xml.in
@@ -18,11 +18,7 @@ You should have received a copy of the GNU General Public License
 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>. -->
 
 <!-- targetSandboxVersion must be 1, for otherwise fascist security
-     restrictions prevent Emacs from making HTTP connections.
-
-     Furthermore, versionCode should remain constant, rather than increase
-     with each major release, because it is impossible to downgrade an
-     installation with a greater value to an older version of Emacs.  -->
+     restrictions prevent Emacs from making HTTP connections. -->
 
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 	  package="org.gnu.emacs"
@@ -33,7 +29,7 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>. -->
 	  android:appCategory="productivity"
 	  @ANDROID_SHARED_USER_ID@
 	  @ANDROID_SHARED_USER_NAME@
-	  android:versionCode="30"
+	  android:versionCode="300093000"
 	  android:versionName="@version@">
 
   <!-- Paste in every permission in existence so Emacs can do
diff --git a/java/INSTALL b/java/INSTALL
index d1ac29525dd..f0015bd230b 100644
--- a/java/INSTALL
+++ b/java/INSTALL
@@ -69,7 +69,8 @@ medium) and installed on-device.
 
 Alternatively, the package can be uploaded to and installed on a device
 in debug mode using the `adb install' command
-(https://developer.android.com/tools/adb).
+(https://developer.android.com/tools/adb).  Use `adb install -d' if you
+wish to downgrade to an earlier package version.
 
 
 LOCATING NECESSARY FILES
-- 
2.48.1