{"id":16681766,"url":"https://github.com/casidiablo/multidex","last_synced_at":"2025-10-06T13:02:01.636Z","repository":{"id":19224452,"uuid":"22458798","full_name":"casidiablo/multidex","owner":"casidiablo","description":"Library Project including compatibility multi dex loader.","archived":false,"fork":false,"pushed_at":"2014-11-25T19:13:17.000Z","size":522,"stargazers_count":292,"open_issues_count":6,"forks_count":54,"subscribers_count":20,"default_branch":"publishing","last_synced_at":"2025-04-09T16:09:53.855Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/casidiablo/multidex","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/casidiablo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-31T06:21:54.000Z","updated_at":"2025-02-06T01:13:13.000Z","dependencies_parsed_at":"2022-08-01T03:08:44.486Z","dependency_job_id":null,"html_url":"https://github.com/casidiablo/multidex","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casidiablo%2Fmultidex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casidiablo%2Fmultidex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casidiablo%2Fmultidex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casidiablo%2Fmultidex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/casidiablo","download_url":"https://codeload.github.com/casidiablo/multidex/tar.gz/refs/heads/publishing","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248065283,"owners_count":21041871,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T14:05:13.525Z","updated_at":"2025-10-06T13:01:56.597Z","avatar_url":"https://github.com/casidiablo.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"IMPORTANT: this library has been superseded by buildToolsVersion 21.1.0\n----\n\nThe steps for multidexing if you are using 21.1.0 or higher is:\n\n```\nandroid {\n    compileSdkVersion 21\n    buildToolsVersion \"21.1.0\"\n\n    defaultConfig {\n        ...\n        minSdkVersion 14\n        targetSdkVersion 21\n        ...\n\n        // Enabling multidex support.\n        multiDexEnabled true\n    }\n    ...\n}\n```\n\nNote that the dependency on 'com.android.support:multidex:1.0.0' is automatic, there is not need to specify it.\n\nI'll keep this around for reference, but I encourage all people using this to switch to the official multidexing method: [Building Apps with Over 65K Methods](http://developer.android.com/tools/building/multidex.html).\n\nDeprecated, non-official multidex\n---------------------------------\n\nLibrary Project including compatibility multi dex loader.\n\nThis can be used by an Android project to install classloader\nwith multiple dex of applications running on API 4+.\n\n### What's this?\n\nThis is just a fork of the original [multidex](https://android.googlesource.com/platform/frameworks/multidex/)\nrepo. I'll maintain this for a while since I needed this to be in a Maven\nrepo for easy consumption.\n\n### What's it for again?\n\nWhile dexing classes it is sometimes possible to exceed the maximum (65536) methods\nlimit (try using Google Play Services and Scaloid for instance):\n\n```\ntrouble writing output: Too many method references: 70820; max is 65536.\nYou may try using --multi-dex option.\n```\n\nSo the suggestion is to use the `--multi-dex` option of the `dx` utility; this\nwill generate several dex files (`classes.dex`, `classes2.dex`, etc.) that will\nbe included in the APK. To do so, add the following code to your app's `build.gradle` file:\n\n```\nafterEvaluate {\n    tasks.matching {\n        it.name.startsWith('dex')\n    }.each { dx -\u003e\n        if (dx.additionalParameters == null) {\n            dx.additionalParameters = []\n        }\n        dx.additionalParameters += '--multi-dex' // enable multidex\n        \n        // optional\n        // dx.additionalParameters += \"--main-dex-list=$projectDir/\u003cfilename\u003e\".toString() // enable the main-dex-list\n    }\n}\n```\n\nBy default Dalvik's classloader will look for the `classes.dex` file only, so\nit's necessary to patch it so that it can read from multiple dex files. That's\nwhat this project provides.\n\nIf you are unlucky enough, the multidex classes will not be included in the\n`classes.dex` file (the first one read by the classloader), which in turn\nwill render all this useless. There's a workaround for this though. Create a file\nwith this content and a arbitrary name:\n\n```\nandroid/support/multidex/BuildConfig.class\nandroid/support/multidex/MultiDex$V14.class\nandroid/support/multidex/MultiDex$V19.class\nandroid/support/multidex/MultiDex$V4.class\nandroid/support/multidex/MultiDex.class\nandroid/support/multidex/MultiDexApplication.class\nandroid/support/multidex/MultiDexExtractor$1.class\nandroid/support/multidex/MultiDexExtractor.class\nandroid/support/multidex/ZipUtil$CentralDirectory.class\nandroid/support/multidex/ZipUtil.class\n```\n\nAnd pass the path of this file to the `--main-dex-list` option of the `dx` utility. Just uncomment the example from above accordingly by enabling one more item to the list of strings exposed by the `additionalParameters` property.\nThe `\u003cfilename\u003e` is the arbitrary choosed above.\n\n### Usage\n\nAdd this project to your classpath:\n\n```groovy\nrepositories {\n  jcenter()\n}\n\ndependencies {\n  compile 'com.google.android:multidex:0.1'\n}\n```\n\nThen you have 3 possibilities:\n\n- Declare `android.support.multidex.MultiDexApplication` as the application in\nyour `AndroidManifest.xml`\n- Have your `Application` extends `android.support.multidex.MultiDexApplication`, or...\n- Have your `Application` override `attachBaseContext` starting with:\n\n```java\nimport android.support.multidex.MultiDex;\n\n// ...\n\n@Override\nprotected void attachBaseContext(Context base) {\n    super.attachBaseContext(base);\n    MultiDex.install(this);\n}\n```\n\n### `build.gradle` example\n\n```groovy\nbuildscript {\n    repositories {\n        jcenter()\n    }\n    dependencies {\n        classpath 'com.android.tools.build:gradle:0.13.3'\n        classpath 'jp.leafytree.gradle:gradle-android-scala-plugin:1.1'\n    }\n}\n\napply plugin: 'com.android.application'\napply plugin: 'jp.leafytree.android-scala'\n\nrepositories {\n    jcenter()\n}\n\nandroid {\n    compileSdkVersion 21\n    buildToolsVersion '21.0.2'\n\n    defaultConfig {\n        applicationId 'some.app'\n        minSdkVersion 19\n        targetSdkVersion 19\n        versionCode 1\n        versionName '1.0'\n    }\n}\n\ndependencies {\n    compile 'com.google.android:multidex:0.1'\n    compile 'com.android.support:support-v4:19.0.1'\n    compile 'com.google.android.gms:play-services:5.0.77'\n    compile 'org.scala-lang:scala-library:2.11.2'\n    compile 'org.scaloid:scaloid_2.11:3.4-10'\n}\n```\n\n### Cautions\n\nIf you extends the `MultiDexApplication` or override the method `attachBaseContext`, you need to remember:\n\n**NOTE: The following cautions must be taken only on your android Application class, you don't need to apply this cautions in all classes of your app**\n\n- The static fields in your **application class** will be loaded before the `MultiDex#install`be called! So the suggestion is to avoid static fields with types that can be placed out of main classes.dex file.\n- The methods of your **application class** may not have access to other classes that are loaded after your application class. As workarround for this, you can create another class (any class, in the example above, I use Runnable) and execute the method content inside it. Example:\n```java\n    @Override\n    public void onCreate() {\n        super.onCreate();\n        \n        final Context mContext = this;\n        new Runnable() {\n\n            @Override\n            public void run() {\n                // put your logic here!\n                // use the mContext instead of this here\n            }\n        }.run();\n    }\n```\n\n### Common problems\n\n#### DexException: Library dex files are not supported in multi-dex mode\n\nIf you catch this error:\n```\nError:Execution failed for task ':app:dexDebug'.\n\u003e com.android.ide.common.internal.LoggedErrorException: Failed to run command:\n  \t$ANDROID_SDK/build-tools/android-4.4W/dx --dex --num-threads=4 --multi-dex\n  \t...\n  Error Code:\n  \t2\n  Output:\n  \tUNEXPECTED TOP-LEVEL EXCEPTION:\n  \tcom.android.dex.DexException: Library dex files are not supported in multi-dex mode\n  \t\tat com.android.dx.command.dexer.Main.runMultiDex(Main.java:322)\n  \t\tat com.android.dx.command.dexer.Main.run(Main.java:228)\n  \t\tat com.android.dx.command.dexer.Main.main(Main.java:199)\n  \t\tat com.android.dx.command.Main.main(Main.java:103)\n```\n\nThe `--multi-dex` option to `dx` is incompatible with pre-dexing library projects. So if your app uses library projects, you need to disable pre-dexing before you can use --multi-dex:\n````groovy\nandroid {\n    // ...\n    dexOptions {\n        preDexLibraries = false\n    }\n}\n```\n\n#### OutOfMemoryError: Java heap space\n\nIf you catch this error while running dex:\n```\nUNEXPECTED TOP-LEVEL ERROR:\njava.lang.OutOfMemoryError: Java heap space\n```\nThere is a field on dexOptions to increase the java heap space:\n```groovy\nandroid {\n    // ...\n    dexOptions {\n        javaMaxHeapSize \"2g\"\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasidiablo%2Fmultidex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcasidiablo%2Fmultidex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasidiablo%2Fmultidex/lists"}