Admob and Google Play not working together

I want to use this 2 plugins:

Admob:
https://code.google.com/p/google-mobile-dev/downloads/detail?name=UnityPlugin_Android_1.0.zip

Google Play:
https://github.com/playgameservices/play-games-plugin-for-unity

Each plugin alone runs fine. But when i try to use them both then i got this error:

Error building Player: CommandInvokationFailure: Unable to convert classes into dex format. See the Console for details.
/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/bin/java -Xmx1024M -Dcom.android.sdkmanager.toolsdir="/Users/lnmedia/Development/adt-bundle-mac-x86_64-20131030/sdk/tools" -Dfile.encoding=UTF8 -jar "/Applications/Unity/Unity.app/Contents/BuildTargetTools/AndroidPlayer/sdktools.jar" -

stderr[

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/google/ads/AdRequest$Gender;
	at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
	at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
	at com.android.dx.command.dexer.Main.processClass(Main.java:685)

The problem is that the play-games library now contains also the AdMob classes. Is it possible somehow to delete the duplicate classes in the JAR file? Or is here anyone who have another solution and is using admob and play services together? I want to avoid to write my own plugin, i just want to use existing ones if possible.

Thanks and have a nice day.

2 Likes

Ok, i found a solution. I deleted the ad folder inside google-play-services.jar Now both plugins work as they should.

Here is a link how to extract and repack a jar file:
http://stackoverflow.com/questions/16806112/how-to-remove-class-file-in-jar-file-and-change-it-with-my-own-implementation

AdMob is now a part of Google Play Game Services.

could you share your repacked jar, please?

I extracted google-play-services.jar and deleted ads folder. After that ads were ok, but playgameservices plugin started to send me weird exceptions:

02-12 05:15:14.099: I/Unity(13953): [Play Games Plugin DLL] GHM creating GameHelper.
02-12 05:15:14.099: I/Unity(13953):  
02-12 05:15:14.099: I/Unity(13953): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 53)
02-12 05:15:14.309: I/Unity(13953): AndroidJavaException: java.lang.ClassNotFoundException: com.google.example.games.basegameutils.GameHelper
02-12 05:15:14.309: I/Unity(13953):   at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <filename unknown>:0 
02-12 05:15:14.309: I/Unity(13953):   at UnityEngine.AndroidJNISafe.CallStaticObjectMethod (IntPtr clazz, IntPtr methodID, UnityEngine.jvalue[] args) [0x00000] in <filename unknown>:0 
02-12 05:15:14.309: I/Unity(13953):   at UnityEngine.AndroidJavaObject._CallStatic[AndroidJavaObject] (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0

I didn’t delete GameHelper so it class must be there. Did anybody meet that strange behaviour?

Hi I have hit the same issue… Did you find a solution?

hi,

even if it is a little late. I had the same issue a few days ago. Here the repacked lib. (I had to add an empty .txt to the archiv, because I was not able to pack it in a .zip otherwise :wink: )

Regards
Kalle

1553241–91233–$lib.zip (1.2 MB)

Hi Kalle, i tried your zip but it din show leaderboards… so i made changes to my own play-services.jar file…
Here is the file unzip and just replace default with this file in Assets\Plugins\Android\google-play-services_lib\libs and it will work.

1659517–103754–google-play-services.zip (1.8 MB)

1 Like

It’s part of play services now. Upgrade in the admob website, and do this:

Do as i say and it will work like a charm…
Assuming you already have the proper unity plugins for admob and play services.
1) Import both and do the required.
2) Now go to Plugin and search for google-play-services.jar file
3) Do not unzip google-play-services.jar goinside it using services like 7-zip or winrar.
4) Go inside that and search for ads folder and delete it.(I am at office so m not sure of its Directory)
5) Delete ads folder.

1 Like

Hi, i solved this problem.

Implement admob unity plugin to sample project first which includes creating adactivity.jar file from eclipse. [Reference video :

]

Now in your main project implement unity leaderboard official plugin first and make it working after adding the application id successfully. [GitHub - playgameservices/play-games-plugin-for-unity: Google Play Games plugin for Unity]

  • After implementing it, simply add GoogleMobileAdsDemoScript.cs in your Asset folder from sample admob project (e.g. HelloWorld from admob plugin example)

  • Add GoogleMobileAds folder from sample admob project to Asset folder of working project

  • Now add AndroidManifest file from sample project following folder C:…Project folder\Assets\Plugins\Android to the respective folder of your main project

  • Add GoogleMobileAdsPlugin folder to C:…Project folder\Assets\Plugins\Android

  • Now add adactivity.jar from your sample project’s libs folder C:…Project folder\Assets\Plugins\Android\google-play-services_lib\libs to your main project respective libs folder.

And it works that way. Hope it helps.

Maybe it’s too late to answer, I was facing the same issue, I created a plugin this plugin contains Facebook SDK+Admob+unityads +unity IAP, all of them work together, I’ve created this plugin in unity 5.6.0, but I’ve checked it, it is working fine in unity 2017 as well, there is a scene “DemoScene”, just open it everything is implemented, unity ads, admob, facebook share with callback, unityIAP.

Note: before importing the plugin kindly delete all the old plugins, also go to services and turn on unity ads.
http://www.mediafire.com/file/ccvj7ixir8ive25/FB_ADMOB_UnityIAP_UnityAds_Plugin_Hameed_Ullah_jan.unitypackage