Skip to content

MMRLApp/DEXMO

Repository files navigation

Dexmo Gradle Plugin

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).


Requirements

Tool Minimum version
Java 11
Gradle 8.0
Kotlin (for Kotlin sources) 1.9 / 2.x

Setup

1. Publish the plugin to a local Maven repository

./gradlew publishToMavenLocal

2. Apply the plugin in your consumer project

settings.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"
}

Usage

Declaring dependencies to bundle

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: dexmoInclude resolves the full transitive closure. If you only want a specific JAR without transitives, set isTransitive = false on the configuration in your build script, or use dexmoInclude(…) { isTransitive = false }.

Configuring the plugin

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")
}

Running the task

./gradlew bundleDex

The DEX file(s) are written to the configured outputDir (default build/dex/).


How it works

Java/Kotlin sources
       │
       ▼
  compileJava / compileKotlin  (standard Gradle compile tasks)
       │
       ├─── .class files ──────────────────────┐
                                               ▼
dexmoInclude deps ──► resolved JARs ──► D8 (com.android.tools:r8)
                                               │
                                               ▼
                                        build/dex/classes.dex
  1. The plugin hooks into all compile* tasks (except test tasks) that are registered by Java/Kotlin plugins.
  2. Compiled .class files + dexmoInclude JARs are passed to D8 as program inputs.
  3. D8 converts them to Dalvik bytecode and writes DEX file(s) to outputDir.

Multi-DEX

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.


Published plugin coordinates

Property Value
Plugin ID dev.mmrl.dexmo
Group dev.mmrl.dexmo
Artifact dexmo
Version 1.0.0

License

MIT

About

A Gradle plugin that compiles Java and Kotlin source files and bundles them—together with any explicitly listed dependencies—into a DEX

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages