Skip to content

Android: no runtime API guard and Activity-only initialisation #30

Open

Description

@developerjamiu
// android/src/main/kotlin/com/developerjamiu/smart_text_flutter/SmartTextFlutterPlugin.kt:73-78
@TargetApi(Build.VERSION_CODES.O)
private fun initClassificationManager() {
    textClassifer = AndroidTextClassifer()
    textClassificationManager =
        activity?.getSystemService(Context.TEXT_CLASSIFICATION_SERVICE) as TextClassificationManager
}

Three problems:

  1. @TargetApi silences lint and guards nothing at runtime. Below API 26 getSystemService returns null and the non-null cast throws. Declared minSdkVersion is 19; Flutter's own floor is now 24, so the live window is API 24 to 25 plus anyone who lowers it deliberately.
  2. Both textClassifer and textClassificationManager are lateinit and assigned only from onAttachedToActivity, so any call arriving without an Activity throws UninitializedPropertyAccessException.
  3. The Linkify fallback path also depends on that Activity-only initialisation, which it has no reason to.

Fix: initialise textClassifer in onAttachedToEngine, resolve the manager lazily behind a real Build.VERSION.SDK_INT >= O check, and correct the README's "SDK 19+" claim.

Found during the v0.4.0 codebase audit.

Activity

  1. added
    bug
    platform: android
    on Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugplatform: android

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions