1

I have exported my Unity project to be able to use multidex. Problem is I have to set the android:name in the project's androidmanifest to "android.support.multidex.MultiDexApplication" when I already have this "io.fabric.unity.android.FabricApplication" set for fabric.

I have tried initializing Fabric manually but then I get this error : AndroidJavaException: io.fabric.unity.android.FabricInitializationException: Fabric did not find a valid application context.

I have found that someone had a similar problem but it didn't got solved: https://twittercommunity.com/t/unity-android-plugin-conflicts/79947?source_topic_id=83751

Thanks in advance for your help!

azekirel555
  • 577
  • 2
  • 8
  • 25
  • are you sure you need to change the name? i have a similar setup and have not changed it in the manifest and everything is working fine. – turnipinrut Mar 23 '17 at 13:17
  • Hi @turnipinrut, yes, it's needed for users of Android 4.x, otherwise it causes a crash – azekirel555 Mar 23 '17 at 15:57

2 Answers2

3

Add next lines to your Application method:

protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    // this one is needed to enable multidex in your application
    MultiDex.install(this);
}

public void onCreate() {
    super.onCreate();
    // this one is needed to init the Fabric SDK
    FabricInitializer.initializeFabric(this, FabricInitializer.Caller.Unity);
}

Also, one more solution you can check here, I created a small GitHub repo with description how to make it in few clicks.

Orest Savchak
  • 4,529
  • 1
  • 18
  • 27
2

Was having the same problem.

Ended up creating a new android studio project. Imported Fabric-(some version).jar and Fabric-init.jar which I got from the android plugins folder inside the Unity project.

Decompiled the Fabric-init.jar and modified the FabricApplication.java class in order to extend from MultiDexApplication instead of Application.

Built the project and extracted the new FabricApplication.class from the build folder in the Android Studio project/app.

Replaced the FabricApplication.class inside the Fabric-init.jar of the Unity project with the new one.

Left "io.fabric.unity.android.FabricApplication" as the application name in the manifest.

Tested in android 4.4 and it worked. Not ideal though because I'll have to do it with every plugin update, but considering I'm a noob with this gradle thing (and Android projects in general), I'm beyond happy that at least it worked.

If anyone comes up with a better approach, please let us know!

  • Was the first step (creating the Android Studio project) necessary, or could you have accomplished this just from decompiling fabric-init.jar and modifying the FabricApplication.java class contained within? – vargonian Aug 23 '17 at 17:46
  • Also, what tool did you use to decompile? As an Android n00b myself, it's hard for me to follow the exact steps (especially the Android Studio-related ones). – vargonian Aug 23 '17 at 18:01