How to use MultiDex with a custom application class?

Ok, so I am creating an application that uses the .App class to get the context statically, the class does not work if it is not placed in the manifest under <application android:name=.App , but the problem is that I programmed 65k, so I have multiDex, and MultiDex should also be in the manifest under <application android:name=.MultiDex , otherwise my application will not work, how can I overcome this problem without affecting multidex, which is my scariest look at how many problems I went through, to make it work?

+5
source share
2 answers

Mark this page :

Note If your application uses the extension of the Application class, you can override the attachBaseContext () method and call MultiDex.install (this) to enable multidex. For more information, see the MultiDexApplication Reference Documentation.

In other words, use your own App class, but add the following:

 @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } 
+7
source

BaseAppplication is a native application class

 public class BaseApplication extends Application { @Override public void onCreate() { super.onCreate(); // your custom code here } // Add multidex Code or other Application Class here @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } } 
0
source

Source: https://habr.com/ru/post/1235446/


All Articles