fix(android): remove unchecked Java compilation warnings

Open Beginner friendly
#8,529 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Quiet
Tech stack
java
Domain
mobile

Research direction

Inspect android/capacitor/src/main/java/com/getcapacitor/Plugin.java around line 679 and BridgeWebChromeClient.java, focusing on the raw collection and ActivityResultLauncher fields identified in the issue. Run ./gradlew :capacitor-android:clean :capacitor-android:compileReleaseJavaWithJavac --console=plain with -Xlint:unchecked enabled; done means the Android library compiles without unchecked-operation warnings and behavior is unchanged.

Written by the indexing model from the issue text.

Description

triage

Summary

Compiling the Capacitor Android library with -Xlint:unchecked reports eight
unchecked operations in the current 8.4.1 release and on main.

Reproduction

From an Android app that includes @capacitor/android@8.4.1, configure Java
compile tasks with -Xlint:unchecked and run:

./gradlew :capacitor-android:clean :capacitor-android:compileReleaseJavaWithJavac --console=plain

The default compilation emits the generic Some input files use unchecked or unsafe operations note.

Affected source

  • android/capacitor/src/main/java/com/getcapacitor/Plugin.java:679 constructs
    a raw CopyOnWriteArrayList from a List<PluginCall>.
  • android/capacitor/src/main/java/com/getcapacitor/BridgeWebChromeClient.java
    stores the permission and activity launchers as raw ActivityResultLauncher
    values, producing six unchecked calls at lines 120, 267, 298, 350, 369, and
    401.

Expected behavior

The released Android library should compile without unchecked-operation notes.
Parameterizing the collection construction and the two launcher fields should
remove the warnings without changing behavior.

Dominant language
TypeScript
Stars
16.7k
Forks
1.3k
Avg merge
3d 10h
Merged PRs (30d)
10

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ionic-team/capacitor

All issues in ionic-team/capacitor

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.