15

After adding compile 'com.android.support:support-v13:21.0.+' to build.gradle, I had some conflicts on building my app, so I had to add multiDexEnabled = true to defaultConfig inside build.gradle. Those conflict are gone, but i got another exception (on opening the app) for the missing calligraphy library:

java.lang.NoClassDefFoundError: uk.co.chrisjenx.calligraphy.R$attr
        at uk.co.chrisjenx.calligraphy.CalligraphyConfig$Builder.<init>(CalligraphyConfig.java:150)
        at com.taxiyaab.android.util.ApplicationClass.onCreate(ApplicationClass.java:120)
        at newapp.com.taxiyaab.taxiyaab.PassengerApplication.onCreate(PassengerApplication.java:68)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4462)
        at android.app.ActivityThread.access$1500(ActivityThread.java:144)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1306)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:212)
        at android.app.ActivityThread.main(ActivityThread.java:5135)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
        at dalvik.system.NativeStart.main(Native Method)

My latest sdk build tools version is 22.0.1. Has anybody faced this issue before?

serv-inc
  • 35,772
  • 9
  • 166
  • 188
Arash GM
  • 10,316
  • 6
  • 58
  • 76

6 Answers6

34

If you support API levels under 21, your Application class should extend MultiDexApplication from the support library.

class MyApplication extends MultiDexApplication

If you do not have a custom Application class, than you should add the MultiDexApplication class to your manifest directly

<application
    android:name="android.support.multidex.MultiDexApplication">
</application>

See https://developer.android.com/tools/building/multidex.html

  • thx for the answer , i did what you said , but it raise other exceptions , i think i shouldn't have to use multiDexEnabled. – Arash GM May 28 '15 at 10:41
  • i get : Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_40\bin\java.exe'' finished with non-zero exit value 2 , if doesn't use multiDexEnabled. – Arash GM May 28 '15 at 10:45
  • Did you get this exception while using MultiDexApplication? If no, which exceptions did it raise when you've used MultiDexApplication? Please supply the full exception details. –  May 28 '15 at 14:02
  • that exception raised because i think my app reach 65k function limit, so by enabling multidex its gone but my libraries need review to handle other exceptions because of enabling multidex config. anyway i accepted your answer , it was helpful thx. – Arash GM May 28 '15 at 18:10
7

If your application extends from Application then override attachBaseContext inside Application i.e

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

Also need to add dependency

compile 'com.android.support:multidex:1.0.1'
6

Goodlife is here again to the rescue . Add this line to ur java file that extends application.

 public void onCreate() {
    super.onCreate();

    mInstance = this;

    //ADD MULTIDEX.INSTALL(THIS) SOLVED MY SIMILAR PROBLEM
    MultiDex.install(this);
    CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
                    .setDefaultFontPath("fonts/Roboto-Regular.ttf")
                    .setFontAttrId(R.attr.fontPath)
                    .build()
    );
}
Goodlife
  • 3,822
  • 2
  • 24
  • 23
  • 1
    This worked, BUT, I had to move it before the setContentView as some of the layout files had calligraphy in them and broke the app. Once it was before the setContentView, things seem to be working just fine. Thanks for the tip. – PGMacDesign Apr 18 '16 at 17:34
1

Yes,update to multidex 1.0.2 and add Mulitidex.install(this) to the class extending application

Kennedy Kambo
  • 372
  • 4
  • 24
0

MultiDex.install(this);

This can fix the problem.

maxxi
  • 197
  • 4
  • 11
0

What i did was too update the compiling library in app level gradle file.

compile 'com.android.support:multidex:1.0.0'

I updated it too

compile 'com.android.support:multidex:1.0.1'

and it worked fine for me. Maybe this helps someone.

Harry .Naeem
  • 1,245
  • 3
  • 20
  • 33