flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [firebase_analytics] FlutterFirebaseAnalyticsPlugin has unchecked cast

Open bswhite1 opened this issue 3 years ago • 5 comments

Bug report

Describe the bug Build is throwing warnings. compiling with details shows it is an unchecked cast within FlutterFirebaseAnalyticsPlugin.java

/Users/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_analytics-9.1.7/android/src/main/java/io/flutter/plugins/firebase/analytics/FlutterFirebaseAnalyticsPlugin.java:69: warning: [unchecked] unchecked cast
            list.add(createBundleFromMap((Map<String, Object>) item));
                                                               ^
  required: Map<String,Object>
  found:    Object


/Users/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_analytics-9.1.7/android/src/main/java/io/flutter/plugins/firebase/analytics/FlutterFirebaseAnalyticsPlugin.java:82: warning: [unchecked] unchecked cast
        bundle.putParcelable(key, createBundleFromMap((Map<String, Object>) value));
                                                                            ^
  required: Map<String,Object>
  found:    Object

Steps to reproduce

Steps to reproduce the behavior:

  1. Compiled with android studio on mac

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.5, on macOS 12.2.1 21D62 darwin-x64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.66.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability


Flutter dependencies

using: firebase_core: ^1.16.0 firebase_analytics: ^9.1.7 firebase_auth: ^3.3.17 cloud_firestore: ^3.1.14

firebase_crashlytics: ^2.7.2 firebase_messaging: ^11.3.0 firebase_performance: ^0.8.0+11


bswhite1 avatar May 03 '22 21:05 bswhite1

@bswhite1 I tried using the plugin example with latest version, but didn't get the exception reported. Are there any specific steps to see the log ?

darshankawar avatar May 04 '22 09:05 darshankawar

Just pulled the flutterfire firebase_analytics example. Made the following changes

android/app/build.gradle
compileSdkVersion 31
android/build.gradle 
classpath 'com.android.tools.build:gradle:7.1.3'
I also added the following:
allprojects {
     gradle.projectsEvaluated {
            tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xlint:unchecked"
        }
    }

android/gradle/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip

Did a flutter clean, flutter pub get, then build. I see these errors.

bswhite1 avatar May 04 '22 14:05 bswhite1

I think I'd prefer to do the Map checks in the dart layer before it gets to the android side. We're getting the map from the parameters passed in from the Dart layerlogEvent() and calling Firebase Android SDK own logEvent(). My sense is we should update the log event function in the dart layer to stop any unallowed params from being passed in.

The only map allowed, as far as I can tell, is the one that is allowed in the items array here. According to the documentation, every other property has to be a primitive value (numbers and strings).

iOS android

So I think I'll improve the Map checks in the dart layer and make a note in the android code to explain why it is unchecked.

russellwheatley avatar Aug 22 '22 15:08 russellwheatley

I am still getting this issue in version 9.3.5 on flutter sdk 3.3.2

Note: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_analytics-9.3.5\android\src\main\java\io\flutter\plugins\firebase\analytics\FlutterFirebaseAnalyticsPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

under3415 avatar Sep 15 '22 22:09 under3415

Any solutions ?

jalchr avatar Sep 21 '22 08:09 jalchr