bdlukaa / native_admob_flutter

Easy-to-make native ads in flutter using AdMOB SDK.
https://pub.dev/packages/native_admob_flutter
BSD 3-Clause "New" or "Revised" License
80 stars 56 forks source link

native ads are crashing app on loading #48

Closed SureshKumar311 closed 3 years ago

SureshKumar311 commented 3 years ago

hello guys i am app i use native ads but now its was crashing

plz help me guys

my :: pubspec.yaml

description: A new Flutter project.

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  connectivity: ^3.0.3

  native_admob_flutter: ^1.2.4
  # admob_flutter: ^1.0.1

  intl: ^0.17.0
  shared_preferences: ^2.0.5

  # flutter_spinkit: ^4.1.2old

  # fluttertoast: ^8.0.3
  fluttertoast: ^7.1.8
  flutter_inappwebview: ^5.2.1+1
  # flutter_inappwebview: ^4.0.0+4 old
  # webview_flutter: ^1.0.7

  #state management
  get: ^4.1.4
  get_storage: ^2.0.2

  # downloader --
  path_provider: ^2.0.1
  #old  path_provider: ^1.6.27
  # flutter_downloader: ^1.5.2
  flutter_downloader: ^1.6.0
  permission_handler: ^6.1.1
  # permission_handler: ^6.0.1+1 old

  # authentication--
  firebase_auth: ^1.0.1
  # oldgoogle_sign_in: ^4.5.3
  google_sign_in: ^5.0.1
  provider: ^5.0.0

  cloud_firestore: ^1.0.3
  # firebase_core : ^1.0.0 old
  firebase_core: ^1.0.2
  firebase_crashlytics: ^1.0.0
  #ui designe
  # flutter_native_splash:
  shimmer: ^1.1.2
  lottie:
  flutter_gradients:
  carousel_pro: ^1.0.0
  flutter_spinkit: ^5.0.0
  animated_widgets: ^1.0.6
  flutter_svg: ^0.19.3
  adobe_xd: ^1.1.0+1

  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2

dev_dependencies:
  flutter_launcher_icons: ^0.8.0
  #change_app_package_name: ^0.1.2
  flutter_native_splash: 
  flutter_test:
    sdk: flutter
flutter_icons:

  android: true
  ios: true
  image_path: "assets/bluebook.png"

flutter_native_splash:

  # This package generates native code to customize Flutter's default white native splash screen
  # with background color and splash image.
  # Customize the parameters below, and run the following command in the terminal:
  # flutter pub run flutter_native_splash:create
  # To restore Flutter's default white splash screen, run the following command in the terminal:
  # flutter pub run flutter_native_splash:remove

  # color or background_image is the only required parameter.  Use color to set the background
  # of your splash screen to a solid color.  Use background_image to set the background of your
  # splash screen to a png image.  This is useful for gradients. The image will be stretch to the
  # size of the app. Only one parameter can be used, color and background_image cannot both be set.
  # color: "#42a5f5"
  color: "#FFFFFF"
  #background_image: "assets/background.png"

  # Optional parameters are listed below.  To enable a parameter, uncomment the line by removing 
  # the leading # character.

  # The image parameter allows you to specify an image used in the splash screen.  It must be a 
  # png file.  
  image: assets/bluebook.png

  # The color_dark, background_image_dark, and image_dark are parameters that set the background
  # and image when the device is in dark mode. If they are not specified, the app will use the
  # parameters from above. If the image_dark parameter is specified, color_dark or 
  # background_image_dark must be specified.  color_dark and background_image_dark cannot both be
  # set.
  #color_dark: "#042a49"
  #background_image_dark: "assets/dark-background.png"
  #image_dark: assets/splash-invert.png

  # The android, ios and web parameters can be used to disable generating a splash screen on a given 
  # platform.
  android: true
  ios: false
  web: false

  # The position of the splash image can be set with android_gravity, ios_content_mode, and
  # web_image_mode parameters.  All default to center.
  #
  # android_gravity can be one of the following Android Gravity (see 
  # https://developer.android.com/reference/android/view/Gravity): bottom, center, 
  # center_horizontal, center_vertical, clip_horizontal, clip_vertical, end, fill, fill_horizontal,
  # fill_vertical, left, right, start, or top.
  android_gravity: center
  #
  # ios_content_mode can be one of the following iOS UIView.ContentMode (see 
  # https://developer.apple.com/documentation/uikit/uiview/contentmode): scaleToFill, 
  # scaleAspectFit, scaleAspectFill, center, top, bottom, left, right, topLeft, topRight, 
  # bottomLeft, or bottomRight.
  #ios_content_mode: center
  #
  # web_image_mode can be one of the following modes: center, contain, stretch, and cover.
  #web_image_mode: center

  # To hide the notification bar, use the fullscreen parameter.  Has no affect in web since web 
  # has no notification bar.  Defaults to false.
  # NOTE: Unlike Android, iOS will not automatically show the notification bar when the app loads.
  #       To show the notification bar, add the following code to your Flutter app:
  #       WidgetsFlutterBinding.ensureInitialized();
  #       SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom, SystemUiOverlay.top]);
  fullscreen: true

  # If you have changed the name(s) of your info.plist file(s), you can specify the filename(s) 
  # with the info_plist_files parameter.  Remove only the # characters in the three lines below,
  # do not remove any spaces:
  #info_plist_files:
  #  - 'ios/Runner/Info-Debug.plist'
  #  - 'ios/Runner/Info-Release.plist'

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:

  assets:
   - assets/anna.jpg
   - assets/014-girl-13.svg
   - assets/004-notebook.svg
   - assets/006-school.svg
   - assets/calculator.png
   - assets/calculator.svg
   - assets/score.svg
   - assets/trophy.svg
   - assets/certification.svg
   - assets/student.svg
   - assets/ece.png
   - assets/bluebook.png
   - assets/bg1.png
   - assets/tech.json
   - assets/code.json
   - assets/gift.json
   - assets/teaching.json
   - assets/developer.png
   - assets/loading.json
   - assets/server-error.json
   - assets/page-error.json
   - assets/images/ex1.png
   - assets/nointernet.json
   - assets/no-internet-connection.json
   - assets/editnointernet.json
   - assets/nointernetout.json

  # assets:
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

my code:

import 'package:au_updates/main.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'package:au_updates/screen/settings.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_gradients/flutter_gradients.dart';

import 'package:au_updates/calculator/Courses/IT.dart';
import 'package:au_updates/calculator/Courses/Mech.dart';
import 'package:au_updates/calculator/Courses/Civil.dart';
import 'package:au_updates/calculator/Courses/Eee.dart';
import 'package:au_updates/calculator/Courses/Bme.dart';
import 'package:au_updates/calculator/Courses/cse.dart';
import 'package:au_updates/calculator/Courses/ece.dart';
import 'package:lottie/lottie.dart';
import 'package:native_admob_flutter/native_admob_flutter.dart';

class Gpapage extends StatefulWidget {
  @override
  _GpapageState createState() => _GpapageState();
}

String router1;
String router2;
String _valuedept = "Select Department";

