flutter_gaimon
flutter_gaimon copied to clipboard
Missing API level check for hasAmplitudeControl() causes lint error
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
- Set
minSdkVersionto 23 or lower in your Flutter project'sandroid/app/build.gradle. - Add
gaimonversion1.4.1as a dependency. - Try to build or run the project.
- 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)
}
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.ktsfile - 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")
}
}
}