1

I have an app on the market with adMod banner, and now I am trying to add some Google Maps api to my application.

I know how to handle adMobs library or Google Maps api separately. But when I try to run the app with adMob and Google Maps api (Google Play service), it seems they have a collision or something like that. Or google-play-services.jar and GoogleAdMobAdsSdk.jar have the same class name for AdMob. Maybe due to that reason I am getting multiple .dex files.

My error on my console is:

trouble writing output: already prepared [2014-05-18 18:24:40 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode; [2014-05-18 18:24:40 - WorkC 3.0.9 actionBar] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode;

I'm afraid it would be bad to my adMob as soon as I update the application version. How can I fix that?

2 Answers2

3

You can get rid of the jar file and use the google play services for both ads and maps. Make the following changes:

In your layout, Change the ad xml namespace from:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

   -----/>

To :

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"

   ----/>

Then, Change:

 <com.google.ads.AdView 
 android:id="@+id/ad"
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content"
 android:layout_gravity="bottom|center" 
 android:layout_marginTop="300dp" 
 ads:adSize="BANNER"
 ads:adUnitId="***************" 
 ads:loadAdOnCreate="true" />

To :

<com.google.android.gms.ads.AdView
 android:id="@+id/ad"
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content"
 android:layout_gravity="bottom|center" 
 android:layout_marginTop="300dp" 
 ads:adSize="BANNER"
 ads:adUnitId="***************" />

Note that ads:loadAdOnCreate is no longer available so you'd have to load the ad via java code in your onCreate():

AdView adView = (AdView)this.findViewById(R.id.ad);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);

Then in your manifest's application tag, Change:

<activity android:name="com.google.ads.AdActivity"/>

to:

<activity android:name="com.google.android.gms.ads.AdActivity" 
                  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

Add:

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

Don't forget the permissions:

 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
   <uses-permission android:name="android.permission.INTERNET"/>
Nana Ghartey
  • 7,901
  • 1
  • 24
  • 26
1

You don't need adMob.jar file. Google Play Services (4.3.23) will suffice.

See : https://developers.google.com/mobile-ads-sdk/docs/?hl=fr https://developer.android.com/google/play-services/setup.html#Install

shemsu
  • 1,066
  • 9
  • 17
  • thank's butnow i need to change some statement in the manifest and my xml layout. example now i have this code: android:name="com.google.ads.AdActivity" and in xml: –  May 18 '14 at 16:22