---
title: "D8 Optimization: Assertions"
url: https://daily.dev/posts/d8-optimization-assertions-grxnxpqe6
source_url: https://jakewharton.com/d8-optimization-assertions
type: article
source: "Jake Wharton"
published: 2026-07-05T07:13:17.444Z
updated: 2026-07-05T07:13:40.877Z
tags: ["java", "android"]
reading_time: 5
upvotes: 0
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# D8 Optimization: Assertions

**[Jake Wharton](https://daily.dev/sources/jakewharton)** · 5 min read · 0 upvotes · 0 comments

## Summary

D8, Android's dexer, optimizes Java `assert` statements by eliminating them in release builds (since Android VMs never enable assertions) and retaining them in debug builds via the `--force-enable-assertions` flag introduced in AGP 4.1. In release builds, D8 replaces the assertions-enabled check with `false` and uses dead-code elimination to strip the entire assertion expression from bytecode. In debug builds, the check is replaced with `true`, keeping the invariant check active at runtime. This brings Android assertion behavior closer to the JVM model where tests run with `-ea` but production does not. Kotlin's `assert()` function is not yet handled by this optimization.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://jakewharton.com/d8-optimization-assertions>

## Similar posts on daily.dev

- [Enabling R8 optimization at scale with AI-assisted debugging](https://daily.dev/posts/enabling-r8-optimization-at-scale-with-ai-assisted-debugging-kovtjstfc) · Grab Tech Blog · 0 upvotes · 0 comments

---

Tags: [#java](https://daily.dev/tags/java), [#android](https://daily.dev/tags/android)

[View this post on daily.dev](https://daily.dev/posts/d8-optimization-assertions-grxnxpqe6)
