Exception while running app below Lollipop devices [duplicate] - android

This question already has answers here:
Android Multidex RuntimeException
(2 answers)
Closed 6 years ago.
My app is running fine on Lollipop devices. But when I try to run the app on below Lollipop devices it is giving error everytime.
the error is given below:
Error:The number of method references in a .dex file cannot exceed 64K.
:app:transformClassesWithDexForDebug FAILED
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
My gradle file is below:
defaultConfig {
applicationId "com.ielts.touchstone.touchstone"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0.4"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

Try adding multiDexEnabled true to your app build.gradle file.
defaultConfig {
multiDexEnabled true
}
Also , Clean Your Project first.

Your app has more than 64K methods which are not supported by default prior to android 5.0, hence the exception. To support more than 64K methods below 5.0 add multidex support to your app.
Add the following code in your app module's gradle file
android {
.
.
.
defaultConfig {
...
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
and in your manifest add the MultiDexApplication class from the multidex support library to the application element.
<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>
More details can be found here

Your application is crossing 64K method limit. Upto API 19, android system uses dalvik processors which is having limit of 64k methods. But from API 21, android system uses Android Runtimes, so that you have to add multiDexEnabled true if you are building your app for API 21 n above. It will Configure Apps with Over 64K Methods.
Check this -
https://developer.android.com/studio/build/multidex.html
Hope it will help :)

Related

Flutter project exceeds .dex Method Reference Count limit

Why does a Flutter project exceed 64K method reference in its .dex file?
I am wondering what the cause of this could be:
In a rather small Flutter project I use 13 plugins. Without Multidex, the Android build fails because it vastly exceeds the method reference limit.
Is there any trick (e.g. Gradle related) that would allow to shrink the method reference count because I think that such a project should not exceed the limit?
(if you want further information on why I think that this is odd, please take a look at older revisions of this question)
I had the same problem and the fix for me was increasing the minSdkVersion in the app/build.bradle like this
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
minSdkVersion 21 // change this to 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
If you are using minSdkVersion less than 21, you can do the following to enable multidex.
In your app level build.gradle change as follows:
Add multiDexEnabled true to defaultConfig
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
...
multiDexEnabled true
}
Add multidex dependency
dependencies {
...
implementation 'androidx.multidex:multidex:2.0.1'
}
You can refer this for more information.
in your android/app/build file increase the minsdkversion from 16 to 21 under defautConfig.
Some have even increased it to 28 but it worked for me at 21.
Here is the link to the issue on git
Edit: multiDexEnabled: true also works for some under the same defautConfig.
in the build.gradle under the defaultConfig add the multiDexEnabled true
minSdkVersion 16
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
Use ProGuard to eliminate unused classes at compile time. This will reduce your method count by a considerable amount.
You will need to adjust the ProGuard rules to work with Flutter like the Flutter documentation explains here.
I successfully migrated the app to androidx using the below link and the second step:
1) Flutter Projects & Android X Migration Issues
2) In your android/app/build file increase the minsdkversion from 16 to 21 under defaultConfig. Some have even increased it to 28 but it worked for me at 21.
There is another solution without multidex or increasing min SDK. But it's need R8, just enable minify on App level build.gradle
buildTypes {
release {
minifyEnabled true
}
debug {
minifyEnabled true
}
}
from github comment
or to run debug without minify github comment
buildTypes {
release {
minifyEnabled true
}
debug {
defaultConfig.minSdkVersion 21
}
}
Option 1: use the multidex Library.
Option 2: increase your min SDK to 21 or higher
Detailed explanation on using Multidex Library:
Versions of the platform prior to Android 5.0 (API level 21) use the Dalvik runtime for executing app code. By default, Dalvik limits apps to single classes.dex bytecode file per APK. In order to get around this limitation, you can add the multidex library to the module-level build.gradle file:
Steps to fixing it: set multiDex enabled to true
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
...
multiDexEnabled true
}
Add multidex dependency:
dependencies {
implementation "androidx.multidex:multidex:2.0.1" }
Detailed explanation on why increasing your min SDK to 21 in your android/app/build.gradle works is:
Android 5.0 (API level 21) and higher uses a runtime called ART which natively supports loading multiple DEX files from APK files. ART performs pre-compilation at app install time which scans for classesN.dex files and compiles them into a single .oat file for execution by the Android device. Therefore if you have your min SDK set to 21 or higher, you do not need the multidex Library.
Here is a more detailed write up about the issue:
https://developer.android.com/studio/build/multidex

My build is ok but d APK It fails.over 64k, I tried google's site to fix the 2 errors although I just get more errors

