Error: Cannot fit requested classes in a single dex file # methods

Error: Cannot fit requested classes in a single dex file # methods - Hello friend inabnomaniiyaha, In the article that you read this time with the title Error: Cannot fit requested classes in a single dex file # methods, we have prepared this article well for you to read and take information in it. hopefully the contents of the post Artikel android-example,what we write you can understand. Alright, happy reading.

Judul : Error: Cannot fit requested classes in a single dex file # methods
link : Error: Cannot fit requested classes in a single dex file # methods

Baca juga


Error: Cannot fit requested classes in a single dex file # methods

I encountered a multiDex problem when quoting the autobahn framework. After looking for relevant information and browsing the explanations of the great gods on the Internet, I solved this problem. Record the problem solving process here.

First of all, let’s roughly talk about why this problem occurs. The android project will compile java files into class files during the compilation process, and then package the class files into dex files. By default, only one dex file is packaged during the packaging process, but a single dex file. The number of methods in the file cannot exceed 65536. When we reference a bunch of dependencies and third-party libraries, after the number of methods exceeds, packaged into a single dex file will compile an error, so it needs to be packaged into multiple dex files, that is multiDexEnable.

Step 1: introduce dependencies

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

Or

implementation 'androidx.multidex:multidex:2.0.0'

Step 2: Add configuration items

Add the configuration item multiDexEnable true under android-->defaultConfig of the main project, as shown in the following figure:

   defaultConfig {

        applicationId ""

        minSdkVersion 16

        targetSdkVersion 30

        versionCode 1

        versionName "1.1"

        multiDexEnabled true

}

Step 3. Introduce the Application class

If there is no Application class in the original project, create a new Application class to inherit the MultiDexApplication class, and then reference this Application in the Manifest file.

If there is already an Application class in the original project, which has already inherited other classes, due to java's single inheritance mode, MultiDexApplication can no longer be inherited, and it can be solved by rewriting the attachBaseContext method

@Override

protected void attachBaseContext(android.content.Context base) {

   super.attachBaseContext(base);

   android.support.multidex.MultiDex.install(this);

}

Some netizens reported that after the above steps, there is no error when running on version 5.0 or higher, but it will crash in version 4.4. Here are the relevant suggestions (only recorded, not tested, no android4.4 device at hand)

Add configuration in build.gradle file, same level directory as buildTypes and defaultConfig configuration

dexOptions{

    preDexLibraries = false

}



That's the articleError: Cannot fit requested classes in a single dex file # methods

That's it for the article Error: Cannot fit requested classes in a single dex file # methods this time, hopefully can be useful for all of you. well, see you in another article post.

You are now reading the articleError: Cannot fit requested classes in a single dex file # methods with link addresshttps://inabnonapudyawanabing.blogspot.com/2021/07/error-cannot-fit-requested-classes-in.html

Related Posts :

0 Response to "Error: Cannot fit requested classes in a single dex file # methods"

Post a Comment

Tips Tricks for Android Phone

Tips & Tricks for Android Phone is a free android app and Collection of Tips and Tricks related to using your android mobile device lik...