A Gradle plugin that compiles Java and Kotlin source files and bundles them—together with any explicitly listed dependencies—into a DEX file using D8 (Android's modern DEX compiler).
| Tool | Minimum version |
|---|---|
| Java | 11 |
| Gradle | 8.0 |
| Kotlin (for Kotlin sources) | 1.9 / 2.x |
./gradlew publishToMavenLocalsettings.gradle.kts
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
google()
mavenCentral()
}
}build.gradle.kts
plugins {
id("com.android.library") version "8.3.0" // or com.android.application
kotlin("android") version "2.0.0"
id("dev.mmrl.dexmo") version "1.0.0"
}The plugin registers a dexmoInclude configuration. Any dependency added to it (including its transitive dependencies) will be resolved to JARs and included in the DEX output.
dependencies {
// Regular project dependencies (compiled against but NOT bundled automatically)
implementation("com.squareup.okhttp3:okhttp:4.12.0")
// These will be DEX-bundled
dexmoInclude("com.google.code.gson:gson:2.10.1")
dexmoInclude("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
}Note:
dexmoIncluderesolves the full transitive closure. If you only want a specific JAR without transitives, setisTransitive = falseon the configuration in your build script, or usedexmoInclude(…) { isTransitive = false }.
dexmo {
// Output directory (default: build/dex)
outputDir.set(layout.buildDirectory.dir("dex"))
// Primary DEX file name. Only effective when D8 produces a single DEX file.
// For multi-dex output the files keep their default names (classes.dex, classes2.dex, …)
outputFileName.set("classes.dex")
// Minimum Android API level to target (affects desugaring). Default: 21
minApiLevel.set(21)
// Release mode enables D8 optimisations and strips debug info. Default: false
release.set(false)
// Provide android.jar when your code references Android framework APIs.
// Without this, D8 may emit warnings for unresolved library references.
bootClasspath.from("/path/to/android-sdk/platforms/android-34/android.jar")
}./gradlew bundleDexThe DEX file(s) are written to the configured outputDir (default build/dex/).
Java/Kotlin sources
│
▼
compileJava / compileKotlin (standard Gradle compile tasks)
│
├─── .class files ──────────────────────┐
▼
dexmoInclude deps ──► resolved JARs ──► D8 (com.android.tools:r8)
│
▼
build/dex/classes.dex
- The plugin hooks into all
compile*tasks (except test tasks) that are registered by Java/Kotlin plugins. - Compiled
.classfiles +dexmoIncludeJARs are passed to D8 as program inputs. - D8 converts them to Dalvik bytecode and writes DEX file(s) to
outputDir.
When the combined number of methods exceeds the 64k DEX limit, D8 automatically
emits multiple files: classes.dex, classes2.dex, etc. The outputFileName
setting is ignored in this case to preserve all files.
| Property | Value |
|---|---|
| Plugin ID | dev.mmrl.dexmo |
| Group | dev.mmrl.dexmo |
| Artifact | dexmo |
| Version | 1.0.0 |