Skip to content

[device_info] null safety version crashes for apps that opt into null safety #76194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MaikuB opened this issue Feb 17, 2021 · 6 comments · Fixed by flutter/plugins#3609
Closed
Assignees
Labels
a: null-safety Support for Dart's null safety feature c: crash Stack traces logged to the console found in release: 1.26 Found to occur in 1.26 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: device_info Plugin to access device information P1 High-priority issues at the top of the work list package flutter/packages repository. See also p: labels. r: fixed Issue is closed as already fixed in a newer version

Comments

@MaikuB
Copy link
Contributor

MaikuB commented Feb 17, 2021

Steps to Reproduce

  1. Update example app for device_info plugin to opt into null safety by changing the SDK constraints
  2. Run app on Android and app crashes

Note: I have fork with these changes that can reproduce the issue at https://github.com/MaikuB/plugins/tree/null_safety_device_info_crash/packages/device_info/device_info. Another observation is that going to the directory of the example app to run the integration test by running the following command

flutter drive \
  --driver=test_driver/integration_test.dart \
  --target=integration_test/device_info_test.dart

does not indicate failure. In fact, all tests are reported to have passed.

Expected results:

Able to receive info on the device

Actual results:

App crashes, it looks like platform channel is receiving null values from the native side

Logs
[ +707 ms] I/flutter ( 6978): type 'Null' is not a subtype of type 'String'
[        ] I/flutter ( 6978): #0      new List.from (dart:core-patch/array_patch.dart:40:5)
[        ] I/flutter ( 6978): #1      AndroidDeviceInfo._fromList (package:device_info_platform_interface/model/android_device_info.dart:144:12)
[        ] I/flutter ( 6978): #2      AndroidDeviceInfo.fromMap (package:device_info_platform_interface/model/android_device_info.dart:137:23)
[        ] I/flutter ( 6978): #3      MethodChannelDeviceInfo.androidInfo (package:device_info_platform_interface/method_channel/method_channel_device_info.dart:16:30)
[        ] I/flutter ( 6978): <asynchronous suspension>
[        ] I/flutter ( 6978): #4      DeviceInfoPlugin.androidInfo (package:device_info/device_info.dart:25:11)
[        ] I/flutter ( 6978): <asynchronous suspension>
[        ] I/flutter ( 6978): #5      _MyAppState.initPlatformState (package:device_info_example/main.dart:43:44)
[✓] Flutter (Channel beta, 1.26.0-17.6.pre, on macOS 11.2.1 20D74 darwin-x64,
    locale en-AU)
    • Flutter version 1.26.0-17.6.pre at /Users/michaelbui/flutter
    • Framework revision a29104a69b (17 hours ago), 2021-02-16 09:26:56 -0800
    • Engine revision 21fa8bb99e
    • Dart version 2.12.0 (build 2.12.0-259.12.beta)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/michaelbui/Library/Android/sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.53.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.19.0

[✓] Connected device (2 available)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86    • Android 11 (API
      30) (emulator)
    • Chrome (web)            • chrome        • web-javascript • Google Chrome
      88.0.4324.182
@darshankawar
Copy link
Member

@MaikuB
I followed your steps and modified plugin's sdk constraint to null safety, but while running, getting below errors:

Launching lib/main.dart on sdk gphone x86 arm in debug mode...
Running Gradle task 'assembleDebug'...
Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:

 - package:device_info
 - package:device_info_platform_interface
 - package:plugin_platform_interface

For solutions, see https://dart.dev/go/unsound-null-safety
lib/main.dart:56:21: Error: Non-nullable variable 'deviceData' must be assigned before it can be used.
      _deviceData = deviceData;
                    ^^^^^^^^^^


FAILURE: Build failed with an except
environment:
  sdk: ">=2.12.0-0 <3.0.0"

Used plugin's official repo example.

Can you provide more details / steps around how are you seeing the crash ?

flutter doctor -v
[✓] Flutter (Channel beta, 1.26.0-17.6.pre, on Mac OS X 10.15.4 19E2269
    darwin-x64, locale en-IN)
    • Flutter version 1.26.0-17.6.pre at /Users/dhs/documents/Fluttersdk/flutter
    • Framework revision a29104a69b (19 hours ago), 2021-02-16 09:26:56 -0800
    • Engine revision 21fa8bb99e
    • Dart version 2.12.0 (build 2.12.0-259.12.beta)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
    • Android SDK at /Users/dhs/Library/Android/sdk
    • Platform android-30, build-tools 30.0.0
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.3, Build version 12C33
    ! CocoaPods 1.9.3 out of date (1.10.0 is recommended).
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin
        code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To upgrade see
      https://guides.cocoapods.org/using/getting-started.html#installation for
      instructions.

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.53.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.18.1

