Adding Admob to flutter App causes it to crash on startup - firebase

I am trying to add Admob to a flutter app.
I followed this tutorial:
https://www.youtube.com/watch?v=rXYmbTBT3Yo
as well as the official documentation for the plugin:
https://github.com/flutter/plugins/tree/master/packages/firebase_admob
I added these lines to my app/src/main/AndroidManifest.xml:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-#~#" />
Replacing the #~# I copied from the add app ui in the AdMob page.
I also added this dependency in the pubspec.yaml file:
firebase_admob: ^0.9.0+1
But when I load the app, it gets to:
Built build\app\outputs\apk\debug\app-debug.apk.
Installing build\app\outputs\apk\app.apk...
The app flashes on the screen and closes. I also couldn't find any way of showing the error. What am I doing wrong?

I hope that you will have solved that problem yet. If no, then changing the version of firebase_admob in pubspec.yaml file to 0.5.3 will solve your problem inshaAllah. Just change the version from 0.9.0+1 to 0.5.3

Related

FlutterFirebaseCorePlugin.java uses or overrides a deprecated API

Ok so I run my program without importing firebase core, firebase auth and cloud firestore, and my code runs just fine but I register my app with firebase and it still runs fine but as soon as I import Firebase_auth, Firebase_core and cloud_Firestore... I get the following error
Note: C:\appflutter\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_core-0.7.0\android\src\main\java\io\flutter\plugins\firebase\core\FlutterFirebaseCorePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\appflutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-0.16.0\android\src\main\java\io\flutter\plugins\firebase\firestore\streamhandler\TransactionStreamHandler.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
D8: Cannot fit requested classes in a single dex file (# methods: 89543 > 65536)
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
The number of method references in a .dex file cannot exceed 64K.
Please help me.
I was having the same problem today and I found the solution here on Github
First, get the latest versions of your dependencies from pub.dev
Current latest versions are these:
firebase_auth: ^0.20.0+1
firebase_core: ^0.7.0
Then run these 3 commands in the terminal:
$ flutter pub upgrade
$ flutter pub get
$ flutter clean
And then run your project
$ flutter run
This will hopefully help you.
Seems it is a bug in Firebase plugins: https://github.com/FirebaseExtended/flutterfire/issues/3876. However setting min SDK to 23 does not show the warning.
it worked for me to change my sdkVersion to 23:
just go to android>app>build.gradle and
change the minSdkVersion-line in defaultConfig{} to .. minSdkVersion 23
$ flutter pub get
Just Do it in your Terminal it will work
Enable multidex in android project & run again.
I am suggesting this according to the last part of the error message you've posted.
According to this guide: https://firebase.flutter.dev/docs/installation/android#enabling-multidex
However, if your minSdkVersion is set to 20 or lower, then you must use the multidex support library and make the following modifications to your app project
In android - app - build.gradel file
add - implementation 'com.android.support:multidex:1.0.3' in dependencies section
add - multiDexEnabled true in default config section enter image description here
enter image description here
Suffered the error of FlutterFirebaseCorePlugin.java uses or overrides a deprecated API. for two days.
finally solved it by changing minSdkVersion to 21 in app/build.gradle and run the app with flutter run --no-sound-null-safety.
Found that the error comes from the sound null safety implementation which grey lists all incompatible API
There are two issues here, -Xlint and multidex.
For -Xlint, #Sarib's solution worked for me and both the -Xlint errors disappeared after running flutter pub upgrade, flutter pub get and flutter clean. You can find them under Tools > Flutter in Android Studio if you are not familiar with Terminal.
For multidex, according to the Android Studio User Guide, multidex is enabled by default if your minSdkVersion is 21 or higher. While #Joshi suggests enabling multidex, I think it is simpler to update the minSdkVersion in android/app/build.gradle file to 21 or higher, rather than mess with more variables and adding more dependencies, assuming you're building an app that targets Android21 or higher.
For this error:
Note: locationInD\flutter\plugins\firebase\core\FlutterFirebaseCorePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
The solution I found was to replace this line in android/app/build.gradle:
implementation 'com.google.firebase:firebase-analytics-ktx'
with
implementation 'com.google.firebase:firebase-analytics'
For me i changed one of my implementation version from
implementation platform('com.google.firebase:firebase-bom:27.1.0') to
implementation platform('com.google.firebase:firebase-bom:26.6.0')
at the moment there are some bugs in this current version "27.1.0" and after running the application it worked
//To help someone my project needed this implementation for my ads #admob
change to minSdkVersion 24
in android/app/build.gradle
dependencies {
//add this in your dependencies
implementation "androidx.multidex:multidex:2.0.0"
}
then
$ flutter clean
$ flutter run
I had the same issue and combined two suggested fixes to get it to finally work:
minSdkVersion 21, change to 23
run "flutter pub upgrade"
= issues fixed!
To double-check what the fix was:
I also reverted back to 21 and invalidated + flutter clean and the issue appeared again. Then I changed to 23 and the warnings disappeared!
Check your minSDK, it works fine for 23

How to know which version of Google Firebase plugin to use in Flutter app?

I've been stuck with Gradle not building (working on iOS fine). I struggled because Gradle was giving a generic error, finally got this today:
FAILURE: Build failed with an exception.
* What went wrong: Failed to capture fingerprint of input files for task ':app:preDebugBuild' property 'compileManifests' during up-to-date check.
> In project 'app' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[18.0. 0]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown.
Dependency failing: com.google.firebase:firebase-messaging:18.0.0 -> com.google.firebase:firebase-iid#[18.0.0], but fire base-iid version was 17.1.2.
The following dependencies are project dependencies that are direct or have transitive dependencies that lead to the art ifact with the issue. -- Project 'app' depends on project 'firebase_messaging' which depends onto com.google.firebase:firebase-messaging#18.0. 0
-- Project 'app' depends on project 'firebase_core' which depends onto com.google.firebase:firebase-core#16.0.9 -- Project 'app' depends on project 'firebase_analytics' which depends onto com.google.firebase:firebase-analytics#16.5. 0 -- Project 'app' depends on project 'firebase_remote_config' which depends onto com.google.firebase:firebase-config#16.4 .1 -- Project 'app' depends onto com.google.firebase:firebase-core#16.0.9
For extended debugging info execute Gradle from the command line with ./gradlew --info :app:assembleDebug to see the dep endency paths to the artifact. This error message came from the google-services Gradle plugin, report issues at https:// github.com/google/play-services-plugins and disable by adding "googleServices { disableVersionCheck = false }" to your b uild.gradle file.
* 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
This was after I took out the version numbers from my pubspec to see if that would help. I don't understand Google's version numbering and I'm not sure which versions of plugins I should be installing as it has caused conflicts in the past:
dependencies:
flutter:
sdk: flutter
http:
cached_network_image:
flutter_cache_manager:
carousel_pro:
cloud_firestore:
firebase_core:
firebase_remote_config:
dynamic_theme:
flutter_signin_button:
shared_preferences:
share:
flutter_search_bar:
google_sign_in:
#flutter_facebook_login:
flutter_html:
requests:
webview_flutter:
flutter_webview_plugin:
firebase_analytics:
flutter_app_badger: #for launcher badge icon (notifications)
uuid:
font_awesome_flutter:
device_info:
carousel_slider:
flutter_spinkit:
flutter_typeahead:
firebase_messaging:
html_unescape:
flutter_masked_text:
configurable_expansion_tile:
stripe_payment:
square_in_app_payments:
Google doesn't seem to maintain consistent version numbering and by taking out the version numbers I thought it would at least take the latest version of the plugins which theoretically should work. So, how can I solve this?
You should begin by putting the version number back in there.
This is an issue with firebase / play services versions being mismatched so you know for sure the other plugins in your pubspec.yaml are fine.
The dependancy which is failing is firebase messaging.
It's using many words to tell you
com.google.firebase:firebase-messaging:18.0.0 package depends on com.google.firebase:firebase-iid#[18.0.0]
but it's only finding 17.1.2.
You need
com.google.firebase:firebase-core#16.0.9
com.google.firebase:firebase-analytics#16.5.0
com.google.firebase:firebase-config#16.4.1
in the future, if you are having version issues check the specific packages GitHub issues to see if there's anything currently wrong with the version you're on. This will save you a lot of time.
I wouldn't recommend removing version numbers from your pubsepc.yaml but if you type
firebase_messaging: any
It will get a compatible version for you.
The error you are getting is not necessarily from the packages you have listed in pubspec.yaml. It is referring to the dependencies on build.gradle.
Google has no issue with the version numbers. There is a difference between the versions of packages i.e what you have listed on pubspec.yaml and the dependencies on app/build.gradle. It would be wise to reconsider the number of packages you use as every package has a dependency and you may end up in a sticky situation where multiple packages are conflicting. In addition you end up with a bloated solution for minimal functionality.
Removing version numbers will not help as some packages are incompatible. I would suggest you start with the packages you require i.e the firebase which from experience have no issues then incrementally add if necessary.

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.

flutter version conflict with location and firebase_messaging

I am using two plugin with my flutter app location: ^1.4.1 and firebase_messaging: ^2.0.0
If I use single one its works fine but together
What went wrong:
Failed to capture snapshot of input files for task ':app:preDebugBuild' property 'compileManifests' during up-to-date check.
> The library com.google.android.gms:play-services-basement is being requested by various other libraries at [[15.0.1,15.0.1]], but resolves to 16.0.1. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
flutter clean
trying to downgrade version for both plugin
and google search
non of the above works for me.
app level build: implementation 'com.google.firebase:firebase-core:16.0.1'
project level build: classpath 'com.google.gms:google-services:4.0.1'
Thanks
:)
In your Project - Goto Android > App > build.gradle
Right after the apply plugin: 'com.google.gms.google-services' at the bottom of your build.gradle the following can be added to work around the issue.
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

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