为什么android在被d8替换后还保留dx?

问题描述

为什么 android 仍然保留 dx 及其更新的替代品 d8

$ cd cmdline-tools/build-tools/30.0.3 && ls d*
d8  dexdump  dx

这是我使用的程序:

$ cat 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,[                       |
 const/4 v,#int 0                       |
 invoke-static {v},|
 move-result-object v                    |
 aput-object v,v                     |
+const-string v,"%d "  <----------------+ 
 invoke-virtual {v,v},add-int/lit8 v,#int 1 
 goto 0001 

解决方法

https://android-developers.googleblog.com/2020/02/the-path-to-dx-deprecation.html 列出弃用计划。 由于去年发现的依赖关系,究竟将在哪个版本的 cmd 行工具中消失仍然有些悬而未决。