android multidex: enabled but not helping - android

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);
}

Related

transformClassesWithMultidexlistForDebug

My project run very good.
After i added google analytics, it did not allow 64k in .dex file and i have already set :
defaultConfig {
multiDexEnabled true
}
but then it have bellow error
:MainEntry:transformClassesWithMultidexlistForDebug FAILED
Error:Execution failed for task ':MainEntry:transformClassesWithMultidexlistForDebug'.
java.io.IOException: Can't read [C:\Users\temp2\android-git\MainEntry\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar] (Can't process class [com/vtcpay/a/a.class] (Unknown verification type [143] in stack map frame))
be sure enabled 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'
}
make sure you added in your manifest 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>
for more detailes you can see Configure Apps with Over 64K Methods
Thanks you everybody
I have already found solution for this issue. i should add this script bellow default config.
A multidex configuration requires significantly increased build processing time because the build system must make complex decisions about what classes must be included in the primary DEX file and what classes can be included in secondary DEX files. This means that routine builds performed as part of the development process with multidex typically take longer and can potentially slow your development process.
productFlavors {
// Define separate dev and prod product flavors.
dev {
// dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
// to pre-dex each module and produce an APK that can be tested on
// Android Lollipop without time consuming dex merging processes.
minSdkVersion 21
}
prod {
// The actual minSdkVersion for the application.
minSdkVersion 14
}
}

Error: number of method references in a .dex file cannot exceed 64k

I try to serach a lot about this stuff but I have not find anything. How can I solve the problem of 64k using Eclipse? I have different libraries, such as google play servces and I realized reading around that the major cause is due to it. I have to finish my app, is very important, How can I proceed? Thanks in advance.
You can use a part of google play services library instead of all. For example, if you need only location add this:
compile 'com.google.android.gms:play-services-location:9.4.0'
It helps me with 64k error.
You may need to config your project to support multiDex
https://developer.android.com/studio/build/multidex.html
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'
}
<?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>

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.

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