skip to Main Content

I created a small app which worked fine on the android emulator so far (Pixel XL – API 33).

I wanted to try out google ads and added the google_mobile_ads: ^1.2.0 to the pubspec.yaml file. This caused a build error and told me that the minSDK needs to be at least 19 instead of 16.
I went into my flutter SDK folder and changed the minSdkVersion set in this file: flutterpackagesflutter_toolsgradleflutter.gradle
Trying to build the app again created a new build error telling me that MultiDex needs to be enabled.
So I went into the project/android/app/build.gradle and added multiDexEnabled true to the default config block.

Now the app builds successfully but crashes on startup without any kind of message…
Reverting the changes from above fixed it again.

Any ideas what I am doing wrong?

2

Answers


  1. Chosen as BEST ANSWER

    I forgot to add the Application ID in the AndroidManifest. After some research, I found out that this is a common problem with google mobile ads. If the application id is not provided the app will just crash on startup.

    After adding this it seems to work:

    <meta-data android:name="com.google.android.gms.ads.APPLICATION_ID"
                android:value="[YOUR_APPLICATION_ID]"/>
    

  2. It’s possible that your app is running out of memory due to the addition of the Google Mobile Ads SDK, which requires enabling multidex support. Here are a few things you can try:

    • Make sure you have the latest version of the Google Mobile Ads SDK installed in your app. You can check the latest version on the official Google Mobile Ads SDK documentation.

    • Increase the memory limit of your app. You can do this by adding android:largeHeap="true" to the tag in your AndroidManifest.xml file.

    • Try to enable ProGuard by adding minifyEnabled true and shrinkResources true to your app/build.gradle file. This can help reduce the size of your app and prevent potential memory issues.

    • Check the logs of your app to see if there are any error messages or exceptions being thrown. You can do this by running the app in debug mode and using Android Studio’s logcat to view the logs.

    • Try running your app on a physical device instead of the emulator to see if the issue persists.

    Hopefully, one of these solutions will help you identify and fix the issue with your app.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search