Test Banner Ads don't load on Android 11.0 - Flutter - flutter

I have a flutter app setup to run google ads using the google_mobile_ads package. All packages are the most recent. I configured it for iOS & Android and the test ads are loading on iOS as expected but not on Android 11.0. This is only an issue on Android 11.0 - API R. When run on Android 9.0 - API 28 the test ads load.
My configuration:
AndroidManifest.xml
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-MY_APP_ID"/>
initState()
setState(() {
_banner = BannerAd(
adUnitId: 'ca-app-pub-3940256099942544/6300978111',
size: AdSize.fullBanner,
request: AdRequest(),
listener: bannerListener,
)..load();
});
where bannerListener is:
final BannerAdListener bannerListener = BannerAdListener(
onAdLoaded: (Ad ad) => print('Ad loaded.'),
onAdFailedToLoad: (Ad ad, LoadAdError error) {
ad.dispose();
print('Ad failed to load: $error');
},
onAdOpened: (Ad ad) => print('Ad opened.'),
onAdClosed: (Ad ad) => print('Ad closed.'),
);
When I run on Android I get the following error:
AdWidget requires Ad.load to be called before AdWidget is inserted into the tree
If I change the code up to split the ..load() to a different line I then get this error:
I/Ads (11598): Ad failed to load : 0
I/flutter (11598): Ad failed to load: LoadAdError(code: 0, domain: com.google.android.gms.ads, message: Internal error., responseInfo: ResponseInfo(responseId: null, mediationAdapterClassName: , adapterResponses: []))
I'm showing the banner with this code:
if (_banner == null)
SizedBox(height: 20)
else
Container(
height: 50,
child: AdWidget(ad: _banner!),
)
What am I doing wrong that the test Ads won't load on Android but iOS has no issue?

Related

Firebase Cloud Messaging (Flutter): Error message when subscribing to topic

I have included Firebase Messaging in my app and I am getting the following error when I try to subscribe to topics.
FLTFirebaseMessaging: An error occurred while calling method Messaging#subscribeToTopic, errorOrNil => {
NSLocalizedFailureReason = "Invalid registration response :'Error=INVALID_PARAMETERS'. It is missing 'token' field.";
}
flutter: subscription error: [firebase_messaging/unknown] An unknown error has occurred.
As you can see it simply says "An unknown error has occurred", which is not very helpful to me.
Here is my code which is meant to obtain permissions for push notifications, then gets the token and subscribes to a list of topics...
Future<void> requestMessagingPermission() async {
FirebaseMessaging messaging = FirebaseMessaging.instance;
NotificationSettings settings = await messaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
print('User granted permission: ${settings.authorizationStatus}');
if (settings.authorizationStatus == AuthorizationStatus.authorized) {
print('User granted notifiactions permission');
messaging.getToken().then((token) async {
print('Messaging token: $token');
//configure notification topics
//gets a list of strings (topic names) from provider and loops through them to subscribe to them all
GlobalProvider provider = context.read<GlobalProvider>();
if (provider.notificationTopicsSet == false) {
//subscribe to topics
for (var topic in provider.notificationTopics) {
print('topic subscribing... $topic');
try {
await messaging.subscribeToTopic(topic).then((value) => print('topic subscribed: $topic'));
} catch (e) {
print('subscription error: $e');
}
}
}
});
}
}
I am getting the same error in the console for every topic that is being looped through and subscribed to. The weird thing is that push notifications were working before, but now they don't seem to be.
I have tried updating Flutter to the latest version (3.3.7), I have tried updating both the Firebase Core package (2.1.1) and the Firebase messaging package to their latest versions (14.0.4) and I am still getting the error.
From pubspec.yaml:
firebase_core: ^2.1.1
firebase_messaging: ^14.0.4
What is this token that is missing? The subscribeToTopic() function only seems to take the topic name string. Am I missing something?
Thank you, any help will be greatly appreciated.
This ended up being only an issue with the iOS simulator. The error did not occur with the Android emulator and push notifications work fine on physical devices.

Login with Apple Id in Flutter?

Here is my login page, actually it should login, but I got error
I included sign in capabilities in XCODE
Xcode configurations all set
**
Error Message I got : Unhandled Exception: SignInWithAppleAuthorizationError(AuthorizationErrorCode.canceled, The operation couldn’t be completed. (com.apple.AuthenticationServices.AuthorizationError error 1001.))**
child: InkWell(
onTap: () async {
final credential =
await SignInWithApple.getAppleIDCredential(
scopes: [
AppleIDAuthorizationScopes.fullName,
AppleIDAuthorizationScopes.email,
],
);
print(credential);
context.read<SignInBloc>().add(
SignInEvent.signInWithApple(
appleToken: credential.authorizationCode,
),
);
},
Above is my function to sign in with Apple Id
App Identifier create to "Sign in with Apple" checkbox selection
like that

No ads found for ad unit - Mopub_flutter

I'm trying to implement Mopub into my Flutter project but I have some issues related to mopub_flutter package.
MopubAdManager class contains the IDs of Mopub stuff.
This is my initState:
void initState() {
try {
MoPub.init(MopubAdManager().publisherId, testMode: true).then((_) => {
loadRewardedAd(),
});
} catch (e) {
print('exception: ${e.toString()}');
}
super.initState();
This is the loadRewaredAd function
void loadRewardedAd() {
videoAd = MoPubRewardedVideoAd(MopubAdManager().rewardedAd, (result, args) {
setState(() {
var rewardedResult = '${result.toString()}____$args';
});
print('$result');
if (result == RewardedVideoAdResult.GRANT_REWARD) {
print('Grant reward: $args');
}
}, reloadOnClosed: true);
This is how I call the function inside a button with onPressed
RaisedButton(
child: Text('Show Video'),
onPressed: () async {
videoAd.load();
var result = await videoAd.isReady();
print('Is Ready $result');
if (result) {
videoAd.show();
}
},
),
Before touching the button, Mopub prints that line in console:
I/MoPub (30148): [com.mopub.network.TrackingRequest$1][onResponse] SDK Log - Successfully hit tracking endpoint: https://ads.mopub.com/m/open
After touching the Show Video button that appears in console:
V/AudioManager(30148): querySoundEffectsEnabled...
I/MoPub (30148): [com.mopub.mobileads.MoPubRewardedVideoManager][fetchAd] SDK Log - Loading rewarded ad request for ad unit 40825097a53247c5a91f9775d3f54298 with URL https://ads.mopub.com/m/ad?v=6&id=40825097a53247c5a91f9775d3f54298&nv=5.15.0&dn=HUAWEI%2CPOT-LX1%2CPOT-LX1&bundle=com.example.anket&z=%2B0300&o=p&cw=1080&ch=2259&w=1080&h=2340&sc=3.0&ct=2&av=1.0.0&abt=%7B%22tapjoy%22%3A%7B%22token%22%3A%221%22%7D%7D&ifa=mp_tmpl_advertising_id&dnt=mp_tmpl_do_not_track&tas=mp_tmpl_tas&mid=mp_tmpl_mopub_id&gdpr_applies=0&force_gdpr_applies=0&current_consent_status=unknown&vv=4&vver=1.3.4-Mopub&mr=1
I/MoPub (30148): [com.mopub.network.AdLoader][fetchAd] Ad requesting from AdServer: https://ads.mopub.com/m/ad
I/MoPub (30148): {"vv":"4","nv":"5.15.0","mid":"e458ffd9-db59-4753-9878-c923a99ef3fc","dn":"HUAWEI,POT-LX1,POT-LX1","sc":"3.0","current_consent_status":"unknown","vver":"1.3.4-Mopub","id":"40825097a53247c5a91f9775d3f54298","bundle":"com.example.anket","gdpr_applies":"0","ch":"2259","ifa":"fe6b229f-fa21-4367-ac77-f8437ef7ebb6","mr":"1","tas":"authorized","h":"2340","force_gdpr_applies":"0","dnt":"0","o":"p","ct":"2","abt":"{\"tapjoy\":{\"token\":\"1\"}}","cw":"1080","av":"1.0.0","v":"6","w":"1080","z":"+0300"}
I/flutter (30148): Is Ready false
I/MoPub (30148): [com.mopub.network.MultiAdResponse][parseSingleAdResponse] Ad server responded with:
I/MoPub (30148): {"content":"","metadata":{"x-adtype":"clear","x-backfill":"clear","x-refreshtime":60}}
I/MoPub (30148): [com.mopub.network.AdLoader$1][onErrorResponse] Ad server responded with:
I/MoPub (30148): No ads found for ad unit.
I/flutter (30148): Flutter mopub rewarded method error
I/flutter (30148): RewardedVideoAdResult.ERROR
Other Ad types such as banner, interstitial shows the same error.
I have created the ad units and copied the Ids to the MopubAdManager class but yet no ads appear in the app. I have tested the test Ids they work perfectly.
Did I skip something?

Flutter fireabse_admob Missing google_app_id

I searched and tryed some solutions but it didn't work for me.
AndroidManifest.xml bottom
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxx116788401~8xxxxxxxxx"/>
In AdvertClass
import 'dart:io';
class AdvertService {
static final AdvertService _instance = AdvertService._internal();
factory AdvertService() => _instance;
MobileAdTargetingInfo _targetingInfo;
final String _bannerAd = Platform.isAndroid
? 'ca-app-pub-6xxxxxxxxx01/xxxxxx5'
: 'ca-app-pub-67xxxxxxxx01/2xxxxxx';
AdvertService._internal() {
_targetingInfo = MobileAdTargetingInfo();
}
showBanner() {
print(_bannerAd);
BannerAd banner = BannerAd(
adUnitId: _bannerAd,
size: AdSize.smartBanner,
targetingInfo: _targetingInfo);
banner
..load()
..show();
banner.dispose();
}
}
build.gradle file android to buttom
android {
compileSdkVersion 28
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.flutter_app"
minSdkVersion 28
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
apply plugin: 'com.google.gms.google-services'
This code works with test id
InterstitialAd(adUnitId: InterstitialAd.testAdUnitId , targetingInfo: _targetingInfo);
But when I change it to my admob id gives error
Admob error
Also
I got verified Admob account.
I created key
I added my test device in
_targetingInfo = MobileAdTargetingInfo( testDevices: <String>["54a0a4f2"]);
Also I see it now it says
Firebase error
but My pubsec.yaml gots
firebase_admob: ^0.9.3+4
firebase_auth: ^0.16.0
cloud_firestore: ^0.13.5
firebase_core: ^0.4.4+3
I createa firebase app ,downlaod the json file and add it then it says this steps but I can't find it
Google json file
The error Missing google_app_id is only because of you didn't implement Firebase Analytics, it is only a reminder, and it doesn't affect the ads.
Initialized AdMob with appID before showing the banner ad
FirebaseAdMob.instance.initialize(appId: appId);
Also set test device id Found in your Admob error to prevent showing real ads in debug mode
MobileAdTargetingInfo(
...
testDevices: <String>["Your device id"], // Android emulators are considered test devices
);
Real Ads will be shown by the following steps:
Verified AdMob ac.
Sign Your App
Build Release if you have set your device test ID in Targeting Info.
Connect to Firebase Project

How to fix 'App not found' on iOS (AppAvailability)

I am launching a flutter app (App 1) from another flutter app (App 2) on Android and it works perfectly. However, I keep getting the same error on IOS. It does not recognize the package name.
I have tried with multiple apps but is the same result, it currently just recognizes the calendar package.
pubspec.yaml file flutter_appavailability
main.dart App 2
import 'package:flutter_appavailability/flutter_appavailability.dart';
//Future void method
if (Platform.isIOS) {
_installedApps = [
{"app_name": "example", "package_name": "com.flutter.example"},
];
print(await AppAvailability.checkAvailability("com.flutter.example")); //ERROR
//Widget build
return Container {
child : Row(
...
GestureDetector(
...
onTap: () {
Scaffold.of(context).hideCurrentSnackBar();
AppAvailability.launchApp(installedApps[0].["package_name"])
.then((_) {
print("App ${installedApps[0]["app_name"]} launched!");
}).catchError((err) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(
"App ${installedApps[0]["app_name"]} not found!")));
print(err);
});
...
),
}
info.plist App 1
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
project.pbxproj App 1
PRODUCT_BUNDLE_IDENTIFIER = com.flutter.example;
Output App 2
[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(, App not found com.flutter.example, null)
#0 AppAvailability.checkAvailability (package:flutter_appavailability/flutter_appavailability.dart:40:9)