为什么 Android 将 DX 替换为 D8 后仍保留 DX?

Why does Android keep DX when it was replaced by D8?

为什么 Android 仍然保留 DX 及其更新的替代品 D8?

cd cmdline-tools/build-tools/30.0.3 && ls d*

结果:

d8  dexdump  dx

这是我使用的程序(文件Primes.java):

class Primes {

    private static boolean isPrime(int p)
    {
        for (int i=2; i<p; i++) {
            for (int j=2; j<p; j++) {
                if (i*j == p) {
                    return false;
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {
        for (int i=2; i<100; i++) {
            if (isPrime(i)) {
                System.out.format("%d ", i);
            }
        }
    }
}

下面是我如何将它编译成 .dex 文件:

javac Primes.java

结果:

cmdline-tools/build-tools/30.0.3/dx --dex --output dx/classes.dex Primes.class
cmdline-tools/build-tools/30.0.3/d8       --output d8             Primes.class
cmdline-tools/build-tools/30.0.3/dexdump -d dx/classes.dex > dx.human
cmdline-tools/build-tools/30.0.3/dexdump -d d8/classes.dex > d8.human

然后我清理地址,注册名和评论以便能够比较:

cat dx.human | awk "/\'main\'/,/catches/" | sed "s/.*|[0-9a-f]*: //g" | sed "s/\/\/.*//g" | sed "s/Ljava.*//g" | sed "s/v[0-9]/v/g" | sed "s/v[0-9]/v/g" > dx.main.human
cat d8.human | awk "/\'main\'/,/catches/" | sed "s/.*|[0-9a-f]*: //g" | sed "s/\/\/.*//g" | sed "s/Ljava.*//g" | sed "s/v[0-9]/v/g" | sed "s/v[0-9]/v/g" > d8.main.human

它们几乎相同,但不完全相同:

$ diff -u dx.main.human d8.main.human
--- dx.main.human    2021-04-12 19:49:37.110476376 +0300
+++ d8.main.human    2021-04-12 19:49:44.650101698 +0300
@@ -2,11 +2,11 @@
...
-      registers     : 7
+      registers     : 5
...
 const/4 v, #int 2
 const/16 v, #int 100
 if-ge v, v, 001f
@@ -14,13 +14,13 @@
 move-result v
 if-eqz v, 001c
 sget-object v,
-const-string v, "%d "  <----------------+
 const/4 v, #int 1                       |
 new-array v, v, [                       |
 const/4 v, #int 0                       |
 invoke-static {v},                      |
 move-result-object v                    |
 aput-object v, v, v                     |
+const-string v, "%d "  <----------------+
 invoke-virtual {v, v, v},
 add-int/lit8 v, v, #int 1
 goto 0001

The path to DX deprecation 列出弃用计划。

由于去年发现了依赖项,因此究竟将在哪个版本的命令行工具中消失仍然是​​一个悬而未决的问题。