mobile-java
БесплатноБез исполняемых скриптовНе проверенWrites, reviews and modernizes Java in Android apps: Java 17 and 21 features that D8 supports, immutability, JSpecify nullability for Kotlin interop…
от ahmadhussain0335267 установок в других каталогахОб этом скилле
Java on Android
Keep Java Android code correct, leak-free and Kotlin-friendly while it lives, and move it to Kotlin in small safe steps when the team decides to.
When to use
- Editing, fixing or reviewing
.javafiles in an Android app or library. - Bumping the Java language level, or using a JDK API that may not exist on the app's
minSdk. - Java code that Kotlin code calls (or will call) and needs nullability and interop annotations.
- Leaks, ANRs or crashes caused by Handlers, executors, Fragments, adapters or unclosed resources.
- Planning or executing an incremental Java-to-Kotlin migration.
Not for: Kotlin-first code (use mobile-kotlin), architecture choices (use mobile-mvvm, mobile-mvi).
Workflow
- Read the module's build file:
compileOptionssource and target level,minSdk, and whetherisCoreLibraryDesugaringEnabledis on. These decide which features and APIs are safe. - Load the reference that matches the task: Threading, Migration to Kotlin, Testing.
- If the project already builds Kotlin and the team has not said otherwise, write new classes in Kotlin. Change existing Java minimally and in place.
- Add nullability annotations to every public signature you touch.
- Apply the rules below. Prefer fixing leaks and threading over stylistic rewrites.
- Run lint (
./gradlew lint) forNewApi, threading annotation and resource-leak checks, then the tests. - Keep conversion or modernization commits separate from behaviour changes.
Toolchain: what Java you can use
| Feature | Java | On Android |
|---|---|---|
| Lambdas, method references, default and static interface methods | 8 | Desugared by D8 for every API level |
var, switch expressions, text blocks, instanceof patterns |
10-16 | Compile-time features, every API level |
| Records | 16 | Supported by current AGP (D8 desugars them). Check reflection-based JSON libraries |
| Sealed classes and interfaces | 17 | Only on recent AGP / D8. Verify before relying on them |
Pattern matching for switch, record patterns |
21 | Needs Java 21 source level and AGP / D8 support. Verify first |
java.time (API 26), java.util.stream, Optional, java.util.function (API 24) |
library | Below those API levels only with core library desugaring |
Newer JDK methods (List.of, List.getFirst(), Stream.toList()) |
library | Tied to newer API levels. Trust lint NewApi; desugaring covers only part |
The JDK that runs Gradle (17+ for current AGP) is separate from the language level and from the APIs available at runtime. The runtime APIs come from the device's Android version.
Rules
1. Language level is free, library APIs are not
// BAD: compiles against a recent compileSdk, crashes on older devices (added to Android in API 35)
Device first = devices.getFirst();
// GOOD
Device first = devices.get(0);
// GOOD: java.time on minSdk below 26 through core library desugaring (app/build.gradle.kts)
android {
compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
dependencies { coreLibraryDesugaring(libs.desugar.jdk.libs) }
Never suppress NewApi without a Build.VERSION.SDK_INT check or confirmed desugaring.
2. Immutable by default
// BAD: public mutable fields, internal list shared with callers
public class Device {
public String name;
public List<String> tags;
}
// GOOD: record with a defensive copy (works on every API level)
public record Device(String id, String name, List<String> tags) {
public Device {
Objects.requireNonNull(id);
tags = Collections.unmodifiableList(new ArrayList<>(tags));
}
}
- No records?
finalclass,private finalfields, no setters, copies in and unmodifiable views out. static finalconstants only for truly immutable values. Astatic final Listis still mutable.
3. Nullability is declared for Kotlin callers
// package-info.java: everything in the package is non-null unless marked
@NullMarked
package com.example.devices;
import org.jspecify.annotations.NullMarked;
// BAD: Kotlin sees String! (platform type) and skips null checks, NPE at runtime
public String findName(String id) { return names.get(id); }
// GOOD: inside @NullMarked, only nullable values are annotated
public @Nullable String findName(String id) { return names.get(id); }
- JSpecify
@Nullableis a type-use annotation:List<@Nullable String>,String @Nullable []. - Packages not yet
@NullMarkeduse AndroidX@NonNull/@Nullableon every public parameter and return. - Recent Kotlin compilers report JSpecify violations as errors, so wrong annotations break the Kotlin build.
4. Nothing long-lived references an Activity, Fragment or View
// BAD: static field
Установить mobile-java в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл mobile-java?
Writes, reviews and modernizes Java in Android apps: Java 17 and 21 features that D8 supports, immutability, JSpecify nullability for Kotlin interop, leak-free threading without static Context or inner-class Handlers, ExecutorService, LiveData, ViewBinding, ListAdapter and DiffUtil, tests with JUnit, Mockito and Espresso, and incremental migration to Kotlin. Use when editing, reviewing or migrating .java files in an Android project.
Как установить скилл mobile-java?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл mobile-java запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic