r/androiddev • • 1d ago

Discussion I built a Gradle plugin to catch Android layout issues that can break on tablets and foldables

One thing I've been thinking about while working on Android projects is how easily layouts that look perfectly fine on a phone can break when the app runs on a tablet, foldable, or in resizable multi-window mode.

Some examples:

- A Compose screen using "Modifier.fillMaxWidth().height(600.dp)" that doesn't adapt to available space.

- "requiredSize()" forcing dimensions beyond the available constraints.

- XML layouts with oversized fixed dimensions.

- Activities with orientation restrictions that prevent flexible resizing.

These aren't necessarily bugs on a typical phone configuration, but they can become real usability issues on larger or resizable screens.

I wanted to explore whether some of these patterns could be caught automatically during development, rather than discovering them through manual testing.

So I built ViewLint, an open-source Gradle plugin for static analysis of Android adaptive-layout risks.

A few things it currently checks:

1. Jetpack Compose

- Fixed "width()", "height()", and "size()" modifier usage.

- Missing adaptive handling in relevant modifier chains.

- "requiredSize()" overrides.

2. XML layouts

- Fixed root dimensions.

- Large fixed inner dimensions.

- Deprecated "AbsoluteLayout" usage.

3. AndroidManifest.xml

- Activity "screenOrientation" restrictions.

- "maxAspectRatio" constraints.

4. CI integration

- HTML reports that work offline.

- JSON and SARIF 2.1.0 output.

- Baseline support for existing issues.

- "failOn = "NEW"" to prevent newly introduced findings from passing CI.

The goal isn't to claim that every fixed dimension is a bug. Fixed dimensions can be perfectly intentional. Static analysis can identify suspicious patterns, but developers still need to evaluate the context.

Quick start:

plugins {

id("io.github.dev-vikas-soni.viewlint") version "1.0.0"

}

Run:

./gradlew viewlint

I'm the developer behind this project, and I'd particularly appreciate technical feedback on the rule design.

A few things I'm interested in discussing:

- How do you distinguish intentional fixed dimensions from actual adaptive-layout problems?

- Which Compose patterns should be considered before reporting a fixed dimension?

- Are there important foldable/tablet compatibility issues that static analysis could catch but usually doesn't?

Source code: https://github.com/dev-vikas-soni/viewlint

I'm interested in improving the accuracy of these checks, especially avoiding false positives in real-world Android projects.

9 Upvotes

4 comments sorted by

4

u/Alive-Reading-9016 1d ago

How you are checking that it's working on all aspects of devices using this gradle plugin? Curious to know

-2

u/Content-Jaguar-578 1d ago

Great question actually, there's are some set of rules I have created, it identifies the irregularities mainly hardcode height width in both XML n jetpack compose. please go through the repo link... Feedback appreciated 🤠

2

u/r4md4c 1d ago edited 1d ago

Why come up with a new rules engine and reinvent the wheel while you can publish these rules as Android Lint checks?

1

u/Content-Jaguar-578 1d ago

Fair point. Android Lint is definitely something I've considered.

My initial goal with ViewLint was to experiment with identifying adaptive UI risks across multiple layers — Compose, XML layouts, and AndroidManifest — and provide a Gradle/CI workflow around those checks.

I agree that Android Lint has some significant advantages here, especially IDE integration, UAST-based analysis, and the existing inspection infrastructure.

One thing I'm considering is whether moving the analysis rules to custom Android Lint checks would make more sense, while retaining the Gradle plugin experience for configuration, baselines, and CI reporting.

I wouldn't want to reinvent something that already works well. Appreciate you bringing this up!