Can´t use adMob api since I updated to API 19

2019-08-29 20:38发布

问题:

Alright, If I include the .jar of the adMob sdk, it will conflict with the google play services API and the app wont compile because of the following error:

Unable to execute dex: Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode;

If I dont include the adMob .jar on the exports, it will crash on runtime because the app couldnt find the classes required for the ad and it displays this message on my layout file:

The following classes could not be instantiated:
- com.google.ads.AdView

What now? It broke after I updated to API 19. Im using the google play services API revision 13 and version 6.4.1 of the adMob .jar.

回答1:

Here's what I did. Remove the AdMob.jar. Remove all your imports relating to AdMob stuff. Then follow this guide to update your code, because the API has changed somewhat.



回答2:

Most probably you need this line in your manifest file as direct element of application tag:

<meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />