googleads / googleads-mobile-flutter

A Flutter plugin for the Google Mobile Ads SDK
Apache License 2.0
343 stars 285 forks source link

Ads are not showing inside in case of releaase mode #679

Closed parmeetmaster closed 1 year ago

parmeetmaster commented 2 years ago

Plugin version is google_mobile_ads: ^2.1.0

I configure Gradle in such a way

Gradle ```gradle def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def keystoreProperties = new Properties() def keystorePropertiesFile = rootProject.file('key.properties') if (keystorePropertiesFile.exists()) { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) } def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") } def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0' } apply plugin: 'com.android.application' // START: FlutterFire Configuration apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.firebase.crashlytics' // END: FlutterFire Configuration apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { compileSdkVersion 33 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } sourceSets { main.java.srcDirs += 'src/main/kotlin' } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.anime.animekill" minSdkVersion 21 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName multiDexEnabled true } signingConfigs { release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null storePassword keystoreProperties['storePassword'] } } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. // proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' // signingConfig signingConfigs.debug signingConfig signingConfigs.release } } buildFeatures { viewBinding true } } flutter { source '../..' } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'com.github.MonsterTechnoGits:WebViewAdblock:1.1' implementation 'androidx.appcompat:appcompat:1.5.0' implementation 'com.android.support:multidex:1.0.3' implementation 'com.google.android.gms:play-services-ads:21.3.0' implementation 'com.google.ads.mediation:facebook:6.11.0.1' //implementation 'com.github.gundy:semver4j:0.16.4' } ```

AdHelper class such way:

dart ```dart import 'dart:async'; import 'dart:io'; import 'package:flutter/material.dart'; import 'package:google_mobile_ads/google_mobile_ads.dart'; import 'dart:math'; class AdHelper { var _interstitialAd; BannerAd? banner1 = null; BannerAd? banner2 = null; BannerAd? homeBanner = null; bool reduceAds = false; /* final NativeAdListener navtiveAdListener = NativeAdListener( // Called when an ad is successfully received. onAdLoaded: (Ad ad) => print('Ad loaded.'), // Called when an ad request failed. onAdFailedToLoad: (Ad ad, LoadAdError error) { // Dispose the ad here to free resources. ad.dispose(); print('Ad failed to load: $error'); }, // Called when an ad opens an overlay that covers the screen. onAdOpened: (Ad ad) => print('Ad opened.'), // Called when an ad removes an overlay that covers the screen. onAdClosed: (Ad ad) => print('Ad closed.'), // Called when an impression occurs on the ad. onAdImpression: (Ad ad) => print('Ad impression.'), // Called when a click is recorded for a NativeAd. onAdClicked: (Ad ad) => print('Ad clicked.'), ); */ Future initalisation() async { print("MobileAds.instance.initialize "); MobileAds.instance.initialize(); MobileAds.instance.updateRequestConfiguration( RequestConfiguration( tagForChildDirectedTreatment: TagForChildDirectedTreatment.unspecified, testDeviceIds: ["5C05B21E815B95F0F629B8DCCA92102D"]), ); } Future _createInterstitialAd() async { final c = new Completer(); // complete will be called in 3 seconds by the timer. await InterstitialAd.load( adUnitId: "ca-app-pub-1699034135614013/6934631017", request: AdRequest(), adLoadCallback: InterstitialAdLoadCallback( onAdLoaded: (InterstitialAd ad) { print('$ad loaded'); _interstitialAd = ad; _interstitialAd!.setImmersiveMode(true); c.complete(); }, onAdFailedToLoad: (LoadAdError error) { print(error); }, )); return c.future; } Future showInterlisationAds() async { await _createInterstitialAd(); if (_interstitialAd == null) { print('Warning: attempt to show interstitial before loaded.'); return; } _interstitialAd!.fullScreenContentCallback = FullScreenContentCallback( onAdShowedFullScreenContent: (InterstitialAd ad) { print('ad onAdShowedFullScreenContent.'); }, onAdDismissedFullScreenContent: (InterstitialAd ad) { print('$ad onAdDismissedFullScreenContent.'); reduceAds = true; ad.dispose(); // displayInterstitialAd(); }, onAdFailedToShowFullScreenContent: (InterstitialAd ad, AdError error) { print('$ad onAdFailedToShowFullScreenContent: $error'); ad.dispose(); // displayInterstitialAd(); }, ); _interstitialAd!.show(); _interstitialAd = null; } void showInertialAdsRandom() { // reduce ads are enable so everytime open screen ads are loaded until its show once if (reduceAds) { if (Random().nextInt(100) % 2 == 0) { showInterlisationAds(); } } else { showInterlisationAds(); } } Future loadBannerAdDescriptionScreen({ required BannerAdListener banner1Listener, required BannerAdListener bannerAd2Listener, }) async { banner1 = BannerAd( adUnitId: 'ca-app-pub-1699034135614013/8467984789', size: AdSize.banner, request: AdRequest(), listener: banner1Listener, )..load(); banner2 = BannerAd( adUnitId: 'ca-app-pub-1699034135614013/8038747551', size: AdSize.banner, request: AdRequest(), listener: bannerAd2Listener, )..load(); } Future loadHomeBanner( {required BannerAdListener homeBannerListener}) async { homeBanner = await BannerAd( adUnitId: 'ca-app-pub-1699034135614013/7173904780', size: AdSize.banner, request: AdRequest(), listener: homeBannerListener, ) ..load(); } Widget getBannerAd() { return Container(height: kToolbarHeight, child: AdWidget(ad: banner1!)); } Widget getBannerAd2() { return Container(height: kToolbarHeight, child: AdWidget(ad: banner2!)); } Widget getHomeBanner() { return Container(height: kToolbarHeight, child: AdWidget(ad: homeBanner!)); } disposeBanner() { banner1!.dispose(); banner2!.dispose(); } /* Widget getNativeAds() { final nativeAds = NativeAd( adUnitId: 'ca-app-pub-1699034135614013/4163043735', factoryId: 'adFactory', request: AdRequest(), listener: navtiveAdListener, )..load(); final AdWidget adWidget = AdWidget(ad: nativeAds); return Container(child: adWidget); }*/ } ```
huycozy commented 2 years ago

Hi @parmeetmaster, please provide a completed and minimal reproducible code sample so that we may verify this. In this case, it also contains Android native configuration, please create a Github repository for this and make it public so that we can access it.

Also, you can try running google_mobile_ads/example in release mode to check if the issue can reproduce.

Thank you!

parmeetmaster commented 2 years ago

Hello @huycozy

Please refer my repository complete.I need this error to fix so i can reveal my whole work.Just run app via flutter run --release

https://github.com/parmeetmaster/animekillnewapp.git

huycozy commented 2 years ago

Hi @parmeetmaster Thanks for providing the repository but it's a complex production code. For the issue to be workable, it needs to be reproducible with a completed and minimal reproducible code sample that doesn’t include 3rd party plugins or complex production code.

Also, you can try running google_mobile_ads/example in release mode to check if the issue can reproduce.

Thank you!

parmeetmaster commented 2 years ago

Please use 3 steps: Just clone the repository. ==> https://github.com/parmeetmaster/animekillnewapp.git

Run this command :

1) flutter pub get

2) flutter pub run build_runner watch --delete-conflicting-outputs

3) flutter run --release

huycozy commented 2 years ago

Hi @parmeetmaster The goal of this Github repo is not to give assistance on personal code or the whole package/plugin project, but to improve googleads-mobile-flutter plugin reporting bugs or feature requests.

In this case, you provide a complex production code where the issue can be caused by your own implementation or other components inside project. So, please provide a completed and minimal reproducible code sample that represents the problem.

Instead, if you think that the issue might depend on your implementation, please see flutter's community for resources and ask questions like this. You may also get some help if you post it on Stack Overflow and flutterhelp.

Thank you!

github-actions[bot] commented 1 year ago

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones. Thanks for your contribution.