How to fix gradle error in flutter project - firebase

I am getting this gradle error when running flutter project:
I am using code from github for flutter pdf view and also using firebase for it.
Launching lib\main.dart on AOSP on IA Emulator in debug mode...
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-0.0.4+3/lib/src/path_provider_windows_real.dart:126:25: Error: The getter 'addressOf' isn't defined for the class 'GUID'.
- 'GUID' is from 'package:win32/src/structs.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/win32-1.7.4+1/lib/src/structs.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'addressOf'.
knownFolderID.addressOf, KF_FLAG_DEFAULT, NULL, pathPtrPtr);
^^^^^^^^^
^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/ffi-0.1.3/lib/src/utf16.dart:16:7: Error: Struct 'Utf16' is empty. Empty structs are undefined behavior.
class Utf16 extends Struct {
^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/ffi-0.1.3/lib/src/allocation.dart:47:33: Error: Expected type 'T' to be a valid and instantiated subtype of 'NativeType'.
final int totalSize = count * sizeOf<T>();
^
FAILURE: Build failed with an exception.
* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1035
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\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 28s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
Plz help me I have got these gradle errors many time.
Thanks

Delete the .idea folder , build folder and pubspec.lock file, then it will work just fine.

Related

Flutter build fails [Execution failed for "cloud_firestore-3.1.12".]

**FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring project ':cloud_firestore'.
Could not load compiled classes for build file 'C:\src\flutter.pub-cache\hosted\pub.dartlang.org\cloud_firestore-3.1.12\android\build.gradle' from cache.
Failed to notify project evaluation listener.
Could not get unknown property 'android' for project ':cloud_firestore' of type org.gradle.api.Project.
Could not find method implementation() for arguments [project ':firebase_core'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Could not get unknown property 'android' for project ':cloud_firestore' of type org.gradle.api.Project.
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 3s
Exception: Gradle task assembleDebug failed with exit code 1**
my current flutter project which uses the following firebase packages
cloud_firestore: ^3.1.12
firebase_core: ^1.14.1
firebase_auth: ^3.3.14
firebase_storage: ^10.2.12
firebase_messaging: ^11.2.13

Build failed when I try to run my flutter app

I attached what I got in debug console when I try to run my app.
These are my firebase dependencies
firebase_core: ^1.12.0
firebase_auth: ^3.3.8
cloud_firestore: ^3.1.9
Launching lib\main.dart on ***** in debug mode...
/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_platform_interface-6.2.0/lib/src/method_channel/utils/exception.dart:14:11: Error: Method not found: 'Error.throwWithStackTrace'.
Error.throwWithStackTrace(exception, stackTrace);
^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_platform_interface-6.2.0/lib/src/method_channel/utils/exception.dart:17:9: Error: Method not found: 'Error.throwWithStackTrace'.
Error.throwWithStackTrace(
^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_platform_interface-6.2.0/lib/src/method_channel/utils/exception.dart:12:7: Error: A non-null value must be returned since the return type 'Never' doesn't allow null.
Never convertPlatformException(Object exception, StackTrace stackTrace) {
^
FAILURE: Build failed with an exception.
* Where:
Script 'C:\src\flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 991
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\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 21s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
I have tried many methods, But they didn't work.
try flutter clean and then flutter run it work for me
flutter version 2.10.4
My first guess is that you might not finish platform-specific installation/setup for Firebase as well as Firebase plugins.
Just to verify that You can visit the FlutterFire website which will guide you through the installation steps for the targeting platforms for Firebase and plugin setup;
Otherwise, the flutter clean and flutter pub get should do the trick.
However, a problem still exists, you can restart your editor and just run the command flutter pub get/ flutter pub upgrade.

Fail to clone and run a flutter app from GitHub (Timy-messenger)

I have been trying to clone and run this time-messenger app from GitHub. But I keep getting this error. I tried flutter doctor, flutter clean, flutter build apk (which also gave an error), flutter pub cache repair, flutter pub get and so on but it didn't work.
This is the error I'm getting:
punreachrany#Punreachs-MacBook-Pro timy-messenger-master % flutter run
Using hardware rendering with device sdk gphone x86 arm. If you get graphics
artifacts, consider enabling software rendering with
"--enable-software-rendering".
Launching lib/main.dart on sdk gphone x86 arm in debug mode...
Compiler message:
../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_platform_w
idgets-0.20.2/lib/src/platform_scaffold.dart:229:38: Error: The getter
'fullObstruction' isn't defined for the class 'ObstructingPreferredSizeWidget'.
- 'ObstructingPreferredSizeWidget' is from
'package:flutter/src/cupertino/page_scaffold.dart'
('../../../Developer/flutter/packages/flutter/lib/src/cupertino/page_scaffold.d
art').
Try correcting the name to the name of an existing getter, or defining a getter
or field named 'fullObstruction'.
final obstruct = navigationBar.fullObstruction == null ||
^^^^^^^^^^^^^^^
../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_platform_w
idgets-0.20.2/lib/src/platform_scaffold.dart:230:25: Error: The getter
'fullObstruction' isn't defined for the class 'ObstructingPreferredSizeWidget'.
- 'ObstructingPreferredSizeWidget' is from
'package:flutter/src/cupertino/page_scaffold.dart'
('../../../Developer/flutter/packages/flutter/lib/src/cupertino/page_scaffold.d
art').
Try correcting the name to the name of an existing getter, or defining a getter
or field named 'fullObstruction'.
navigationBar.fullObstruction;
^^^^^^^^^^^^^^^
Compiler message:
../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_platform_widgets-0.20.2/lib/src/platform_scaffold.dart:229:38: Error: The getter 'fullObstruction' isn't defined for the class 'ObstructingPreferredSizeWidget'.
- 'ObstructingPreferredSizeWidget' is from 'package:flutter/src/cupertino/page_scaffold.dart' ('../../../Developer/flutter/packages/flutter/lib/src/cupertino/page_scaffold.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'fullObstruction'.
final obstruct = navigationBar.fullObstruction == null ||
^^^^^^^^^^^^^^^
../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_platform_widgets-0.20.2/lib/src/platform_scaffold.dart:230:25: Error: The getter 'fullObstruction' isn't defined for the class 'ObstructingPreferredSizeWidget'.
- 'ObstructingPreferredSizeWidget' is from 'package:flutter/src/cupertino/page_scaffold.dart' ('../../../Developer/flutter/packages/flutter/lib/src/cupertino/page_scaffold.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'fullObstruction'.
navigationBar.fullObstruction;
^^^^^^^^^^^^^^^
Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
build failed.
FAILURE: Build failed with an exception.
* Where:
Script '/Users/punreachrany/Developer/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 882
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/Users/punreachrany/Developer/flutter/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 9s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 9,7s
Exception: Gradle task assembleDebug failed with exit code 1
punreachrany#Punreachs-MacBook-Pro timy-messenger-master %
What can I try next?
Project Link : https://github.com/janoodleFTW/timy-messenger
Change the version number of flutter_platform_widgets to ^0.32.4 in pubspec.yaml, then run flutter packages upgrade
Source

Flutter build error.(related to pub-cache)

When I tried to build my project, I get this error printed in my console.
everything was working fine 2 days ago.
Here is the error,
Running "flutter pub get" in SampleApp...
Launching lib\main.dart on Android SDK built for x86 in debug mode...
/E:/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/top_level.dart:1:8: Error: Not found: 'dart:html'
import 'dart:html';
^
/E:/flutter/.pub-cache/hosted/pub.dartlang.org/js-0.6.2/lib/js.dart:8:1: Error: Not found: 'dart:js'
export 'dart:js' show allowInterop, allowInteropCaptureThis;
^
/E:/flutter/.pub-cache/hosted/pub.dartlang.org/js-0.6.2/lib/js_util.dart:8:1: Error: Not found: 'dart:js_util'
export 'dart:js_util';
^
/E:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_svg-0.17.4/lib/src/picture_stream.dart:88:26: Error: Type 'DiagnosticableMixin' not found.
class PictureStream with DiagnosticableMixin {
^^^^^^^^^^^^^^^^^^^
/E:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_svg-0.17.4/lib/src/picture_stream.dart:192:44: Error: Type 'DiagnosticableMixin' not found.
abstract class PictureStreamCompleter with DiagnosticableMixin {
^^^^^^^^^^^^^^^^^^^
FAILURE: Build failed with an exception.
* Where:
Script 'E:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 896
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'E:\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 4m 13s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
I really don't know why is this is happening, i tried googling but couldn't find anything useful.
There are more errors, related to .pub-cache, but i didn't post it, as then the question would be too long.
Please help.
The error is in the "Firebase" package, remove that, and it's working.
To be specific on what needs to be done to help others who are seeing this issue , I am explaining it below :
When you somehow add below import statement, you are likely to see this issue :
import 'package:firebase/firebase.dart';
Find and remove above line, clean your build (by running flutter clean command) and run again. Issue should be resolved by now.

AppCenter build error: Project firebaseauth_web at : is either no Android app project or build version has not been set to override

I have a mobile project in flutter and I am trying to build it on AppCenter but I got this error:
Project firebaseauth_web at : is either no Android app project or build version has not been set to override. Skipping...
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/runner/.pub-cache/hosted/pub.dartlang.org/firebase_auth_web-0.1.3+1/android/build.gradle' line: 22
* What went wrong:
A problem occurred evaluating root project 'firebaseauth_web'.
> Failed to apply plugin [id 'com.android.library']
> Minimum supported Gradle version is 5.4.1. Current version is 4.10.2. If using the gradle wrapper, try editing the distributionUrl in /Users/runner/.pub-cache/hosted/pub.dartlang.org/firebase_auth_web-0.1.3+1/android/gradle/wrapper/gradle-wrapper.properties to gradle-5.4.1-all.zip
* 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 4s
The plugin firebase_auth_web could not be built due to the issue above.
##[error]The process '/bin/bash' failed with exit code 1
##[error]Bash failed with error: The process '/bin/bash' failed with exit code 1
##[section]Finishing: Post Clone Script
##[section]Starting: Checkout Chofu#master to s
==============================================================================
Task : Get sources
Description : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version : 1.0.0
Author : Microsoft
Help : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
==============================================================================
Cleaning any cached credential from repository: Chofu (ExternalGit)
##[section]Finishing: Checkout Chofu#master to s
##[section]Starting: Finalize Job
Cleaning up task ***
Start cleaning up orphan processes.
Terminate orphan process: pid (1490) (java)
Terminate orphan process: pid (1470) (java)
Terminate orphan process: pid (1462) (java)
Terminate orphan process: pid (1404) (java)
Terminate orphan process: pid (1289) (adb)
##[section]Finishing: Finalize Job
##[section]Finishing: Build
My gradle version is actually 6.1.1.
Here is my gradle-wrapper.properties from android/gradle code:
...
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
...
I have tried to change the version to 5.4.1 but I got a similar error:
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/runner/runners/2.170.1/work/1/s/android/app/build.gradle' line: 24
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.internal.version-check']
> Minimum supported Gradle version is 6.1.1. Current version is 5.4.1. If using the gradle wrapper, try editing the distributionUrl in /Users/runner/runners/2.170.1/work/1/s/android/gradle/wrapper/gradle-wrapper.properties to gradle-6.1.1-all.zip
* 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 'assembleRelease'... 19.8s
Gradle task assembleRelease failed with exit code 1
EDITED:
After a better look I discover other 2 errors:
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':appcenter:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> 1 exception was raised by workers:
com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
/Users/runner/.gradle/caches/transforms-2/files-2.1/469951e99791312bb8bf182873580e29/core-1.1.0/res/values/values.xml:142:5-173:25: AAPT: error: resource android:attr/fontVariationSettings not found.
/Users/runner/.gradle/caches/transforms-2/files-2.1/469951e99791312bb8bf182873580e29/core-1.1.0/res/values/values.xml:142:5-173:25: AAPT: error: resource android:attr/ttcIndex not found.
* 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.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':appcenter_analytics:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> 1 exception was raised by workers:
com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
/Users/runner/.gradle/caches/transforms-2/files-2.1/469951e99791312bb8bf182873580e29/core-1.1.0/res/values/values.xml:142:5-173:25: AAPT: error: resource android:attr/fontVariationSettings not found.
/Users/runner/.gradle/caches/transforms-2/files-2.1/469951e99791312bb8bf182873580e29/core-1.1.0/res/values/values.xml:142:5-173:25: AAPT: error: resource android:attr/ttcIndex not found.
If someone could help me I would be grateful!
After one month of struggle I found how to solve the problem:
I have changed gradle version from android/gradle/wrapper/gradle-wrapper.properties from 6.1.1 to 5.6.2 . So my file looks like:
...
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
...
In android/build.gradle I have changed gradle tool version from 4.0.0 to 3.5.0:
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
...
}
In android/app/build.gradle I have added checkReleaseBuilds false to lintOptions :
lintOptions {
...
checkReleaseBuilds false
}
In android/app/appcenter-post-clone.sh I have added two builds before --release build:
...
# build APK
flutter build apk --debug
flutter build apk --profile
flutter build apk --release
...
I hope this will help others :)

Resources