11

E/FBAudienceNetwork: You are using custom Application class and don't call AudienceNetworkAds.isInAdsProcess(). Multi-process support will be disabled. Please call AudienceNetworkAds.isInAdsProcess() if you want to support multi-process mode.

implementation 'com.facebook.android:audience-network-sdk:5.1.0'
implementation 'com.mopub.mediation:facebookaudiencenetwork:5.1.0.2'

am using FAN along with Mopub.

How to fix the above issue? Thanks in advance.

Sarath Kumar
  • 1,922
  • 3
  • 19
  • 43
  • where you subclassing application class or not ? I am not subclassing the application class and I received this after enabling multidex not sure if its a bug or what – isJulian00 Jun 30 '19 at 16:01

2 Answers2

11

It's likely because you use custom Application subclass. Put AudienceNetworkAds.isInAdsProcess() call on top of your custom Application class like this:

public class YourApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        if (AudienceNetworkAds.isInAdsProcess(this)) {
            return;
        }

        // your normal onCreate() code
    }
}

Now warning should disappear.

Alternatively you can turn multiprocess support off (not recommended) by setting:

AdSettings.setMultiprocessSupportMode(MultiprocessSupportMode.MULTIPROCESS_SUPPORT_MODE_OFF);

Note. You should call this before calling SDK methods or MoPub mediation.

Yuriy
  • 1,466
  • 2
  • 14
  • 30
  • 1
    I found the same thing in Audience Network SDK API reference saying that I should skip all other initialization if current process is created by Audience Network SDK. I just wonder why Audience Network SDK is trying to instantiate Application, and for what? – ZhouX May 20 '19 at 07:04
  • @ZhouX AN SDK supports running ads in separate process, but if you start second process it will instantiate second instance of Application class (it's how Android framework is designed). That's why you should prevent any code to be run concurrently from Application.onCreate(), because if you access files without synchronization they can get corrupted. Hope this helps. – Yuriy May 20 '19 at 12:06
  • Thanks! Then I guess AN is using multiple process mode by default that's why we were facing this warning. I can understand that different processes hold their own application instance, just not so familiar with AN, what is the benefit of running ads in a separated (dedicated) process? – ZhouX May 21 '19 at 13:04
  • 1
    @ZhouX There are 2 main benefits of running separate process: 1) this allows to save memory of the main process that can be useful for example for games; 2) any crash inside separate process doesn't affect main process. – Yuriy May 23 '19 at 11:10
  • right, that makes sense, it would be AN SDK consuming memory instead the app itself to reduce OOM errors especially for game. Thank you! – ZhouX May 24 '19 at 02:27
  • I only have 1 class that is a activity class, but I think this warning started appearing after I enabled multiDex, anyone have any ideas on this ? – isJulian00 Jun 30 '19 at 02:15
  • how come you don't return anything in the if statement ? isn't it suppose to return true or false ? – isJulian00 Jul 02 '19 at 04:35
  • @Julian 1) If you use MultiDexApplication in AndroidManifest, you will need to extend it and do same as above public class YourApplication extends MultiDexApplication { } 2) you don't need to return anything, because onCreate() method is void. – Yuriy Jul 03 '19 at 21:20
  • @YuriyAshaev Ok, but I followed the instructions on what to do they say if you don't use or extend the application class then you just have to declare it in AndroidManifest so how come you are saying I need to do the same as above "public class YourApplication extends MultiDexApplication" I don't use application I only have 1 activity – isJulian00 Jul 03 '19 at 23:08
  • @Julian Can you add Log.d("Application", "" + context.getApplicationContext().getClass().getName()); into onCreate() of your activity and check what you see in LogCat? – Yuriy Jul 09 '19 at 01:48
  • @YuriyAshaev I see androidx.multidex.MultiDexApplication, so everything is working good I think, I never wrote extends multidex but I think it does it for me behind the scenes since I don't override application class – isJulian00 Jul 17 '19 at 21:06
  • @YuriyAshaev do you know or anyone else how come when I put a Log.d("application", "testing"); log inside if(AudienceNetworkAds.isInAdsProcess(this)) I never see it printed to the console ? is it because I actually don't extend the application class ? – isJulian00 Jul 26 '19 at 05:56
  • The method `isInAdsProcess` is deprecated since sdk 5.7: https://developers.facebook.com/docs/audience-network/reference/android/com/facebook/ads/audiencenetworkads.html/?version=v5.9.0#isinadsprocess-context- – activity May 22 '20 at 16:28
  • `AudienceNetworkAds.isInAdsProcess` is gone in v6.3. – Kimi Chiu May 06 '21 at 12:14
0

If you are using Facebook Audience Network then, Must be implement both latest sdk in your dependencies then you can call all callback of facebook sdk( check this link- https://developers.facebook.com/docs/audience-network/guides/adding-sdk/android )

Here you forget to add (support annotation dependencies).

In Android Studio, make sure that mavenCentral() or jcenter() is included in your project's list of repositories. Repositories are defined in your project's module-level build.gradle file.

repositories {
    mavenCentral()
    jcenter()
}

Next, add the following implementation dependencies to your project's list of dependencies. Dependencies are also defined in your project's module-level build.gradle file. Note that annotation support is required by the Audience Network SDK.

dependencies { 
    implementation 'com.android.support:support-annotations:28.0.0'
    implementation 'com.facebook.android:audience-network-sdk:5.+'
}

HAPPY CODING :)

AG-Developer
  • 361
  • 2
  • 10