Flutter project not running after successful migration to null safety - flutter

I have problem running flutter project after successful migration to null safety. I use android studio. Here is the result of flutter doctor:
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.2.1, on Microsoft Windows [Version 10.0.19041.985], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] Connected device (3 available)
• No issues found!
And here is the result of outdated dependency checks:
See https://dart.dev/go/null-safety-migration for a migration guide.
Analyzing project...
[-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\]
All sources appear to be already migrated. Nothing to do.
However, I get an error caused by a dependency (not used directly in my pubspec.yaml, but seems one of the packages is using it and this dependency has no null safety updated). So when I try to run it from android studio I get the following output (even though dart migrate should have mention even internal packages dependencies since it might be a stopper from running):
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:
- package:tinycolor
For solutions, see https://dart.dev/go/unsound-null-safety
lib/screens/invitations_screen.dart:115:5: Warning: Operand of null-aware operation '?.' has type 'TabController' which excludes null.
- 'TabController' is from 'package:flutter/src/material/tab_controller.dart' ('/D:/Flutter/flutterV1.0.0.0/packages/flutter/lib/src/material/tab_controller.dart').
_c1?.dispose();
^
/D:/Flutter/flutterV1.0.0.0/.pub-cache/hosted/pub.dartlang.org/flutter_datetime_picker-1.5.1/lib/flutter_datetime_picker.dart:311:32: Warning: Operand of null-aware operation '??' has type 'Color' which excludes null.
- 'Color' is from 'dart:ui'.
color: theme.backgroundColor ?? Colors.white,
^
FAILURE: Build failed with an exception.
* Where:
Script 'D:\Flutter\flutterV1.0.0.0\packages\flutter_tools\gradle\flutter.gradle' line: 1035
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'D:\Flutter\flutterV1.0.0.0\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 23s
Exception: Gradle task assembleDebug failed with exit code 1
So I tried finally to run without sound-null-safety, but still an error keeps happening (I tried flutter clean --> Invalidate Caches/Restart --> pub get --> flutter run --no-sound-null-safety but still the same problem):
Using hardware rendering with device Android SDK built for x86. If you notice graphics artifacts, consider enabling software rendering with "--enable-software-rendering".
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 22.1s
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Error connecting to the service protocol: failed to connect to http://127.0.0.1:57596/NxvUCmZt3sM=/
Note: Before the last trial of restarting android studio, this last error also showed an exception right before the "Error connecting ..." statement, and the exception was as I recall (sorry don't have the full stack trace as it doesn't show anymore):
androidx WindowInsetsCompat ---> NullPointerException on Preconditions.checkNonNull
EDIT
After going through dependencies in a new porject as suggested by #Taur, it turns out the problem when running without sound-null-safety was caused by flutter_typeahead dependency throwing the previously mentioned exception when I run the project:
E/AndroidRuntime(11173): java.lang.ExceptionInInitializerError
E/AndroidRuntime(11173): at androidx.core.view.WindowInsetsCompat.<clinit>(WindowInsetsCompat.java:82)
E/AndroidRuntime(11173): at androidx.core.view.WindowInsetsCompat.toWindowInsetsCompat(WindowInsetsCompat.java:169)
E/AndroidRuntime(11173): at androidx.core.view.ViewCompat$Api21Impl$1.onApplyWindowInsets(ViewCompat.java:4753)
E/AndroidRuntime(11173): at android.view.View.dispatchApplyWindowInsets(View.java:9799)
E/AndroidRuntime(11173): at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:7076)
E/AndroidRuntime(11173): at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:7080)
E/AndroidRuntime(11173): at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:7080)
E/AndroidRuntime(11173): at android.view.ViewRootImpl.dispatchApplyInsets(ViewRootImpl.java:1632)
E/AndroidRuntime(11173): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1734)
E/AndroidRuntime(11173): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1443)
E/AndroidRuntime(11173): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7125)
E/AndroidRuntime(11173): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:935)
E/AndroidRuntime(11173): at android.view.Choreographer.doCallbacks(Choreographer.java:747)
E/AndroidRuntime(11173): at android.view.Choreographer.doFrame(Choreographer.java:682)
E/AndroidRuntime(11173): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:921)
E/AndroidRuntime(11173): at android.os.Handler.handleCallback(Handler.java:873)
E/AndroidRuntime(11173): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(11173): at android.os.Looper.loop(Looper.java:164)
E/AndroidRuntime(11173): at android.app.ActivityThread.main(ActivityThread.java:6649)
E/AndroidRuntime(11173): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(11173): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/AndroidRuntime(11173): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
E/AndroidRuntime(11173): Caused by: java.lang.NullPointerException
E/AndroidRuntime(11173): at androidx.core.util.Preconditions.checkNotNull(Preconditions.java:119)
E/AndroidRuntime(11173): at androidx.core.view.WindowInsetsCompat.toWindowInsetsCompat(WindowInsetsCompat.java:169)
E/AndroidRuntime(11173): at androidx.core.view.WindowInsetsCompat.toWindowInsetsCompat(WindowInsetsCompat.java:149)
E/AndroidRuntime(11173): at androidx.core.view.WindowInsetsCompat$BuilderImpl20.build(WindowInsetsCompat.java:1706)
E/AndroidRuntime(11173): at androidx.core.view.WindowInsetsCompat$Builder.build(WindowInsetsCompat.java:1588)
E/AndroidRuntime(11173): at androidx.core.view.WindowInsetsCompat$Impl.<clinit>(WindowInsetsCompat.java:748)
E/AndroidRuntime(11173): ... 22 more

Related

Flutter: Icon works locally but fails android driver test: Error: Member not found: 'airline_stops'

I'm trying to use the icon "Icons.airline_stops" that can be found on the flutter website https://api.flutter.dev/flutter/material/Icons/airline_stops-constant.html
When I compile it on my local emulator, it displays correctly as I want. However, when I do a commit and the android drive test are run, it fails.
drive_android (Failed)
drive_ios (Success)
Problematic line in the error:
lib/external_projects/project1/screens/finish_experiment.dart:71:23: Error: Member not found: 'airline_stops'.
Icons.airline_stops,
^^^^^^^^^^^^^
If I change this icon to another one, the android drive test passes successfully. But I'd like to use this one and since it's in the flutter.dev website it should work...
Complete error log:
Running "flutter pub get" in flutter_tools... WARNING | /etc/localtime does not point to zoneinfo-compatible timezone name
5.4s
Running "flutter pub get" in my_project... 36.4s
Running Gradle task 'assembleDebug'...
[flutter_background_geolocation] Purging debug resources in release build
lib/external_projects/project1/screens/finish_experiment.dart:71:23: Error: Member not found: 'airline_stops'.
Icons.airline_stops,
^^^^^^^^^^^^^
FAILURE: Build failed with an exception.
* Where:
Script '/Users/runner/hostedtoolcache/flutter/2.8.1-stable/x64/packages/flutter_tools/gradle/flutter.gradle' line: 1070
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/Users/runner/hostedtoolcache/flutter/2.8.1-stable/x64/bin/flutter'' 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 2m 18s
Running Gradle task 'assembleDebug'... 140.9s
Gradle task assembleDebug failed with exit code 1
Error: The process '/bin/sh' failed with exit code 1
Terminate Emulator
INFO | Discarding the changed state: command-line flag
WARNING | Discarding the changed state (command-line flag).
INFO | Shutting down gRPC endpoint
INFO | Shutting down gRPC endpoint
Solution:
The virtual machine flutter version used to run drive_android tests has to be updated to match the flutter version.
Explanation:
In this case, my flutter versions were as follows:
Local device: Flutter 2.10.5
drive_android: Flutter 2.8.1
drive_ios: Flutter 2.10.0
The icon Icon.airline_stops was probably introduced in a flutter version older than 2.8.1, that's the reason why it failed drive_android but passed both the local device (that is using Android) and the drive_ios tests.
Therefore, to solve this all versions must be updated to match the local device. And, why not update drive_ios too to avoid something similar happening in the future?
Local device: Flutter 2.10.5
drive_android: Flutter 2.8.1 -> 2.10.5
drive_ios: Flutter 2.10.0 -> 2.10.5

Error: No named parameter with the name 'nullOk'. after updating to FLutter 2.0

I updated my App to the latest version of the Flutter.
E:\anmol\Jan' 2021 -Backup\nemar_user_(for_new_packages)>flutter --version
Flutter 2.0.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 4d7946a68d (3 days ago) • 2021-03-18 17:24:33 -0700
Engine • revision 3459eb2436
Tools • Dart 2.12.2
Along with that, I upgraded new packages in pubspec.yaml
When I run my app, then it shows the following errors, I tried so many things but nothing Works. Any Kind of Help would be appreciated.
/E:/flutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/expandable_text-1.3.2/lib/expandable_text.dart:153:56: Error: No named parameter with the name 'nullOk'.
final locale = Localizations.localeOf(context, nullOk: true);
^^^^^^
/E:/flutterSDK/flutter/packages/flutter/lib/src/widgets/localizations.dart:413:17: Context: Found this candidate, but the arguments don't match.
static Locale localeOf(BuildContext context) {
^^^^^^^^
FAILURE: Build failed with an exception.
Where:
Script 'E:\flutterSDK\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 991
What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
Process 'command 'E:\flutterSDK\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 46s
Exception: Gradle task assembleDebug failed with exit code 1
This is due to the version of Flutter you're using (stable channel, Flutter 2.0.3) is null-safety enabled. These are the APIs that were subject to change & so you need to use this migration guide to modify your code to use the new form of the APIs with null safety.
Method 1:
Check if you're using any of the aforementioned API dependencies & use .maybeOf(context) instead of .of(context, nullOk: true);
In your posted code,change your Localizations.localeOf(context, nullOk: true); to Localizations.maybeLocaleOf(context);
Method 2:
Find the dependency that caused the problem & update it to null safety, for example, if you're using flutter_svg: ^0.19.0 you'll encounter the same error, so either update it to flutter_svg: ^0.20.0-nullsafety.3 or in case you can't migrate to null safety yet, use this version flutter_svg: ^0.19.3
Method 3:
Alternatively, if you can also downgrade your Flutter version which doesn't provide null safety. It should also fix the error but needs the downgrading. To downgrade to v1.22.6 run the following command:
flutter downgrade v1.22.6
After each/any method, run the following commands:
flutter clean
flutter pub get
flutter run

showing Error while running using Getx widget-Flutter

This error occurs only when I use get package. To Solve this problem, I deleted get folder from the .pub-cache/hosted/pub.dartlang.org destination and again imported it but nothing happened.
Launching lib\main.dart on sdk gphone x86 arm in debug mode...
Running Gradle task 'assembleDebug'...
/D:/Flutter/.pub-cache/hosted/pub.dartlang.org/get-3.25.4/lib/
get_navigation/src/root/get_cupertino_app.dart:121:9:
Error: Type 'RouteInformationProvider' not found.
final RouteInformationProvider routeInformationProvider;
^^^^^^^^^^^^^^^^^^^^^^^^
/D:/Flutter/.pub-cache/hosted/pub.dartlang.org/get-3.25.4/lib/
get_navigation/src/root/get_cupertino_app.dart:122:9: Error: Type
'RouteInformationParser' not found.
final RouteInformationParser<Object> routeInformationParser;
^^^^^^^^^^^^^^^^^^^^^^
/D:/Flutter/.pub-cache/hosted/pub.dartlang.org/get-3.25.4/lib/
get_navigation/src/root/get_cupertino_app.dart:122:9: Error:
Expected 0 type arguments.
final RouteInformationParser<Object> routeInformationParser;
^
/D:/Flutter/.pub-cache/hosted/pub.dartlang.org/get-3.25.4/lib/
get_navigation/src/root/get_cupertino_app.dart:123:9: Error: Type
'RouterDelegate' not found.
final RouterDelegate<Object> routerDelegate;
^^^^^^^^^^^^^^
/D:/Flutter/.pub-cache/hosted/pub.dartlang.org/get-3.25.4/lib/
get_navigation/src/root/get_cupertino_app.dart:123:9: Error:
Expected 0 type arguments.
final RouterDelegate<Object> routerDelegate;
^
/D:/Flutter/.pub-cache/hosted/pub.dartlang.org/get-3.25.4/lib/
get_navigation/src/root/get_material_app.dart:130:9: Error:
Expected 0 type arguments.
final RouteInformationParser<Object> routeInformationParser;
^^^^^^^^^^^^^^
/D:/Flutter/.pub-cache/hosted/pub.dartlang.org/get-3.25.4/lib/
get_navigation/src/root/get_material_app.dart:132:9: Error: '
BackButtonDispatcher' isn't a type.
final BackButtonDispatcher backButtonDispatcher;
^^^^^^^^^^^^^^^^^^^^
/D:/Flutter/.pub-cache/hosted/pub.dartlang.org/get-3.25.4/lib/
get_navigation/src/root/get_material_app.dart:245:25: Error:
Method not found: 'MaterialApp.router'.
? MaterialApp.router(
^^^^^^
FAILURE: Build failed with an exception.
* Where:
Script 'D:\Flutter\packages\flutter_tools\gradle\flutter.gradle'
line: 896
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'D:\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 22s
Exception: Gradle task assembleDebug failed with exit code 1
I Used many other packages but the error occurred only when using get package.
open your android studio terminal
1 - clean your project
flutter clean
2 - change flutter channel to stable
Flutter channels:
master
dev
beta
* stable
make sure you are on a stable channel
3 - now you need to make upgrade flutter upgrade (on the terminal)
flutter upgrade
output
Flutter is already up to date on channel stable
Flutter 2.0.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision c5a4b4029c (2 days ago) • 2021-03-04 09:47:48 -0800
Engine • revision 40441def69
Tools • Dart 2.12.0
4 - make clean again
flutter clean
if you on flutter 2 then all is well :)

Flutter New Project Build Error mergeDebugResources

I have created a new flutter project and out of nowhere it gives me the following errors when I run the default application (no edits made).
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Multiple task action failures occurred:
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource compilation failed
C:\Users\bvenh\Documents\flutter\flutter_app_5\build\app\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml: AAPT: error: file failed to compile.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource compilation failed
C:\Users\bvenh\Documents\flutter\flutter_app_5\build\app\intermediates\incremental\mergeDebugResources\merged.dir\values-hi\values-hi.xml: AAPT: error: file failed to compile.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource compilation failed
C:\Users\bvenh\Documents\flutter\flutter_app_5\build\app\intermediates\incremental\mergeDebugResources\merged.dir\values-de\values-de.xml: AAPT: error: file failed to compile.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource compilation failed
C:\Users\bvenh\Documents\flutter\flutter_app_5\build\app\intermediates\incremental\mergeDebugResources\merged.dir\values-lo\values-lo.xml: AAPT: error: file failed to compile.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource compilation failed
C:\Users\bvenh\Documents\flutter\flutter_app_5\build\app\intermediates\incremental\mergeDebugResources\merged.dir\values-pt\values-pt.xml: AAPT: error: file failed to compile.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource compilation failed
C:\Users\bvenh\Documents\flutter\flutter_app_5\build\app\intermediates\incremental\mergeDebugResources\merged.dir\values-lt\values-lt.xml: AAPT: error: file failed to compile.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource compilation failed
C:\Users\bvenh\Documents\flutter\flutter_app_5\build\app\intermediates\incremental\mergeDebugResources\merged.dir\values-hr\values-hr.xml: AAPT: error: file failed to compile.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource compilation failed
C:\Users\bvenh\Documents\flutter\flutter_app_5\build\app\intermediates\incremental\mergeDebugResources\merged.dir\values-lv\values-lv.xml: AAPT: error: file failed to compile.
* 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 12s
Exception: Gradle task assembleDebug failed with exit code 1
I have tried everything!
I installed a new version of visual c++ as someone gave that as a solution to a question that was similar to mine on stack overflow.
I installed a new version of flutter
I installed a new version of Java JDK 1.8
I changed my user variables for JAVA_HOME & ANDROID_HOME
And it still does not work.
This is what flutter doctor outputs:
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 1.22.2, on Microsoft Windows [Version 10.0.18362.1139], locale en-NL)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[√] Android Studio (version 4.0)
[√] VS Code (version 1.50.1)
[√] Connected device (1 available)
• No issues found!
I use windows.
Old projects do work
So in short, what is the issue?
When I create a new project the default project (and all edits made after that) will result in a mergeDebugResources error, even without making any changes.
Does anyone know how to solve this?
Your help would be of major support!
It seems it is a Gradle issue. From this thread: https://github.com/flutter/flutter/issues/51690 There is this possible fix posted (updating Gradle version).
In gradle/wrapper/gradle-wrapper.properties try changing:
https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
to
https\://services.gradle.org/distributions/gradle-5.6.3-all.zip
There is also a stack overflow answer here:
https://stackoverflow.com/a/61156603/13714686
Which goes into detail about fixing this issue by changing Gradle settings.
I had same issue with my project and searched for an answer for hours. The solution was actually quite unexpected...
In Windows 10 "Security Options," I turned off the option of ransomware and tried to run the project and it worked. I don't know if this will solve the issue, but consider this as one option if same problem is encountered in future.

Flutter Project is not running when using indian domain

I created a project using following command on windows environment
flutter create --org in.myorg helloworld
Project is created successfully
Flutter version is as below
Flutter 1.9.1+hotfix.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 1aedbb1835 (3 weeks ago) • 2019-10-17 08:37:27 -0700
Engine • revision b863200c37
Tools • Dart 2.5.0
When I run the code I get following error
e: D:\Project\test\helloworld\android\app\src\main\kotlin\in\myorg\helloworld\MainActivity.kt: (1, 9): Package name must be a '.'-separated identifier list
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details
* 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 12s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 13.5s
Gradle task assembleDebug failed with exit code 1
.in domains are not allowed in flutter? using an incorrect domain will face issue while publishing app?
Yes, because in is one of Kotlin reserved keywords: keyword-reference
You can fix it by set Java as your Android platform language and not Kotlin.
Also, I think that this word is also reserved for Swift language.
I'm not sure if you can switch it on the fly but you can recreate your project with:
flutter create -i objc -a java command