Novice development flutter problem record

1. Run flutter build apk and report an error:

D:\flutter_sdk\flutter>flutter build apk
Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
Do not run this command from the root of your git clone of Flutter.

Solution: Check if D:\flutter_sdk\flutter> is pointing to your own project path, and point to your own project path instead.

2. The flutter apk crashes and fails, reporting the problem of couldn't find "libflutter.so":

Error content:

    --------- beginning of crash
2019-07-02 17:40:36.626 7059-7059/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: comde.example.flutter_app, PID: 7059
    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/comde.example.flutter_app-1/base.apk"],nativeLibraryDirectories=[/data/app/comde.example.flutter_app-1/lib/arm64, /data/app/comde.example.flutter_app-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]] couldn't find "libflutter.so"
        at java.lang.Runtime.loadLibrary0(Runtime.java:984)
        at java.lang.System.loadLibrary(System.java:1562)
        at io.flutter.view.FlutterMain.startInitialization(FlutterMain.java:154)
        at io.flutter.view.FlutterMain.startInitialization(FlutterMain.java:130)
        at io.flutter.app.FlutterApplication.onCreate(FlutterApplication.java:22)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1025)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5547)
        at android.app.ActivityThread.-wrap2(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1625)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:163)
        at android.app.ActivityThread.main(ActivityThread.java:6383)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)

solution:

  1. Packaged separately for arm32 and arm64 (flutter provides commands to package arm32 and arm64 separately)

    • flutter build apk --target-platform=android-arm32

    • flutter build apk --target-platform=android-arm64

we useflutter build apk --target-platform=android-arm64Package the apk and install and run it on the mobile phone of the arm64cpu architecture. It works perfectly. But when we installed the apk to 32-bit, the problem reappeared, and the reason was no longer repeated. Obviously, this method cannot solve this problem. In order to adapt to arm32 and arm64, we need to package them separately, and most domestic application markets cannot upload different apks for different cpu architectures.

The solution comes from: https://www.jianshu.com/p/04684df6d829

 

Question 2.

After updating flutter sdk2.0.0, use Pub get after adding dependencies in pubspec.yaml , a warning will appear:

Your Flutter application is created using an older version of the Android
embedding. It's being deprecated in favor of Android embedding v2. Follow the
steps at

Solution: Add in AndroidManifest.xml

  1. <meta-data
  2. android:name="flutterEmbedding"
  3. android:value="2" />

Reference: http://www.ifindbug.com/doc/id-44369/name-opening-an-old-flutter-project-says-your-flutter-application-is-created-using-an-older-version-of-the-android-embedding.html

Question 3. 

1: [!] Your app isn't using AndroidX.

Solution: Add the following code to gradle.properties

android.enableJetifier=true
android.useAndroidX=true

 

Question 4. After upgrading flutter sdk to 2.0.0, running the old project reported an error

Launching lib\main.dart on Redmi Note 5A in debug mode...
/D:/flutter_sdk/flutter/.pub-cache/hosted/pub.flutter-io.cn/chewie-0.9.10/lib/src/chewie_player.dart:83:7: Error: No named parameter with the name 'resizeToAvoidBottomPadding'.
      resizeToAvoidBottomPadding: false,
      ^^^^^^^^^^^^^^^^^^^^^^^^^^
/D:/flutter_sdk/flutter/packages/flutter/lib/src/material/scaffold.dart:1451:9: Context: Found this candidate, but the arguments don't match.
  const Scaffold({undefined
        ^^^^^^^^
/D:/flutter_sdk/flutter/.pub-cache/hosted/pub.flutter-io.cn/chewie-0.9.10/lib/src/chewie_player.dart:276:17: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/D:/flutter_sdk/flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'inheritFromWidgetOfExactType'.
        context.inheritFromWidgetOfExactType(_ChewieControllerProvider)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^


FAILURE: Build failed with an exception.

* Where:
Script 'D:\flutter_sdk\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 991

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'D:\flutter_sdk\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 18s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done                        19.7s
Exception: Gradle task assembleDebug failed with exit code 1

solution: 

To troubleshoot this error by commenting out the third-party dependent library, it is found that chewie: ^0.9.7 is caused by the video playback plug-in, 

Note: When directly relying on chewie: ^0.9.7 library in pubspec.yaml, no error will be reported, only after adding import 'package:chewie/chewie.dart'; will an error be reported.

Tags: Novice development flutter problem record

flutter flutter error

Related: Novice development flutter problem record