# Several Android-specific questions, while integrating Ads Mediation (15+ networks)

**URL:** <https://forum.defold.com/t/several-android-specific-questions-while-integrating-ads-mediation-15-networks/68026>\
**Category:** Questions\
**Created:** [April 6, 2021, 1:20pm UTC](https://forum.defold.com/t/several-android-specific-questions-while-integrating-ads-mediation-15-networks/68026 "2021-04-06T13:20:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexeyFeskov](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/alexeyfeskov/32/1203_2.png) [@AlexeyFeskov](https://forum.defold.com/u/AlexeyFeskov)\
**Post date:** [April 6, 2021, 1:20pm UTC](https://forum.defold.com/t/several-android-specific-questions-while-integrating-ads-mediation-15-networks/68026/1 "2021-04-06T13:20:19Z")

</div>

I’m trying to develop [native extension for AppLovin Max](https://github.com/alexeyfeskov/defold-maxsdk) ads mediation (WIP Android only - AdColony, AppLovin, Pangle, Facebook, InMobi, Smaato, Tapjoy, Verizon, Vungle only adapters for now)

First, I want to say a “Great thank you” to @AGulev for [Unity Ads](https://github.com/AGulev/DefVideoAds) and [new-admob](https://github.com/defold/extension-admob/tree/5fb021d036d6afe7e26b45a0dce8e06c32cb69bc/extension-admob) (which I use as template and example - I couldn’t have done anything without them).  
And then I describe the problems faced while integrating ad-networks AAR-packages (and that may face anyone who will integrate ads mediation):

✅ Java 8 Support (Smaato, Verizon) and `element <queries> in <manifest>` (AdMob, InMobi, myTarget, Pangle)  
**Workaroud:** Use [Defold 1.2.181 BETA](https://forum.defold.com/t/defold-1-2-181-beta/67881/) (or above) with D8 support

✅ Facebook Ads  
Got an runtime-error on ads initialization:

```lua
Can't load Audience Network Dex. Please, check that audience_network.dex is inside of assets folder.
java.io.FileNotFoundException: audience_network.dex

```

Related to [#5710](https://github.com/defold/defold/issues/5710)  
**Workaroud:** Manually add custom assets to [native extension resources](https://defold.com/manuals/extensions/#project-layout). In my case - copy `audience-network-sdk-6.3.0.aar/assets/audience_network.dex` to `myextension/res/android/assets/audience_network.dex`.  
(also already there is [PR](https://github.com/defold/defold/pull/5720) - thanks Defold devs for fast fix)

✅ 3rd party activity from ARR  
Got an runtime-error while opening [Mediation Debugger activity](https://dash.applovin.com/documentation/mediation/android/testing-networks/mediation-debugger):

```lua
...
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.applovin.sdk.R$layout" on path: DexPathList[[zip file "/data/app/com.defold.applovinexample/base.apk"],nativeLibraryDirectories=[/data/app/com.defold.applovinexample/lib/arm, /data/app/com.defold.applovinexample/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib, /data/downloads, /data/priv-downloads]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
...

```

**Workaroud:** add package name to [ext.manifest aaptExtraPackages section](https://defold.com/manuals/extensions/#the-extmanifest-file) to force AAPT2 to generate `R.class` file in package namespace. (`'com.applovin.sdk'` in my case).  
I’m not sure this is expected behaviour and I didn’t found this in navive extension manuals.

❌ Mintegral (not solved)  
Got an runtime-error on ads initialization:

```lua
...
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mintegral.msdk.out.MTGConfiguration" on path: DexPathList[[zip file "/data/app/com.defold.applovinexample/base.apk"],nativeLibraryDirectories=[/data/app/com.defold.applovinexample/lib/arm, /data/app/com.defold.applovinexample/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib, /data/downloads, /data/priv-downloads]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
...

```

Class `com.mintegral.msdk.out.MTGConfiguration` is present in `classes2.dex` (but not in main DEX) - seems related to legacy-multidex problem. Also this error may be related to [Fb+Push issue](https://forum.defold.com/t/defold-1-2-181-beta/67881/35)

I tried to set minSdk=21 or change in manifest `<application android:name="androidx.multidex.MultiDexApplication">` to avoid legacy-multidex but it didn’t help.

❌ AdMob / Google Ad Manager and Applovin conflict (not solved)  
`com.applovin:applovin-sdk:10.1.2` and `com.google.android.gms:play-services-ads:19.8.0` contains conflicting dependencies, got an D8 Compilation failed error:

```lua
Error in /tmp/.gradle/unpacked/com.google.android.gms-play-services-measurement-base-18.0.0.aar/classes.jar:com/google/android/gms/internal/measurement/zze.class:
Type com.google.android.gms.internal.measurement.zze is defined multiple times: /tmp/.gradle/unpacked/com.google.android.gms-play-services-measurement-base-18.0.0.aar/classes.jar:com/google/android/gms/internal/measurement/zze.class, /tmp/.gradle/unpacked/com.google.android.gms-play-services-measurement-impl-16.4.0.aar/classes.jar:com/google/android/gms/internal/measurement/zze.class
Compilation failed

```

I tried to play around ext.manifest [aaptExcludePackages section](https://defold.com/manuals/extensions/#allowed-keys), but looks like section is obsolete and I’ve got `Error in 'extension-maxsdk/ext.manifest': Manifest context variable unsupported: aaptExcludePackages`.

❌ myTarget (not solved)  
Got an extender-error:

```lua
Missing 'package' key attribute on element package at [:com.my.target.mytarget-sdk-5.11.3:] 
AndroidManifest Validation failed

```

Not sure but it may be related to [manifest-merger version](https://github.com/defold/extender/blob/24a7cd83e7e5595eb9aacc50066dada417bb2dc7/server/manifestmergetool/build.gradle#L39) don’t support Android 11 specific manifests.

And I will be grateful for any clues how to solve problems above…

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [April 6, 2021, 1:30pm UTC](https://forum.defold.com/t/several-android-specific-questions-while-integrating-ads-mediation-15-networks/68026/2 "2021-04-06T13:30:48Z")

</div>

Note that we just now had to revert the support for `d8` in the 1.2.181 BETA because it didn’t work with certain packages (e.g. facebook). [http://d.defold.com/beta/](http://d.defold.com/beta/) (ff5b94e)

---

<div class="post-metadata">

**Author:** ![AlexeyFeskov](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/alexeyfeskov/32/1203_2.png) [@AlexeyFeskov](https://forum.defold.com/u/AlexeyFeskov)\
**Post date:** [April 6, 2021, 4:29pm UTC](https://forum.defold.com/t/several-android-specific-questions-while-integrating-ads-mediation-15-networks/68026/3 "2021-04-06T16:29:27Z")

</div>

Sad to hear this… But in any case, I’m happy with the fact that now we always can to build and run extender locally. And for me it’s a good opportunity to learn Docker at last.

PS I’m not sure (not an android specialist) but seems to run with `--release` flag D8 multidex behavior similar to DX (place classes in main dex while 64k methods limit not reached), but may affect other unwanted properties (strip debug info etc.)

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [April 6, 2021, 9:39pm UTC](https://forum.defold.com/t/several-android-specific-questions-while-integrating-ads-mediation-15-networks/68026/4 "2021-04-06T21:39:25Z")

</div>

> [@Mathias\_Westerdahl](#):
>
> Note that we just now had to revert the support for `d8` in the 1.2.181 BETA

> [@AlexeyFeskov](#):
>
> Sad to hear this

We will reintroduce d8 support in the next release again.

> [@AlexeyFeskov](#):
>
> seems to run with `--release` flag D8 multidex behavior

I believe --debug is default for d8. But for it to work the java classes must be compiled (using javac) with the -g option to include the required debug info. D8 arguments: [https://developer.android.com/studio/command-line/d8#general\_usage](https://developer.android.com/studio/command-line/d8#general_usage)
