• Register
0 votes
53 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

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
2 answers 1.2K views
1.2K views
Problem : I am getting following error login error: there is an error in logging you into this application. please try again later.
asked Nov 16, 2019 peterlaw 6.9k points
0 votes
1 answer 51 views
51 views
Problem : I have the Android Studio Beta. I have created the new project with compiling my old modules but when I tried launching my app it did not launch and it gave me the below message: Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. com ... merge dex But I am unable to know how to fix above error. I researched on this for hours but with no success.
asked Jan 31 jwilliam 3.9k points
0 votes
1 answer 32 views
32 views
Problem : I am trying to use the custom adapter extending cursor adapter for displaying data in the listview, So that I can display particular phone number that I have passed the id to a method in the database class however it is giving following error : ... mycursor.getColumnIndex("ContactNumber")); mycursor.close(); mydb.close(); return mynum; } Can someone help me to resolve my issue?
asked Dec 9, 2019 alecxe 7.5k points
0 votes
1 answer 42 views
42 views
Problem : Whenever I want to copy my 4 files into the bin folder, when I stop the main service, I always face an error with the one particular file (e.g. TexteDll). The error is as follows : Cannot copy TexteDll: The requested operation cannot be performed on a ... may be due to some system locking. Or may be another process is using that DLL. Can someone suggest a cause or solution for this ?.
asked Dec 6, 2019 alecxe 7.5k points