flutter_gaimon icon indicating copy to clipboard operation
flutter_gaimon copied to clipboard

Missing API level check for hasAmplitudeControl() causes lint error

Open Harunn33 opened this issue 9 months ago • 1 comments

Summary

The plugin causes a build failure due to an Android Lint error when used in Flutter projects with minSdkVersion < 26.

In the GaimonPlugin.kt file, inside the "pattern" method, the vibrator.hasAmplitudeControl() call is made without checking the Android API level. This method requires API 26, and using it without proper checks results in a lint error.


Reproduction Steps

  1. Set minSdkVersion to 23 or lower in your Flutter project's android/app/build.gradle.
  2. Add gaimon version 1.4.1 as a dependency.
  3. Try to build or run the project.
  4. Observe that the build fails due to a Lint error pointing to hasAmplitudeControl().

Environment

Flutter version: 3.29.3

Plugin version: 1.4.1

Android compileSdkVersion: 35

Android minSdkVersion: 23

Expected Behavior

The method call should be guarded with an API level check as follows:


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && vibrator.hasAmplitudeControl()) {
    val effect = VibrationEffect.createWaveform(mVibratePattern, mAmplitudes, repeat)
    vibrate(effect)
}

Harunn33 avatar Jun 27 '25 15:06 Harunn33

Thanks for raising an issue but I can't reproduce the same result on my side...

  • Created a fresh flutter project.
  • Edited the build.gradle.kts file
  • Add gaimon latest version: gaimon: ^1.4.1
  • Run the command flutter build aab
  • Build complete successfully

Here is the build.gradle.kts file of my example app:

android {
    namespace = "com.example.gaimontest"
    compileSdk = 35
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_11.toString()
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "com.example.gaimontest"
        // You can update the following values to match your application needs.
        // For more information, see: https://flutter.dev/to/review-gradle-config.
        minSdk = 23
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig = signingConfigs.getByName("debug")
        }
    }
}

istornz avatar Jul 30 '25 13:07 istornz