r/androiddev • • 2h 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.

4 Upvotes

2 comments sorted by

2

u/Alive-Reading-9016 45m ago

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

1

u/Content-Jaguar-578 42m 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 ðŸ¤