简体   繁体   中英

What's the file path of d8.jar used by Android Studio?

I know that Android Studio switch to D8 dexer by default . But I wonder what's the file path of d8.jar ? I can't found d8.jar in SDK like dx.jar .

A typical dx.jar located in Android/Sdk/build-tools/<VERSION>/lib/ :

xb@dnxb:~/Android/Sdk/build-tools/27.0.3/lib$ ls
apksigner.jar  dx.jar  shrinkedAndroid.jar
xb@dnxb:~/Android/Sdk/build-tools/27.0.3/lib$ 

My first thought is dx.jar means d8.jar, but seems like not the case.

The old dx.jar source code :

xb@dnxb:~/Downloads/dalvik/dx/src/com/android$ ls 
dex  dx  multidex
xb@dnxb:~/Downloads/dalvik/dx/src/com/android$ ls -1 dex
Annotation.java
CallSiteId.java
ClassData.java
ClassDef.java
Code.java
DexException.java
DexFormat.java
DexIndexOverflowException.java
Dex.java
EncodedValueCodec.java
EncodedValue.java
EncodedValueReader.java
FieldId.java
Leb128.java
MethodHandle.java
MethodId.java
Mutf8.java
ProtoId.java
SizeOf.java
TableOfContents.java
TypeList.java
util
xb@dnxb:~/Downloads/dalvik/dx/src/com/android$ 

Is exactly the same as the .classes of dx.jar in 27.0.3 or older(eg 25.0.0) SDK (I unzip it):

xb@dnxb:~/Android/Sdk/build-tools/27.0.3/lib/dx/com/android$ ls 
dex  dx  multidex
xb@dnxb:~/Android/Sdk/build-tools/27.0.3/lib/dx/com/android$ ls -1 dex | grep -v '\$'
Annotation.class
CallSiteId.class
ClassData.class
ClassDef.class
Code.class
Dex.class
DexException.class
DexFormat.class
DexIndexOverflowException.class
EncodedValue.class
EncodedValueCodec.class
EncodedValueReader.class
FieldId.class
Leb128.class
MethodHandle.class
MethodId.class
Mutf8.class
ProtoId.class
SizeOf.class
TableOfContents.class
TypeList.class
util
xb@dnxb:~/Android/Sdk/build-tools/27.0.3/lib/dx/com/android$ 

But the new d8.jar has totally difference structure:

xb@dnxb:~/Downloads/r8/build/libs/d8/com/android/tools/r8$ ls
annotations                                           ExtractMarkerCommand.class                                                                      
ApiLevelException.class                               ExtractMarker$VdexOrigin.class                                                                  
ArchiveClassFileProvider.class                        GenerateMainDexList.class
ArchiveProgramResourceProvider.class                  GenerateMainDexListCommand$1.class
ArchiveProgramResourceProvider$ZipFileSupplier.class  GenerateMainDexListCommand$Builder.class
BaseCommand$Builder.class                             GenerateMainDexListCommand.class
BaseCommand.class                                     graph
BaseCompilerCommand$Builder.class                     InternalProgramOutputPathConsumer.class
... omit

And I search filename with d8 keyword in both sdk and Android Studio, but no luck:

xb@dnxb:~$ find /home/xiaobai/Android/ -iname '*d8*'
xb@dnxb:~$ find ~/Downloads/AS/android-studio -iname '*d8*'
xb@dnxb:~$ 

So where's the file path of d8.jar in Android Studio ? My Android Studio version is 3.2 Canary 12 already, but how Android Studio invoke d8 by default if d8.jar not exist ? Or it hide in somewhere ?

D8/R8 wasn't distributed as a part of the Android SDK like dx prior to build-tools 28.0.1. In recent versions there is build-tools/28.0.1/d8 and build-tools/28.0.1/lib/d8.jar .

It is also shipped as a part of the Android Gradle plugin. As of 3.1.x/3.2-alpha, D8 classes (and their repackaged dependencies) are bundled into com.android.tools.build:builder artifact. The latter is a transitive dependency of the primary gradle plugin's artifact. So the Gradle plugin (and therefore Android Studio) uses bundled d8 classes to dex code.

There is a separate artifact com.android.tools:r8 that is a separate R8 jar (without dependencies, as of version 1.0.25) but the Android Gradle plugin doesn't depend on it.

After a default installation of Android Studio I just made, I have a d8.jar here (size 4 MB):

~/Android/Sdk/build-tools/29.0.3/lib/d8.jar

To invoke it BTW, you need to run

java -cp d8.jar com.android.tools.r8.D8 ...

D8 is part of the new R8 project . D8 does not share any history with dx - even though the naming might make it seem that way. dx is no longer actively being developed, but D8 is actively developed by Google as an open source project at https://r8-review.googlesource.com .

You should be able to find r8.jar (not d8.jar - that doesn't exist) in your classpath, and if you want to use a different version of D8, you can put your own r8.jar on your classpath.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM