The Target URI doesn't Exist:'package:firebase_database/firebase_database.dart'; - firebase

Importing Dependencies in Pubsec.Yaml is successfull,
But when opening main.dart file it shows the error
Problem(1)
The Target URI doesn't Exist:
'package:firebase_database/firebase_database.dart';

Either
flutter packages get
needs to be run or failed when you run it
or you just need to restart your IDE. I saw it mentioned a few times recently that this was necessary to fix the problem.

1- Go to the link: https://pub.dev/packages/firebase_database#-installing-tab-
2- Add dependencies in pubspec.yaml file.e.g:-
dependencies:
flutter:
sdk: flutter
firebase_database: ^3.1.3
3- Press ctrl+s after two seconds it will give a message click on Get Dependencies, and wait for some time its will run pub get in your project.
4- Problem will be solved.

Related

Flutter: Firebase has not been correctly initialized

I'm working on iPhone 12 Pro Max Emulator, macOS Catalina.
I'm getting this error when I try to run the app:
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized.
Also there is a tip in the console:
Usually this means you've attempted to use a Firebase service before calling Firebase.initializeApp.
I initialize the Firebase before use it. Like this:
void main() async {
print('-- main');
WidgetsFlutterBinding.ensureInitialized();
print('-- WidgetsFlutterBinding.ensureInitialized');
await Firebase.initializeApp();
print('-- main: Firebase.initializeApp');
runApp(const MyApp());
}
This is what I see in the console output:
Xcode build done. 132.9s
flutter: -- main
flutter: -- WidgetsFlutterBinding.ensureInitialized
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized.
Usually this means you've attempted to use a Firebase service before calling `Firebase.initializeApp`.
I can't see the -- main: Firebase.initializeApp line in the console. So it fails in first trying to initialize the Firebase.
I create Android/Apple apps in Firebase. Downloaded google-services.json / GoogleService-Info.plist and put in the project.
GoogleService-Info.plist:
google-services.json:
I'm not using the android, but I added dependency into build.gradle: classpath 'com.google.gms:google-services:4.3.10'
And app/build.gradle: apply plugin: 'com.google.gms.google-services'
dependencies:
firebase_auth: ^3.3.5
firebase_messaging: ^10.0.9
google_sign_in: ^5.2.1
flutter --version:
Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 18116933e7 (3 months ago) • 2021-10-15 10:46:35 -0700
Engine • revision d3ea636dc5
Tools • Dart 2.14.4
How can I solve this problem? BTW, I'm working on a brand new flutter project.
When you add google-services.json to an iOS project, you need to add it using Xcode as described in the following document:
https://firebase.flutter.dev/docs/manual-installation/ios
If you read through the page, you'll find the following note:
adding [google-service.json] manually via the filesystem won't link the file to the project
You need to try that then restart your app (rebuild it).
Edit: Additional Note:
You'll also need to add firebase_core to your dependencies in pubspec.yaml.
You have to add the GoogleService-Info.plist in Xcode instead of just placing it into the folder:
So it looks like this:
Note: The file can also be moved to a sub folder in the project (i.e. Runner).
Source: https://www.kindacode.com/article/flutter-correctly-adding-googleservices-info-plist-to-ios/
Here's how I fixed this error:
Ensure that all firebase services have been added to your pubspec.yaml file, in the dependencies section. firebase_core appears to be missing and is required to connect your flutter app to your firebase project.
You can simply add it using this command:
flutter pub add firebase_core
Add the firebase plugins to your main file:
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
Replace your void main function with an asynchronous one:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const YourAppGoesHere());
}
When I add the GoogleService-Info.plist file in Xcode, I used the wrong name GoogleService-Info**(1)**.plist.
If you have the same file in downloads, mac adds a number of copy to the next downloaded file.

firebase_analytics 0.0.4 which requires SDK version >=1.8.0 <2.0.0, version solving failed

I am trying to learn mobile devt using flutter, dat and firebase. SO as a start I downloaded the chat app code from here
But I can't seem to run the code via vscode and android studio. Can anyone please help me figure out how to run this.
error is:
VScode:
{
"resource": "/C:/Users/Administrator/Downloads/flutter-chat-app-master/flutter-chat-app-master/lib/ChatMessageListItem.dart",
"owner": "dart",
"code": "uri_does_not_exist",
"severity": 8,
"message": "Target of URI doesn't exist: 'package:firebase_database/firebase_database.dart'.\nTry creating the file referenced by the URI, or Try using a URI for a file that does exist.",
"source": "dart",
"startLineNumber": 1,
"startColumn": 8,
"endLineNumber": 1,
"endColumn": 58,
"tags": []
}
this is the error when i run it in android studio.
C:\src\flutter\bin\flutter.bat --no-color packages get Running
"flutter packages get" in flutter-chat-app-master... The current
Dart SDK version is 2.3.0-dev.0.5.flutter-a1668566e5.
Because flutter_chat_app depends on firebase_analytics 0.0.4 which
requires SDK version >=1.8.0 <2.0.0, version solving failed. pub get
failed (1)
I was able to run other sample codes, one is from this so I know that my setup is working.
I already tried few possbile solutions but not working, I saw this , but did not solve my issue.
I think the error requires me to downgrade android sdk but I dont know where to do that. I just need to run so I can see what it looks and I can follow. thanks.
You are using SDK version 2.3 and the package firebase_analytics 0.0.4 requires SDK version >=1.8.0 <2.0.0.
Some dependencies of this project are out of the date.
cupertino_icons: ^0.1.2
firebase_auth: 0.7.0
google_sign_in: 3.2.4
cloud_firestore: 0.8.2+3
fluttertoast: ^2.0.7
image_picker: 0.4.12+1
shared_preferences: 0.4.3
firebase_storage: 1.0.4
cached_network_image: ^0.7.0
intl: ^0.15.7
Update all of them to the newest version.
After a lot of googling , reinstalling, downgrade, upgrade, package get(which never worked coz the error was in the way so it exits before it could 'get'), package upgrade etc, I was finally able to solve this.
The only problem I had was I did not know which version (or what is the latest) to use coz for some reason, it wasn't indicated in their list of "versions", or least it wasn't easy to find coz I always end up in this page. Simply putting these lines (and/or doing the answer above)
environment:
sdk: '>=2.1.0 <3.0.0'
dependencies:
flutter:
sdk: flutter
google_sign_in: ^0.3.1
firebase_analytics: ^0.0.4
firebase_auth: ^0.2.0
firebase_database: ^0.0.12
firebase_storage: ^0.0.5
in yaml did not solve it, although a lot of ppl claimed it did.
the only thing that solved it was when I happen to go in this page where it contains the correct and latest firebase versions that the latest Dart SDK where in my case - DART SDK 2.3 supports.
just get the current version to this You can search every plugin in the search bar.
my yaml looks like this now:
dependencies:
flutter:
sdk: flutter
image_picker: ^0.6.0+8
google_sign_in: ^4.0.1+3
firebase_analytics: ^3.0.1
firebase_auth: ^0.11.1+1
firebase_database: ^3.0.0
firebase_storage: ^3.0.0
Added steps which I am not sure if it is necessary, but I did it before the version correcting.
invalidate cache, restart
In relation with running the app itself, and not particular to firebase:
change gradle version by doing steps from here (because of some error with gradle not related to firebase) and look for answer of keviepanas
Fixed: i got thesame issue as when trying to run flutter upgrade, have tried all the fix online nothing seems to be working, all i deed was upgrade manually and boom, everything worked like magic
1.Download the latest stable version from https://flutter.dev/docs/get-started/install/windows
2.then copy the extracted folder to your flutter directory,
3 delete all files from your previous flutter directory, and paste in the current files
from the latest release
Note: do not delete the flutter sdk directory folder, of cause you cant cause it is already in use.
Summary: all you need do is download the latest version and replace the content(files)with your old flutter sdk files and you are good to go
This combination is working
environment:
sdk: ">=2.1.0<3.0.0"
dependencies:
firebase_core: ^0.3.4
firebase_auth: ^0.8.4+5
cloud_firestore: ^0.9.13+1
flutter:
sdk: flutter
Just try one of the previous versions. The latest one which is dev version is not worked for me. Using an old version worked for me.

Flutter Firebase (firebase_core) does not build on Android

When using the Firebase plugins and starting an Android build, I get the following error:
ERROR: Failed to resolve: com.google.firebase:firebase-core:
Affected Modules: app, firebase_core.
It works fine on iOS.
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
> Could not find com.google.firebase:firebase-core:.
Required by:
project :app
project :app > project :firebase_core
This issue was fixed in the 0.3.4 update of firebase_core, which is a dependency of other Flutter Firebase plugins. You should be able to get the fix with a "flutter packages upgrade".
https://github.com/flutter/plugins/pull/1464/files
This is an issue that occurs because FlutterFire is migrating to BoM.
To solve this issue for now, you should just use firebase_core: 0.3.1+1.
The ideal solution would be adding the following to your settings.gradle in your android module:
enableFeaturePreview('IMPROVED_POM_SUPPORT')
However, this might not work. In that case, you should revert to 0.3.1+1 for the moment.
You can find out more about it here.

FIREBASE FOR FLUTTER CodeLab not working on IOS sim

I'm pretty new to Flutter and want to add Firebase to my Flutter app. So I went through the Flutter Codelab:
enter link description here
However I am getting errors as soon as I add the Cloud_Firestore package to my Pubspec.yaml file:
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.8.2 # new
I continued hoping that a following activity would resolve the problem and created the GoogleService-Info.plist file and added that as instructed.
However I still get the errors and build fail.
Here are the errors:
Error output from Xcode build: ↳ 2019-01-21 10:19:17.576
xcodebuild[70286:12860097] [MT] PluginLoading: Required plug-in
compatibility UUID D7881182-AD00-4C36-A94D-F45FC9B0CF85 for plug-in at
path '~/Library/Application
Support/Developer/Shared/Xcode/Plug-ins/RealmPlugin.xcplugin' not
present in DVTPlugInCompatibilityUUIDs 2019-01-21 10:19:17.577
xcodebuild[70286:12860097] [MT] PluginLoading: Required plug-in
compatibility UUID D7881182-AD00-4C36-A94D-F45FC9B0CF85 for plug-in at
path '~/Library/Application
Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin' not present
in DVTPlugInCompatibilityUUIDs
** BUILD FAILED **
Any help with solving this would be really appreciated
Thanks
Ok so I found the answer. Not sure why it's happening, seems that it's due to a bug in cloud_firestore 0.8.0.
So if anyone else is having this error, do the following:
go to terminal, open your apps directory,
cd ios
pod update Firebase
That should fix it.

What happened with HTTP package in Dart 2.1?

With dart 2.0 and lower I was able to import the HTTP package directly without modifying my pubspec.yaml file.
I've opened an old project and I've got the error:
"Your application could not be compiled, because its dependencies could not be established.
That library is in a package that is not known. Maybe you forgot to mention it in your pubspec.yaml file?"
I had to go to pubpect.yaml file, and under dependencies I've added: "http: ^0.12.0" to make my project work again.
What happened, why was the HTTP package removed from dart core libraries?
https://github.com/flutter/flutter/wiki/Changelog#v025
v0.2.5
#15416 removed package:http from Flutter and replaced all usages with the HttpClient from dart:io. If you use package:http you must add it
as a dependency in your pubspec.yaml to continue using it.
See https://github.com/flutter/flutter/wiki/Changelog#v025
As the flutter has removed the http from dart.io, you can't directly use it without specifying the dependency in pubspec.yaml file.
open the flutter project and add the http library dependency as given below,
dependencies:
flutter:
sdk: flutter
shared_preferences: "^0.4.2"
http: ^0.12.0

Resources