3

I downloaded the SugarORM source to use it as a library module (so I could override the aplication's "attachBaseContext" method.

I have already seen the question SugarORM and multidex, Problem is that I can't figure out how to reference the MultiDex library into my new SugarORM library module. Can someone help me figuring this out?

Error page screenshot

Community
  • 1
  • 1

2 Answers2

7

Create a class java file

public class MultiDex extends SugarApp {
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        android.support.multidex.MultiDex.install(this);
    }


    @Override
    public void onCreate() {
        super.onCreate();
        SugarContext.init(this);
    }

    @Override
    public void onTerminate() {
        SugarContext.terminate();
        super.onTerminate();
    }
}

In Manifest, call the java class file.

<application
   .......
    android:name=".MultiDex"

   ......>

Check the version of sugar library and make sure you complie the latest version of sugar library . Using version like 1.3 will throw some errors with multidex.

add this in your gradle

 compile 'com.github.satyan:sugar:1.5'
-1

If possible, extend the MultiDexApplication yourself:

public class MyApplication extends MultiDexApplication

Also, ensure you have followed all steps required to configure MultiDex.

Particularly build.gradle:

android {
   defaultConfig {
      ...
      multiDexEnabled = true
}

And AndroidManifest.xml:

<application
    android:name="android.support.multidex.MultiDexApplication"
    .. >
 ..
</application>
Jake Lee
  • 7,549
  • 8
  • 45
  • 86
  • Thank you for your answer Jake. I had not thought about extending MultiDexAplication. It turned out I decided to compile using API 23, which natively supports multidex (because of ART Runtine). – Vinícius Filenga Apr 18 '16 at 14:11