Multidex application in Eclipse - android

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>

Related

android multidex: enabled but not helping

I updated my app to use multidex
multiDexEnabled true
and upped my minSdkVersion to 21:
ext {
buildToolsVersion = "30.0.3"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 30
javaVersion = JavaVersion.VERSION_1_8
}
so when I start building my app I first get this
> Configure project :app
[SafeDK] Your project has been updated to support Multi-Dex!
With Multi-Dex support you can use as many methods as you like in your application (no 65K method limit)
but later the build fails with:
[SafeDK-ERROR] Main Dex exceeded 65K methods or field references, Exception: Main Dex exceeded 65K methods or field references
why is that? how is this contradiction possible?
According to android docs:
If your minSdkVersion is set to 21 or
higher, multidex is enabled by default and you do not need the
multidex library.
So you do not need:
multiDexEnabled true
Still if you face this issue make sure:
You also have:
dependencies {
implementation 'androidx.multidex:multidex:2.0.1' //with androidx libraries
//implementation 'com.android.support:multidex:1.0.3' //with support libraries
}
In the 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="androidx.multidex.MultiDexApplication">
<!-- If you are using support libraries use android:name="android.support.multidex.MultiDexApplication" -->
<!--If you are using your own custom Application class then extend -->
<!--MultiDexApplication and change above line as-->
<!--android:name=".YourCustomApplicationClass"> -->
...
</application>
</manifest>
Finlly:
If you are using your own Application class, change the parent class from Application to MultiDexApplication.
#Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(newBase);
MultiDex.install(this);
}

Android 65k multidex issue for android system application

Developing an system application which works with multiple libraries and aar files resulting application get the Multidex 65k issue which is reported by many developers working on Android studio .
In my case as am working on android system build environment not sure how to enable the multidex option ?
Have extended the Application and added MultiDex.install(this); which is making no difference for the compilation resulting
trouble writing output: Too many method references: 156862; max is 65536.
You may try using --multi-dex option.
Not able to find any reference to work on the system build for this kind of issue .
Any pointers on this will be helpful
Thanks
Update in your gradle
defaultConfig {
..............
multiDexEnabled true
}
dexOptions should add..
dexOptions {
//incremental = true;
preDexLibraries = false
javaMaxHeapSize "4g"
}
dependency add
compile 'com.android.support:multidex:1.0.1'
Also In Your AndroidManifest.xml add this lines android:name
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:name="android.support.multidex.MultiDexApplication"
>
Idea is if apk method is > 64K, then we break it to have multiple dex files.
In build.gradle
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
// Add this dependency
compile 'com.android.support:multidex:1.0.0'
}
Hope this helps.
Reference: Android Dev
You can visit Configure Apps with Over 64K Methods for details.
Here some excerpt from it:
Setting up your app development project to use a multidex configuration requires that you make a few modifications to your app development project. In particular you need to perform the following steps:
Change your Gradle build configuration to enable multidex
Modify your manifest to reference the MultiDexApplication class
Modify the module-level build.gradle file configuration to include the support library and enable multidex output, as shown in the following code snippet:
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'
}
In your manifest add the MultiDexApplication class from the multidex support library to the application element.
<?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>
UPDATE
If you have included Google Play Service library, instead using:
compile 'com.google.android.gms:play-services:9.4.0'
Try to only use what you really need. Something like this:
com.google.android.gms:play-services-base:9.4.0
com.google.android.gms:play-services-ads:9.4.0 // only need ads
com.google.android.gms:play-services-gcm:9.4.0 // only need gcm
Read more at Setting Up Google Play Services.

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.

How to Enable MultiDex Support in Intellij IDEA

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.

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