Hello I get the 2 errors when trying to generate a signed APK. Although when I build the project it has O errors.
I have gone to the links tried to make the modifications but it comes up with more errors
Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
Error:Execution failed for task ':app:transformClassesWithDexForRelease'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException
Configure your app for multidex
Setting up your app project to use a multidex configuration requires that you make the following modifications to your app project, depending on the minimum Android version your app supports.
If your minSdkVersion is set to 21 or higher, all you need to do is set multiDexEnabled to true in your module-level build.gradle file, as shown here:
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 25
multiDexEnabled true
}
...
}
However, if your minSdkVersion is set to 20 or lower, then you must use the multidex support library as follows:
Modify the module-level build.gradle file to enable multidex and add the multidex library as a dependency, as shown here:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 25
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
This is the point I though I should put it in my code. I looked around and tried a couple more locations although I keep getting errors.
android {
compileSdkVersion 25
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.adventure.game"
minSdkVersion 10
targetSdkVersion 25
versionName '1'
versionNameSuffix '1.0'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
If anyone can help, that would be great.
Thanks in advance.
I had the 64k error in one of my apps, and the solution was not to use the multidex.
My problem was that I was importing all the google services with this line in my dependencies: compile 'com.google.android.gms:play-services:10.0.1'. Google brought 64k classes to my app, so I removed this compile line and imported only the services I needed (the location service).
You can find the complete list here.
And this worked for me.
I hope this will help you.

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

Unable to build apk

I am working on current location tracking but when I am trying to build apk it is showing ERRORS WHILE BUILDING APK.I am not getting the problem.
Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_101\bin\java.exe'' finished with non-zero exit value 2
In your build.gradle add this line and try again:
multiDexEnabled true
Have you tried adding the heap size adjustment to your build.gradle file? For example this will set the max heap size for dexing to 4GB, and it will also enable
multiDexEnabled option.
android {
...
dexOptions {
javaMaxHeapSize "4g"
}
defaultConfig {
multiDexEnabled true
}
}
hi we have 2 ways to handle multidex,
first way we should add this snippet of code in gradle
defaultConfig {
applicationId "com.example"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "4g"
}
Second way we can use this code in our Application class,
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
thanks it may be helpful for you
There can be 2 solutions for your problem :
1. As you are developing location tracking app you might have included the whole google play services that includes several libraries.Better you try to include on maps services in you gradle file like
compile 'com.google.android.gms:play-services-maps:8.3.0'
If the above approach doesn't works try to Modify the module-level build.gradle file configuration to include the support library and enable multidex output, as shown in the following code
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'
}
Some of the dependencies's methods cross the 64k limit. Hence you have to introduced a support called as "MULTIDEX SUPPORT".
http://frogermcs.github.io/MultiDex-solution-for-64k-limit-in-Dalvik/
Multidex will allow to have any number of methods in an app (along with its associated third party libraries).
Even though lollipop and above version's do support the app to have any number of methods, pre-lollipop versions support only SINGLE DEX. Due to this, multidex has to be installed(REQUIRED) at the time of app installation. This way, your app can run even on pre-lollipop versions.
Android Studio project works on Lollipop but does not work on Kitkat
This will slow down your app a little bit as multidex will try to extract all the resources from dex files but once this process is done whenever you will open your app it will work fine.
In addition it won't give you any problem after you create a signed apk.

Manifest Merging Failed: Android Studio

I am not sure what's the issue. I googled and though it was about matching the sdk versions. They are the same as follows:
build.gradle
android {
compileSdkVersion 17
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 4
targetSdkVersion 17
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':slidingMenu')
compile project(':slidingMenu')
compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar')
compile files('libs/Parse-1.4.0.jar')
}
Manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gurbani.ujagar"
android:hardwareAccelerated="true"
android:installLocation="preferExternal"
android:versionCode="26"
android:versionName="7.0" >
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="17" />
You will be ended up with this error, If your libraries/modules uses different minSdkVersion or targetSdkVersion inside your project.
To find , In which module actual conflicts are happening you can see your Gradle Console output.
Best practice is to have minSdkVersion 8 at least because most of the libraries like play services etc using this.
Please do the following change and sync Project with gradle
Try to Use minsdkVesion 8 in all your build.gradle files as well as AndroidManifest.xml files ans sync.
If it doesn't solves the problem go through your gradle console to and make required changes as per the error shown.
Note : While compilation, your minSdkVersion and targetSdkVersion in AndroidManifest.xml will be overridden by what you have mention in your build.gradle files.
I think slidingMenu library minSdkVersion is greater than yours (minSdkVersion 4). So manifests cant be merged. You cant use library that requires min version 11 (e.g.) in app that works on api version 4.

Categories

Resources