Unable to build apk - android

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.

Related

Qt Android app error: com.android.builder.dexing.DexArchiveMergerException

So I am having this strange error when I try to compile my Qt application for Android. My build.gradle is practically (except for package name) the same as this one here https://github.com/Larpon/QtFirebaseExample/blob/master/App/platforms/android/build.gradle. When I try to compile however I get a long list of errors beginning with:
What went wrong: Execution failed for task ':transformDexArchiveWithExternalLibsDexMergerForDebug'.
BUILD FAILED in 8s 21 actionable tasks: 8 executed, 13 up-to-date com.android.builder.dexing.DexArchiveMergerException: Error while
merging dex archives:
I have read similar threads on here which suggest enabling multiDexEnabled = true, I have already tried and also tried to clean my app but it doesn't work. I have also tried to add implementation 'com.android.support:multidex:1.0.3' in the dependencies section of my build.gradle but no luck. Finally I have also set but nothing works.
defaultConfig {
applicationId "packagename" // Used by Firebase auto-config (the google-services.json from Firebase console)
minSdkVersion 23
targetSdkVersion 28
//versionCode 1
//versionName "1.0"
//testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
// Enabling multidex support.
multiDexEnabled = true
}
So I was able to fix the problem by migrating to AndroidX as noted here https://developer.android.com/jetpack/androidx/migrate. After modifying the necessary files the compilation error disappeared.

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

Exception while running app below Lollipop devices [duplicate]

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 :)

Android Studio: Why am i getting multi dex error on brand new Google Maps API project?

I'm relatively new to Android programming and I am trying to create a Google Maps project. I used the template option in Android Studio, and I added the key for the API.
I haven't added any of my own code and left the template code as is because I just wanted to run the code and see what it looks like, however, I keep getting a multi dex error when I try to run this on the emulator causing the build to fail. It's weird to me that I am getting this error because I haven't added ANY code at all and am using what the Google Maps template has from Android Studio.
Anyone know why this error shows up on a brand new project? The error I see is pasted below.
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_91\bin\java.exe'' finished with non-zero exit value 2
as quoted below:
Your probably compiling all of the play-services API's using compile 'com.google.android.gms:play-services:9.2.0'... Now we can selectively compile API's to avoid dex limit of 64K. For Google Maps use com.google.android.gms:play-services-maps:9.2.0... – Loki Jul 1 at 19:01
Answer from Loki worked and was very simple to do.
setting up google play services
Go through this link just add the dependencies which you want in your application.
This will prevent 64k exceeding error.
Happy coding.
For those who tried all the above methods and failed. Try changing the mini sdk version to 21 in the build.gradile file. For me it was on 16 and when I changed it to 21 the multidex error was gone for good.
minSdkVersion 21
The issue is you currently have a high number of methods. There can only be 65536 methods for dex. You can try enabling multiDex by editing your build.gradle file.
android {
//stuff
defaultConfig {
...
// Enable multiDex support.
multiDexEnabled true
}
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Also, oops as the poster above mentioned in your manifest you also need to add that you are using the multidex class from the multidex support library.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.dexapp">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
Change your Gradle build configuration to enable multidex
android {
compileSdkVersion 23
buildToolsVersion "24.0.0 rc2"
defaultConfig {
applicationId "com.try.app"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
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>
Note: Visit https://developer.android.com/studio/build/multidex.html for more info.
Set property multiDexEnabled to true in defaultConfig. This error occurs when method references increase the limit of 65k. Check Google Play Service APIs.
android{
...
defaultConfig {
...
multiDexEnabled true
}
...
}
Here is a good source to get started with Google Maps Android API
I removed the dependencies as suggested by Loki and it works.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.google.android.gms:play-services-maps:9.4.0'
}

Categories

Resources