]> git.eshelyaron.com Git - emacs.git/commitdiff
Optimize generated Android DEX bytecode
authorPo Lu <luangruo@yahoo.com>
Wed, 10 Apr 2024 14:33:08 +0000 (22:33 +0800)
committerEshel Yaron <me@eshelyaron.com>
Wed, 10 Apr 2024 20:30:52 +0000 (22:30 +0200)
* configure.ac (D8): Attempt to locate the bundle where d8 is
installed, detect whether an installation of `r8' is similarly
present, and use this installation in place of d8 if so.

* java/Makefile.in (ANDROID_MIN_SDK, IS_D8_R8): New
substitutions.
(classes.dex): Provide --min-api, --debug or --release and
--pg-conf to d8 or r8.

(cherry picked from commit ed88bed3afbc9922f020cf3a8803e08f2811e89b)

configure.ac
java/Makefile.in

index b0b454eda44756a7cdac7d3c7f318a9fa88a31d6..de858a9f8ce10412f995ae7b56f0f1775d1f311d 100644 (file)
@@ -856,6 +856,7 @@ ANDROID_ABI=
 WARN_JAVAFLAGS=
 ANDROID_SHARED_USER_ID=
 ANDROID_SHARED_USER_NAME=
+IS_D8_R8=
 
 # This is a list of Makefiles that have alternative versions for
 # Android.
@@ -1023,6 +1024,21 @@ Please verify that the path to the SDK build tools you specified is correct])
 Please verify that the path to the SDK build tools you specified is correct])
   fi
 
+  # Locate any d8.jar within the SDK build tools directory.  The R8
+  # optimizing compiler is also present in this bundle, and it generates
+  # far superior code.
+  emacs_val=`which $D8`
+  emacs_val=`AS_DIRNAME([$emacs_val])`/lib/d8.jar
+  AS_IF([test -f "$emacs_val"],
+    [AC_CACHE_CHECK([whether d8.jar coresident with d8 binary provides r8],
+       [emacs_cv_d8_provides_r8],
+       [AS_IF([java -cp "$emacs_val" com.android.tools.r8.R8 --help &>/dev/null],
+         [emacs_cv_d8_provides_r8=yes], [emacs_cv_d8_provides_r8=no])])])
+  AS_IF([test "$emacs_cv_d8_provides_r8" = "yes"],
+    # And substitute it for D8 if present.
+    [D8="java -cp $emacs_val com.android.tools.r8.R8"
+     IS_D8_R8=yes])
+
   AC_PATH_PROGS([ZIPALIGN], [zipalign], [], "${SDK_BUILD_TOOLS}:$PATH")
   if test "ZIPALIGN" = ""; then
     AC_MSG_ERROR([The Android ZIP archive alignment utility was not found.
@@ -1281,6 +1297,7 @@ AC_SUBST([D8])
 AC_SUBST([ZIPALIGN])
 AC_SUBST([ANDROID_JAR])
 AC_SUBST([ANDROID_ABI])
+AC_SUBST([IS_D8_R8])
 
 if test "$XCONFIGURE" = "android"; then
   ANDROID=yes
index c23b52ed44e5410f0d6753e565a89c97f8301e5b..daa577467c192c94b4cc6a57d02d60cff4edf030 100644 (file)
@@ -98,6 +98,12 @@ JAVA_FILES := $(filter-out $(RESOURCE_FILE),$(JAVA_FILES))
 ANDROID_MIN_SDK := @ANDROID_MIN_SDK@
 APK_NAME := emacs-$(version)-$(ANDROID_MIN_SDK)-$(ANDROID_ABI).apk
 
+# Whether or not the bundle is to be debuggable.
+ANDROID_DEBUGGABLE := @ANDROID_DEBUGGABLE@
+
+# Whether or not $(D8) is in fact the name of the `r8' optimizer binary.
+IS_D8_R8 := @IS_D8_R8@
+
 # How this stuff works.
 
 # emacs.apk depends on emacs.apk-in, which is simply a ZIP archive
@@ -299,10 +305,14 @@ $(CLASS_FILES) &: $(JAVA_FILES)
 # N.B. that find must be called all over again in case javac generated
 # nested classes.
 
-classes.dex: $(CLASS_FILES)
+classes.dex: $(CLASS_FILES) $(if $(IS_D8_R8), proguard.conf)
        $(AM_V_D8) $(D8) --classpath $(ANDROID_JAR)             \
          $(subst $$,\$$,$(shell find $(srcdir) -type f         \
-           -name *.class)) --output $(builddir)
+           -name *.class)) --output $(builddir)                \
+         --min-api $(ANDROID_MIN_SDK)                          \
+         $(if $(filter false,$(ANDROID_DEBUGGABLE)),--release, \
+                --debug) \
+         $(if $(IS_D8_R8),--pg-conf proguard.conf)
 
 # When emacs.keystore expires, regenerate it with:
 #