• Register
0 votes
114 views

Problem :

I want to add the fused location services but I am facing below error :

“Cannot fit requested classes in a single dex file. try supplying a main-dex list.”            

6 5 3
7,540 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

The problem lies in your Multidex. You should try to add the below library in your app gradle:

implementation 'com.android.support:multidex:1.0.3'

After that just add in your defaultConfig of the app gradle :

multiDexEnabled true

Now your Application should be of a Multidex type.. You must write it in your manifest as below :

android:name=".MyApplication"

"MyApplication" should be either a Multidex class, or it should extend it.

OR

Versions of a platform prior to the Android 5.0 (API level 21) use a Dalvik runtime for executing the app code. By default the Dalvik limits apps to the single classes.dex bytecode file per APK. Now in order to get around this limitation, you should add a multidex support library to your project as shown below:

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}

If the minSdkVersion is set to 21 or higher then all you need to do is just set the multiDexEnabled as true in the module-level build.gradle file, as shown below :

android {
    defaultConfig {
        ...
        minSdkVersion 21 
        targetSdkVersion 28
        multiDexEnabled true
    }
    ...
}
9 7 4
38,600 points
0 votes

Solution:

None of the answers they gave you were completed. The problem remains in the Multidex. You should include the library in the app gradle :

implementation 'com.android.support:multidex:1.0.3'

After, include in the defaultConfig of the app gradle :

multiDexEnabled true

Your Application should be of the Multidex type.. You should write it in the manifest :

android:name=".MyApplication"

"MyApplication" should be either the Multidex class, or it should enhance it.

Temper your app's or module's build.gradle

android {
    defaultConfig {
        ...
        minSdkVersion 21 <----- *here
        targetSdkVersion 26
        multiDexEnabled true <------ *here
    }
    ...
}

Following official documentation

Multidex backing for Android 5.0 and higher

Android 5.0 (API level 21) and higher employ a runtime named ART which natively clinchs loading multiple DEX files from APK files. ART works pre-compilation at app install time which scans for classesN.dex files and compiles them into a single .oat file accomplished by the Android device. Hence, in case your minSdkVersion is 21 or higher, you do not require the multidex support library.

What are dex files: Android app (APK) files hold executable bytecode files in the form of Dalvik Executable (DEX) files, which hold the compiled code employed to run your app.

Cause for this exception: The DEX specification limits the total number of systems that can be referenced within a single DEX file to 65,536 (64K reference limit) —adding Android framework methods, library methods, and methods in your own code.

Step 01. Include the following dependency as follows

For Non-Androidx Users,

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}
defaultConfig {
    minSdkVersion 16
    targetSdkVersion 28
    multiDexEnabled true  //ADD THIS LINE
}

For Androidx Users,

dependencies {
  implementation 'androidx.multidex:multidex:2.0.1'
}
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28
        multiDexEnabled true  //ADD THIS LINE
    }

Step 02:

After including those Sync projects and before you run the project ensure that to Build a project before the run. Else, you will get an exception.

Versions of the platform prior to Android 5.0 (API level 21) employ the Dalvik runtime for executing app code. By default, Dalvik limits apps to a single classes.dex bytecode file per APK. For getting around this limitation, you can include the multidex support library to your project:

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}

In case your minSdkVersion is fix to 21 or higher, all you require to do is set multiDexEnabled to true in your module-level build.gradle file, as shown here:

android {
    defaultConfig {
        ...
        minSdkVersion 21 
        targetSdkVersion 28
        multiDexEnabled true
    }
    ...
}

At the time you are using dependencies so your systems increased! google has a solution for that. that named Multidex!

NOTE: ensure that min SDK is over 14.

in your build.gradle :

android {
    defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 28
        multiDexEnabled true
    }
    ...
}



  dependencies {
      implementation 'com.android.support:multidex:1.0.3'
    }

FOR androidX USE :

 def multidex_version = "2.0.1"
 implementation 'androidx.multidex:multidex:$multidex_version'

 

10 6 4
31,120 points

Related questions

0 votes
1 answer 2 views
2 views
Problem: Error while generating the main dex list, Why did I have the mistake?
asked Mar 31 zayed1 35.6k points
1 vote
1 answer 4 views
4 views
Problem: When I generate the main dex list I get this error: Com.android.build.api.transform.transformexception: error while generating the main dex list.
asked Mar 30 PkGuy 13.1k points
0 votes
1 answer 10 views
10 views
Problem: Since upgrade to adt14 I can no longer build my project. It was the construction of the fine before the update. The error: [2011-10-23 16:23:29 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/myapp/R$array; [2011-10-23 ... Tools Eclipse re-installation (updated to latest 3.7.1 version) Created a new import project from file system Created a new subversion project.
asked Apr 5 sasha 16.2k points
1 vote
2 answers 117 views
117 views
Problem : I am very new to google play games services and Admob plugin. Currently I am trying to build the APK using google play games services and Admob plugin but it is not working for me. I am facing below error. CommandInvokationFailure: Unable to convert classes into dex format ... zzbyc; 2 errors; aborting ] Please Note: I am using Unity 5.6.1f1 (64-bit) Please help me in fixing above error.
asked Mar 27, 2020 morrisBson 3.2k points
0 votes
1 answer 2 views
2 views
Problem: Do you have any suggestions about how i can solve this problem,"the requested content cannot be loaded please try again later?"
asked 5 days ago sumaiya simi 15.8k points
0 votes
1 answer 233 views
233 views
Problem: I am working on Fancybox for the very first time I am trying to display the inline content (it is a div with the image linked to the new page). My div and image are displayed properly in a modal but if a image is clicked to navigate to a new page then in that case I ... website.com/file/id:64/ext:.png" class="img" /></a></div></div> </li> Can someone help me in fixing my fancybox error.
asked Jul 14, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 4 views
4 views
Problem: Hi there! I am new to the world of web designing. I want to know that is there any way to apply two or more CSS classes on a single HTML element? If yes, how do we do it and how do we apply the style to those classes? Please answer. I want something like the following: <h1 class = &ldquo;head1&rdquo; , class = &ldquo;head2&rdquo;></h1>
asked Mar 31 Code Learner 9.2k points
0 votes
1 answer 3 views
3 views
Problem I am not finding any original dex files for dex location,help me to solve this problem.
asked Apr 7 salim1 39k points
0 votes
1 answer 6 views
6 views
Problem: Don't know how to solve this error> com.android.builder.dexing.dexarchivemergerexception: unable to merge dex
asked Mar 19 Azlan2020 2.3k points
0 votes
1 answer 5 views
5 views
Problem: Iam having a problem that i am unable to merge dex android studio. can anyone hrelp me solviong this problem.
asked Mar 18 waseem memon 2.4k points