How to Enable MultiDex Support in Intellij IDEA - android

I face on compile error "com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536", I search in google the problem is my project reached a limit of method. I following from MultIDex instruction. I added build.gradle, the following is file context of build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 15
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 15 //lower than 14 doesn't support multidex
targetSdkVersion 21
// Enabling multidex support.
multiDexEnabled = true
}
dexOptions {
preDexLibraries = false
}
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
When I build it again, the error still exist, how can I do?

You will need also to create a custom application and override the attachBaseContext method as follow:
public class MyApplication extends Application {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
then add it on your manifest as follow:
<application
android:name=".MyApplication"
.....
</application>
and voila!

I have what other responders have suggested but IntelliJ still doesn't recognize the MultiDex package, even with the library added manually to the project (multidex-1.0.1.aar file, as pulled in by Gradle). The real issue is that IntelliJ doesn't seem to recognize symbols in aar files yet. However, the app still builds via a Gradle task in IntelliJ.

Related

need help on android studio google map

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
above is the error message while i run the simulation on genymotion
i updated all the api, actived the google+ for genymotion
i create a google map project from the default project from android studio. can anyone help me out from here?
try suggestion from google
like downgrade the dependencies, add in the multidex true and etc but it still show this error.... yes, i have added the api key also
thanks everyone but i still having error after adding all the suggestionsplease see the image below
Definitely a mutlidex issue, enable mutlidex as follows,
1. Add code
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
There should be an entry in manifest too
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
or if you have an application class then do this instead of above manifest entry
public void onCreate(Bundle arguments) {
MultiDex.install(getTargetContext());
super.onCreate(arguments);
...
}
And make sure you have clicked on sync at top right on build.gradle file, when it appears.
Clean and build.
Theory: https://developer.android.com/studio/build/multidex.html
If issue still persist give gradle file and error log.
Seems like you have gone past the ~65000 method limit. Try enabling multidex if you 're using recent versions of the Android build tools
dependencies {
compile group: 'com.android.support', name : 'multidex', version: '1.0.1'
}
In your android config
android {
defaultConfig {
// flag
multiDexEnabled true
}
}
There should be an entry in manifest or in application class(if it's there) too
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
or if you have an application class then do this instead of above manifest entry
public void onCreate(Bundle arguments) {
MultiDex.install(getTargetContext());
super.onCreate(arguments);
...
}
Edit:
You must be using build tools > 21.1.*

Where add 64K code and where?

What code must i add and where to get 64K methods?
I try and build signed APK but it give me issue whole time!
Error:The number of method references in a .dex file cannot exceed 64K.
Error:Execution failed for task
’:myapp:transformClassesWithDexForRelease’. >
com.android.build.api.transform.TransformException:
com.android.ide.common.process.ProcessException:
java.util.concurrent.ExecutionException:
java.lang.UnsupportedOperationException
KUMAR's answer is pretty close but not covering all the details.
Firstly add necessary configuration to your build.gradle of app module:
app/build.gradle
android {
defaultConfig {
multiDexEnabled true
}
}
dependencies
{
compile 'com.android.support:multidex:1.0.1'
}
In the second step you can follow two paths depending on your need.
a. You don't have a custom application class. So you need to add the MultiDexApplication class from the multidex support library to the application element in your manifest:
AndroidManifest.xml
<application
android:name="android.support.multidex.MultiDexApplication"
OR
b. You have a custom application class. So you need to make it extend MultiDexApplication class:
MyApplication.java
public class MyApplication extends MultiDexApplication {
}
AndroidManifest.xml
<application
android:name="MyApplication"
You should be ready to go over 64K method limit.
You can read this tutorial over multidex to understand the logic behind all of these.
If our application is exceeding more than 64K methods then we need to enable the multiDex in our code.
Add the dependency in build.gradle
dependencies
{
compile 'com.android.support:multidex:1.0.0'
}
Enable multidex in build.gradle like the following
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
Now sync your code and run it then it will work.

Error:Execution failed for task ':app:buildInfoDebugLoader'. Exception while doing past iteration backup

I got this error while compiling one of my android project in android studio 2.0. How to solve this?
Clean your project.
Try to build. If not solved, do following stuff
Add multidex support to your application. If application class is exist in your application then add attachBaseContext method otherwise create one and register in menifest.xml,under name attribute of application tag.
public class YouApplication extends Application {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
And update your build.gradle(app)
android {
compileSdkVersion 22
buildToolsVersion "23.0.0"
defaultConfig {
minSdkVersion 14 //lower than 14 doesn't support multidex
targetSdkVersion 22
// Enabling multidex support.
multiDexEnabled true
}
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
try Build -> Rebuild Project and then Run again.
or
Build -> Clean Project
or both of them

Multidex application in Eclipse

I've developed an android application in Eclipse which uses lot of library JAR files so i got exception of
Unable to execute dex: method ID not in [0, 0xffff]: 65536
So i thought to implement multidex. I searched many blogs but nothing helps me in the eclipse framework. So i installed the Gradle plugin for eclipse to achive the multidex which was mentioned in many posts (As mentioned here, and Here). Both telling the same method to add
multiDexEnabled true
but its not working
I asked my application class to override
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
and in the gradle file which is builded i edited as
android{
defaultConfig {
minSdkVersion 14 //lower than 14 doesn't support multidex
targetSdkVersion 22
// Enabling multidex support.
multiDexEnabled true
}
}
But it doesn't helped me. Can anyone help me to find how to multidex my application with eclipse or correct way to multidex with the gradle.
add this to your gradle dependencies:
dependencies {
compile 'com.android.support:multidex:1.0.0'
...
}
If that doesn't work, I'm lost as to how to help you because that is the only thing missing that I can see from other answers here on SO.
You need to do 3 things to enable MultiDex:
1) Add following dependency to your build.gradle file:
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
2) Enable multidex in your build.gradle file:
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
3) Finally, if you are using a custom Application class, it should extend MultiDexApplication:
public class MuyApplication extends MultiDexApplication {
}
or if you are not using a custom Application class, do the following in your manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>

Configuring TapJoy Creating Dex FIle issue

I have multiple libraries in my libs folder in android. When I try to add "Tapjoy", I get the error:
unable to execute dex method id not in 0 0xffff 65536 android problem
is coming
and, when I am trying to configure build path and adding external jars,
java.lang.NoClassDefFoundError: com.tapjoy.TapjoyConnect
I'm stuck on this problem. Can any one give me solution?
Congratulation you have reached the 65K method limit you have two options :
a) Clean up some code by removing unnecessary libraries / using ProGuard.
b) Multidex solution , follow these steps
Make sure your Android SDK Build and Android Support Repository are updated to latest version.
Modify your build.gradle by adding the support dex lib and enabling the multidex
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Modify your manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
p.s if you already extend Application then just override the attachBaseContext method
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
for more info:
Building Apps with Over 65K Methods

Categories

Resources