Gradle 中的 dex 是什么 [英] What is dex in Gradle

查看:26
本文介绍了Gradle 中的 dex 是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Gradle 或 Android 中的 dex 是什么?

What is the dex in Gradle or in Android?

在Gradle中,dexoptions是什么意思?

In Gradle, what's the meaning of dexoptions?

有时我的项目由于某些 dexerrors 而无法编译.我需要激活 ProGuard 来编译我的 Android 应用程序.

Sometimes my project does not compile because of some dexerrors. I need to activate ProGuard to compile my Android app.

推荐答案

在标准的java世界中:

当您编译标准 java 代码时:编译器生成 *.class 文件.*class 文件包含可以在标准 JVM 上执行的标准 java 字节码.

In the standard java world:

When you compile standard java code : the compiler produce *.class file. A *class file contains standard java bytecode that can be executed on a standard JVM.

这是不同的.您使用 java 语言编写代码,但编译器不生成 *.class 文件,它生成 *.dex 文件.*.dex 文件包含可以在 Android 虚拟机 (dalvik) 上执行的字节码,这不是标准的 Java 虚拟机.

It is different. You use the java language to write your code, but the compiler don't produce *.class files, it produce *.dex file. A *.dex file contains bytecode that can be executed on the Android Virtual Machine (dalvik) and this is not a standard Java Virtual Machine.

明确一点:android 中的 dex 文件相当于标准 java 中的 class.

To be clear: a dex file in android is the equivalent of class in standard java.

所以 dexoptions 是一个 gradle 对象,其中定义了一些配置此 java-code-to-android-bytecode 转换的选项.通过这个对象配置的选项是:

So dexoptions is a gradle object where some options to configure this java-code-to-android-bytecode transformation are defined. The options configured via this object are :

  • 目标API级别
  • force-jumbo 模式(启用后允许 dex 文件中包含更多字符串)

启用 jumboMode :

android {
    dexOptions {
        jumboMode = true
    }
}

这篇关于Gradle 中的 dex 是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