flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165k stars 27.18k forks source link

webview_flutter carsh with NullPointerException on HuaWei Nova #71142

Closed Rickyballs closed 3 years ago

Rickyballs commented 3 years ago

Here is the flutter doctor

[√] Flutter (Channel stable, 1.22.2, on Microsoft Windows [Version 6.1.7601], locale zh-CN)
    • Flutter version 1.22.2 at F:\flutter1.22.2\flutter
    • Framework revision 84f3d28555 (6 weeks ago), 2020-10-15 16:26:19 -0700
    • Engine revision b8752bbfff
    • Dart version 2.10.2
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at E:\SDK
    • Platform android-R, build-tools 29.0.2
    • ANDROID_HOME = E:\SDK
    • Java binary at: C:\android-studio-ide-171.4443003-windows\android-studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Android Studio (version 4.0)
    • Android Studio at E:\Android Studio
    • Flutter plugin version 50.0.1
    • Dart plugin version 193.7547
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[!] Android Studio (version 4.1.0)
    • Android Studio at C:\android-studio-ide-171.4443003-windows\android-studio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[!] VS Code, 64-bit edition (version 1.18.0)
    • VS Code at C:\Program Files\Microsoft VS Code
    X Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (1 available)
    • MI 5 (mobile) • 925fedd4 • android-arm64 • Android 7.0 (API 24)

! Doctor found issues in 2 categories.

Steps to Reproduce

  1. webview_flutter 1.0.7.
  2. Run on HuaWei Nova(华为 CAZ AL10 | Android 7.0,level 24)
  3. When you open a website, it crashes
Logs ``` java.lang.NullPointerException Attempt to invoke virtual method 'void android.view.Display.getSize(android.graphics.Point)' on a null object reference org.chromium.ui.display.DisplayAndroid.updateFromDisplay(DisplayAndroid.java:280) org.chromium.ui.display.DisplayAndroidManager$DisplayListenerBackendImpl.onDisplayChanged(DisplayAndroidManager.java:176) android.hardware.display.DisplayManagerGlobal$DisplayListenerDelegate.handleMessage(DisplayManagerGlobal.java:495) android.os.Handler.dispatchMessage(Handler.java:105) android.os.Looper.loop(Looper.java:156) android.app.ActivityThread.main(ActivityThread.java:6517) java.lang.reflect.Method.invoke(Native Method) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832) ```
pedromassangocode commented 3 years ago

Hi @Rickyballs Can you please provide your flutter run --verbose and a minimal complete reproducible code sample? Thank you

Rickyballs commented 3 years ago

This is the main part of the code

class WebViewExample extends StatefulWidget {
  @override
  WebViewExampleState createState() => WebViewExampleState();
}

class WebViewExampleState extends State<WebViewExample> {
  @override
  void initState() {
    super.initState();
    // Enable hybrid composition.
    // if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
  }

  /// loadfinish()
  void _webViewFinishLoadRequestCallback(String url) {
    _progress=1.0;
    if (mounted) {
      setState(() {
        //do sth
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      child: new Column(
        children: <Widget>[
          _linearProgressWidget(),
          _body(),
          // _webLogoutWidget(),
        ],
      ),
    );
  }

  Widget _body() {
    return new Expanded(
      child: _webView(),
    );
  }

  /// webView
  Widget _webView() {
    return Container(
      child: WebView(
        initialUrl: "https://www.baidu.com/",
        javascriptMode: JavascriptMode.unrestricted,
        onPageFinished: _webViewFinishLoadRequestCallback,
      ),
    );
  }

  double _progress=0.45;
  Widget _linearProgressWidget() {
    if (1.0 == _progress) {
      ///if return Container(height:3.0); Crash would not happen;
      return new Padding(padding: new EdgeInsets.only());
    }

    return new Container(
      child: new LinearProgressIndicator(
        backgroundColor: new Color(0x00FFFFFF),
        value: _progress,
        valueColor: new AlwaysStoppedAnimation<Color>(new Color(0xFF24C77E)),
      ),
      height: 3.0,
    );
  }
}

Yesterday's experiment found that as long as there is no height change after initialization, it will not crash. This strange problem only appears on HuaWei Nova. Others of the same system will not have such problems.

Rickyballs commented 3 years ago

[ +131 ms] executing: [F:\flutter1.22.2\flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H [ +314 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H [ ] 84f3d28555368a70270e9ac8390a9441df95e752 [ +1 ms] executing: [F:\flutter1.22.2\flutter/] git tag --points-at HEAD [ +380 ms] Exit code 0 from: git tag --points-at HEAD [ ] 1.22.2 [ +11 ms] executing: [F:\flutter1.22.2\flutter/] git rev-parse --abbrev-ref --symbolic @{u} [ +179 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u} [ +1 ms] origin/stable [ ] executing: [F:\flutter1.22.2\flutter/] git ls-remote --get-url origin [ +163 ms] Exit code 0 from: git ls-remote --get-url origin [ ] https://github.com/flutter/flutter.git [ +236 ms] executing: [F:\flutter1.22.2\flutter/] git rev-parse --abbrev-ref HEAD [ +174 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD [ +1 ms] stable [ +104 ms] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update. [ ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update. [ ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update. [ ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update. [ +18 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update. [ +1 ms] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update. [ +25 ms] executing: E:\SDK\platform-tools\adb.exe devices -l [ +116 ms] List of devices attached 925fedd4 device product:gemini model:MI_5 device:gemini transport_id:6 debug2.testin.cn:4082 device product:CAZ-AL10 model:HUAWEI_CAZ_AL10 device:HWCAZ transport_id:10 [ +8 ms] E:\SDK\platform-tools\adb.exe -s 925fedd4 shell getprop [ +206 ms] E:\SDK\platform-tools\adb.exe -s debug2.testin.cn:4082 shell getprop [ +232 ms] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update. [ +5 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update. [ +1 ms] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update. [ +3 ms] Artifact Instance of 'FlutterWebSdk' is not required, skipping update. [ +3 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update. [ +113 ms] Multiple devices found: [ +3 ms] ro.hardware = qcom [ +2 ms] ro.hardware = qcom [ +3 ms] MI 5 (mobile) • 925fedd4 • android-arm64 • Android 7.0 (API 24) [ +1 ms] HUAWEI CAZ AL10 (mobile) • debug2.testin.cn:4082 • android-arm64 • Android 7.0 (API 24) [ +1 ms] [0]: MI 5 (925fedd4) [ ] [1]: HUAWEI CAZ AL10 (debug2.testin.cn:4082) [ +1 ms] Please choose one (To quit, press "q/Q") [ ] :

pedromassangocode commented 3 years ago

Can't reproduce this because I don't own a Huawei device mentioned above. The issue does not reproduce on my emulators and physical Xiaomi 5Plus device.

Rickyballs commented 3 years ago

This problem is not serious. I have no problem with other mobile phones except this one. Besides,It's hard to find HuaWei nova. It doesn't trigger as long as you don't change the height.

github-actions[bot] commented 3 years ago

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.