class _GpapageState extends State<Gpapage> {
  final interstitialAd = InterstitialAd();
//unitId: initalunit()
  List<String> deptments = [
    "ECE",
    "EEE",
    "CSE",
    "IT",
    "BME",
    "MECH",
    "CIVIL",
    "Select Department",
  ];
  @override
  void initState() {
    if (!interstitialAd.isLoaded) interstitialAd.load();
    interstitialAd.onEvent.listen((e) {
      final event = e.keys.first;
      switch (event) {
        case FullScreenAdEvent.closed:
          // Here is a handy place to load a new interstitial after displaying the previous one
          interstitialAd.load();
          // Do not show an ad here
          break;
        default:
          break;
      }
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: appbarcolour,
        title: Text(
          'Anna University GPA Calculator',
          style: TextStyle(
              fontSize: 21,
              fontWeight: FontWeight.bold,
              color: appbartextcolour),
          textAlign: TextAlign.center,
        ),
        elevation: 01,
      ),
      body: SafeArea(
        child: Container(
          decoration: BoxDecoration(gradient: FlutterGradients.newYork()),
          child: Center(
            child: Column(children: <Widget>[
              SizedBox(
                height: 2,
              ),
              // Container(
              //   height: 150,
              //   child: imageCarousel(context, adsenable: true),
              // ),
              Expanded(
                child: Container(
                  height: 200,
                  child: NativeAd(
                    builder: (context, child) {
                      return Container(
                        child: child,
                      );
                    },
                    buildLayout: adbuilder,
                    loading: Lottie.asset("assets/loading.json"),
                    error: Lottie.asset("assets/page-error.json"),
                    //Text('Error in ADs Server \n Please report to developer'),
                    icon: AdImageView(size: 100, padding: EdgeInsets.all(5)),
                    ratingBar: AdRatingBarView(
                        elevationColor: Colors.white, height: 20),
                    store: AdTextView(
                      style: TextStyle(
                        fontSize: 12,
                        fontWeight: FontWeight.normal,
                        color: Colors.amber[300],
                      ),
                    ),
                    button: AdButtonView(
                      pressColor: Colors.white,
                      padding: EdgeInsets.all(10),
                      textStyle: TextStyle(
                          fontSize: 20,
                          fontWeight: FontWeight.bold,
                          color: Colors.black54,
                          letterSpacing: 0.3),
                    ),
                    headline: AdTextView(
                      style: TextStyle(
                        fontSize: 20,
                        fontWeight: FontWeight.bold,
                        color: Colors.white,
                      ),
                      maxLines: 1,
                    ),
                    media: AdMediaView(height: 80, width: 120),
                  ),
                ),
              ),

AdLayoutBuilder get adbuilder => (ratingBar, media, icon, headline, advertiser,
        body, price, store, attribution, button) {
      return AdLinearLayout(
        gravity: LayoutGravity.center,
        padding: EdgeInsets.all(10),
        // The first linear layout width needs to be extended to the
        // parents height, otherwise the children won't fit good
        height: MATCH_PARENT,
        width: MATCH_PARENT,
        orientation: HORIZONTAL,
        decoration: AdDecoration(
          gradient: AdRadialGradient(
            colors: [Colors.blue, Colors.blue],
            center: Alignment(0.5, 0.5),
            radius: 1000,
          ),
        ),

        children: [
          icon,
          AdLinearLayout(
            gravity: LayoutGravity.left,
            padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
            // height: 0.5,
            children: [
              headline,
              AdLinearLayout(
                gravity: LayoutGravity.left,
                padding: EdgeInsets.fromLTRB(0, 10, 0, 0),
                children: [
                  attribution,
                  AdLinearLayout(
                    gravity: LayoutGravity.left,
                    padding: EdgeInsets.fromLTRB(10, 0, 0, 0),
                    children: [
                      ratingBar,
                      advertiser,
                      AdLinearLayout(
                        gravity: LayoutGravity.left,
                        padding: EdgeInsets.fromLTRB(10, 0, 0, 0),
                        children: [store],
                        orientation: HORIZONTAL,
                        width: WRAP_CONTENT,
                      ),
                    ],
                    orientation: HORIZONTAL,
                    width: WRAP_CONTENT,
                  ),
                ],
                orientation: HORIZONTAL,
                width: WRAP_CONTENT,
              ),
              AdLinearLayout(
                gravity: LayoutGravity.left,
                padding: EdgeInsets.fromLTRB(0, 10, 10, 3),
                children: [
                  button,
                ],
                width: 230,
              ),
            ],
            margin: EdgeInsets.all(5),
          ),
        ],
      );

error log on visual code :

D/EgretLoader(15947): EgretLoader(Context context)
D/EgretLoader(15947): The context is not activity
I/DynamiteModule(15947): Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:210890500
I/DynamiteModule(15947): Selected remote version of com.google.android.gms.ads.dynamite, version >= 210890500
2
W/ResourceType(15947): No package identifier when getting name for resource number 0x00000000
W/ResourceType(15947): ResTable_typeSpec entry count inconsistent: given 67, previously 69
W/ResourceType(15947): ResTable_typeSpec entry count inconsistent: given 5625, previously 5626
D/DynamitePackage(15947): Instantiating com.google.android.gms.ads.ChimeraNativeAdViewDelegateCreatorImpl
I/zygote64(15947): Do full code cache collection, code=250KB, data=165KB
I/zygote64(15947): After code cache collection, code=242KB, data=132KB
I/zygote64(15947): Do partial code cache collection, code=249KB, data=135KB
I/zygote64(15947): After code cache collection, code=249KB, data=135KB
I/zygote64(15947): Increasing code cache capacity to 1024KB
D/TransportRuntime.SQLiteEventStore(15947): Storing event with priority=HIGHEST, name=FIREBASE_CRASHLYTICS_REPORT for destination cct
D/TransportRuntime.JobInfoScheduler(15947): Scheduling upload for context TransportContext(cct, HIGHEST, MSRodHRwczovL2NyYXNobHl0aWNzcmVwb3J0cy1wYS5nb29nbGVhcGlzLmNvbS92MS9maXJlbG9nL2xlZ2FjeS9iYXRjaGxvZ1xBSXphU3lCcnBTWVQ0RkZMMDlyZUhKaTZIOUZZZGVpU25VVE92Mk0=) with jobId=372847150 in 20117ms(Backend next call timestamp 1619615312293). Attempt 1

error for firebase Crashlytics :

       at com.bruno.native_admob_flutter.native.NativeAdKt.applyText(NativeAd.kt:338)
       at com.bruno.native_admob_flutter.native.NativeAdPlatformView.buildView(NativeAd.kt:85)
       at com.bruno.native_admob_flutter.native.NativeAdPlatformView.buildView(NativeAd.kt:81)
       at com.bruno.native_admob_flutter.native.NativeAdPlatformView.buildView(NativeAd.kt:81)
       at com.bruno.native_admob_flutter.native.NativeAdPlatformView.build(NativeAd.kt:52)
       at com.bruno.native_admob_flutter.native.NativeAdPlatformView.<init>(NativeAd.kt:235)
       at com.bruno.native_admob_flutter.native.NativeViewFactory.create(NativeAd.kt:30)
       at io.flutter.plugin.platform.SingleViewPresentation.onCreate(SingleViewPresentation.java:186)
       at android.app.Dialog.dispatchOnCreate(Dialog.java:403)
       at android.app.Dialog.show(Dialog.java:302)
       at android.app.Presentation.show(Presentation.java:249)
       at io.flutter.plugin.platform.VirtualDisplayController.<init>(VirtualDisplayController.java:95)
       at io.flutter.plugin.platform.VirtualDisplayController.create(VirtualDisplayController.java:48)
       at io.flutter.plugin.platform.PlatformViewsController$1.createVirtualDisplayForPlatformView(PlatformViewsController.java:207)
       at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:104)
       at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:59)
       at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
       at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
       at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
       at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
       at android.os.MessageQueue.next(MessageQueue.java:331)
       at android.os.Looper.loop(Looper.java:149)
       at android.app.ActivityThread.main(ActivityThread.java:6635)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
bdlukaa commented 3 years ago

Please downgrade the version to 1.2.1 until the next release (in about 6 hours)

bdlukaa commented 3 years ago

Fixed in 1.3.0