adMob.jar图书馆和谷歌播放service.jar中不携手合作中不、图书馆、adMob、jar

2023-09-08 18:45:54 作者:夜在熬我

我有市场,adMod旗帜上的应用程序,现在我想一些谷歌地图API添加到我的应用程序。

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

我知道如何处理adMobs库或谷歌地图API分开。但是,当我尝试运行与AdMob的和谷歌地图API(谷歌Play业务)的应用程序,它似乎他们有碰撞或类似的东西。或谷歌播放-services.jar和GoogleAdMobAdsSdk.jar对AdMob的相同的类名。也许由于这个原因,我越来越多.dex文件。

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:

麻烦写输出:已经prepared [2014年5月18日18时24分40秒 - 地塞米松装载机]无法执行DEX:多DEX文件定义LCOM /谷歌/广告/ AdRequest $错误code; [2014年5月18日18时24分40秒 - WorkC 3.0.9动作条]转换为的Dalvik格式失败:无法执行DEX:多DEX文件定义LCOM /谷歌/广告/ AdRequest $错误code;

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;

恐怕这将是坏我的AdMob的,只要我更新的应用程序版本。我该如何解决呢?

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

推荐答案

您可以摆脱jar文件中,并使用谷歌播放服务,为双方的广告和地图。做以下修改:

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

在你的布局,更改从广告XML命名空间:

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"

   -----/>

要:

 <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" />

要:

<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="***************" />

需要注意的是广告:loadAdOnCreate不再可用,因此你必须加载通过Java code中的广告在你的onCreate():

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"/>

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

地址:

 <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"/>