[✓] Connected device (2 available)
    • sdk gphone x86 arm (mobile) • emulator-5554 • android-x86    • Android 11
      (API 30) (emulator)
    • Chrome (web)                • chrome        • web-javascript • Google
      Chrome 88.0.4324.150

! Doctor found issues in 1 category.

@darshankawar darshankawar added in triage Presently being triaged by the triage team waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds labels Feb 17, 2021
@MaikuB
Copy link
Contributor Author

MaikuB commented Feb 17, 2021

@darshankawar the steps I mentioned were all that I did. Your error looks worse because device_info had already been migrated to null safety (see https://github.com/flutter/plugins/blob/master/packages/device_info/device_info/pubspec.yaml). The error you're seeing generally occurs when looks using a plugin that hasn't been migrated to null safety but the app using it has opted in. Are you sure your copy of the plugins repo is up to date?

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Feb 17, 2021
@MaikuB
Copy link
Contributor Author

MaikuB commented Feb 17, 2021

Also noticed you mentioned you updated the plugin's SDK constraints though the steps I mentioned were to update the example's SDK constraints. As the plugin itself has already been migrated to null safety, it doesn't need to have the SDK constraints updated. In my original post, I had posted a link to a fork that can reproduce the problem so that could be cloned and run to see the issue. For convenience, the link is https://github.com/MaikuB/plugins/tree/null_safety_device_info_crash/packages/device_info/device_info. As I'm writing this, it is only one commit ahead of master, where the only change is to update the SDK constraints of the example app for the device_info plugin. The details of that commit can be seen at MaikuB/plugins@569ec0d

@darshankawar
Copy link
Member

Thanks @MaikuB for the details. I was able to see the crash using your fork above. Verified on Android 8.1.0 device using latest beta.

flutter doctor -v
[✓] Flutter (Channel beta, 1.26.0-17.6.pre, on Mac OS X 10.15.4 19E2269
    darwin-x64, locale en-IN)
    • Flutter version 1.26.0-17.6.pre at /Users/dhs/documents/Fluttersdk/flutter
    • Framework revision a29104a69b (2 days ago), 2021-02-16 09:26:56 -0800
    • Engine revision 21fa8bb99e
    • Dart version 2.12.0 (build 2.12.0-259.12.beta)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
    • Android SDK at /Users/dhs/Library/Android/sdk
    • Platform android-30, build-tools 30.0.0
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.3, Build version 12C33
    ! CocoaPods 1.9.3 out of date (1.10.0 is recommended).
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin
        code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To upgrade see
      https://guides.cocoapods.org/using/getting-started.html#installation for
      instructions.

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.53.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.18.1

[✓] Connected device (2 available)
    • SM A260G (mobile) • 5200763ebcfa861f • android-arm    • Android 8.1.0 (API
      27)
    • Chrome (web)      • chrome           • web-javascript • Google Chrome
      88.0.4324.182

! Doctor found issues in 1 category.

@darshankawar darshankawar added a: null-safety Support for Dart's null safety feature p: device_info Plugin to access device information p: first party found in release: 1.26 Found to occur in 1.26 has reproducible steps The issue has been confirmed reproducible and is ready to work on c: crash Stack traces logged to the console and removed in triage Presently being triaged by the triage team labels Feb 18, 2021
@cyanglaz cyanglaz added the P1 High-priority issues at the top of the work list label Feb 18, 2021
jason-simmons added a commit to jason-simmons/flutter_plugins that referenced this issue Feb 18, 2021
@stuartmorgan-g
Copy link
Contributor

@cyanglaz We need to make sure the fix for this is landed/tested before the stable NNBD release.

@github-actions
Copy link

github-actions bot commented Aug 5, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 5, 2021
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: null-safety Support for Dart's null safety feature c: crash Stack traces logged to the console found in release: 1.26 Found to occur in 1.26 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: device_info Plugin to access device information P1 High-priority issues at the top of the work list package flutter/packages repository. See also p: labels. r: fixed Issue is closed as already fixed in a newer version
Projects
None yet
4 participants