Where add 64K code and where? - android

What code must i add and where to get 64K methods?
I try and build signed APK but it give me issue whole time!
Error:The number of method references in a .dex file cannot exceed 64K.
Error:Execution failed for task
’:myapp:transformClassesWithDexForRelease’. >
com.android.build.api.transform.TransformException:
com.android.ide.common.process.ProcessException:
java.util.concurrent.ExecutionException:
java.lang.UnsupportedOperationException

KUMAR's answer is pretty close but not covering all the details.
Firstly add necessary configuration to your build.gradle of app module:
app/build.gradle
android {
defaultConfig {
multiDexEnabled true
}
}
dependencies
{
compile 'com.android.support:multidex:1.0.1'
}
In the second step you can follow two paths depending on your need.
a. You don't have a custom application class. So you need to add the MultiDexApplication class from the multidex support library to the application element in your manifest:
AndroidManifest.xml
<application
android:name="android.support.multidex.MultiDexApplication"
OR
b. You have a custom application class. So you need to make it extend MultiDexApplication class:
MyApplication.java
public class MyApplication extends MultiDexApplication {
}
AndroidManifest.xml
<application
android:name="MyApplication"
You should be ready to go over 64K method limit.
You can read this tutorial over multidex to understand the logic behind all of these.

If our application is exceeding more than 64K methods then we need to enable the multiDex in our code.
Add the dependency in build.gradle
dependencies
{
compile 'com.android.support:multidex:1.0.0'
}
Enable multidex in build.gradle like the following
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
Now sync your code and run it then it will work.

Related

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

need help on android studio google map

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.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
above is the error message while i run the simulation on genymotion
i updated all the api, actived the google+ for genymotion
i create a google map project from the default project from android studio. can anyone help me out from here?
try suggestion from google
like downgrade the dependencies, add in the multidex true and etc but it still show this error.... yes, i have added the api key also
thanks everyone but i still having error after adding all the suggestionsplease see the image below
Definitely a mutlidex issue, enable mutlidex as follows,
1. Add code
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
There should be an entry in manifest too
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
or if you have an application class then do this instead of above manifest entry
public void onCreate(Bundle arguments) {
MultiDex.install(getTargetContext());
super.onCreate(arguments);
...
}
And make sure you have clicked on sync at top right on build.gradle file, when it appears.
Clean and build.
Theory: https://developer.android.com/studio/build/multidex.html
If issue still persist give gradle file and error log.
Seems like you have gone past the ~65000 method limit. Try enabling multidex if you 're using recent versions of the Android build tools
dependencies {
compile group: 'com.android.support', name : 'multidex', version: '1.0.1'
}
In your android config
android {
defaultConfig {
// flag
multiDexEnabled true
}
}
There should be an entry in manifest or in application class(if it's there) too
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
or if you have an application class then do this instead of above manifest entry
public void onCreate(Bundle arguments) {
MultiDex.install(getTargetContext());
super.onCreate(arguments);
...
}
Edit:
You must be using build tools > 21.1.*

Android 65k multidex issue for android system application

Developing an system application which works with multiple libraries and aar files resulting application get the Multidex 65k issue which is reported by many developers working on Android studio .
In my case as am working on android system build environment not sure how to enable the multidex option ?
Have extended the Application and added MultiDex.install(this); which is making no difference for the compilation resulting
trouble writing output: Too many method references: 156862; max is 65536.
You may try using --multi-dex option.
Not able to find any reference to work on the system build for this kind of issue .
Any pointers on this will be helpful
Thanks
Update in your gradle
defaultConfig {
..............
multiDexEnabled true
}
dexOptions should add..
dexOptions {
//incremental = true;
preDexLibraries = false
javaMaxHeapSize "4g"
}
dependency add
compile 'com.android.support:multidex:1.0.1'
Also In Your AndroidManifest.xml add this lines android:name
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:name="android.support.multidex.MultiDexApplication"
>
Idea is if apk method is > 64K, then we break it to have multiple dex files.
In build.gradle
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
// Add this dependency
compile 'com.android.support:multidex:1.0.0'
}
Hope this helps.
Reference: Android Dev
You can visit Configure Apps with Over 64K Methods for details.
Here some excerpt from it:
Setting up your app development project to use a multidex configuration requires that you make a few modifications to your app development project. In particular you need to perform the following steps:
Change your Gradle build configuration to enable multidex
Modify your manifest to reference the MultiDexApplication class
Modify the module-level build.gradle file configuration to include the support library and enable 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'
}
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>
UPDATE
If you have included Google Play Service library, instead using:
compile 'com.google.android.gms:play-services:9.4.0'
Try to only use what you really need. Something like this:
com.google.android.gms:play-services-base:9.4.0
com.google.android.gms:play-services-ads:9.4.0 // only need ads
com.google.android.gms:play-services-gcm:9.4.0 // only need gcm
Read more at Setting Up Google Play Services.

Multidex application in Eclipse

I've developed an android application in Eclipse which uses lot of library JAR files so i got exception of
Unable to execute dex: method ID not in [0, 0xffff]: 65536
So i thought to implement multidex. I searched many blogs but nothing helps me in the eclipse framework. So i installed the Gradle plugin for eclipse to achive the multidex which was mentioned in many posts (As mentioned here, and Here). Both telling the same method to add
multiDexEnabled true
but its not working
I asked my application class to override
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
and in the gradle file which is builded i edited as
android{
defaultConfig {
minSdkVersion 14 //lower than 14 doesn't support multidex
targetSdkVersion 22
// Enabling multidex support.
multiDexEnabled true
}
}
But it doesn't helped me. Can anyone help me to find how to multidex my application with eclipse or correct way to multidex with the gradle.
add this to your gradle dependencies:
dependencies {
compile 'com.android.support:multidex:1.0.0'
...
}
If that doesn't work, I'm lost as to how to help you because that is the only thing missing that I can see from other answers here on SO.
You need to do 3 things to enable MultiDex:
1) Add following dependency to your build.gradle file:
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
2) Enable multidex in your build.gradle file:
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
3) Finally, if you are using a custom Application class, it should extend MultiDexApplication:
public class MuyApplication extends MultiDexApplication {
}
or if you are not using a custom Application class, do the following in your manifest:
<?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>

Configuring TapJoy Creating Dex FIle issue

I have multiple libraries in my libs folder in android. When I try to add "Tapjoy", I get the error:
unable to execute dex method id not in 0 0xffff 65536 android problem
is coming
and, when I am trying to configure build path and adding external jars,
java.lang.NoClassDefFoundError: com.tapjoy.TapjoyConnect
I'm stuck on this problem. Can any one give me solution?
Congratulation you have reached the 65K method limit you have two options :
a) Clean up some code by removing unnecessary libraries / using ProGuard.
b) Multidex solution , follow these steps
Make sure your Android SDK Build and Android Support Repository are updated to latest version.
Modify your build.gradle by adding the support dex lib and enabling the multidex
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'
}
Modify your manifest:
<?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>
p.s if you already extend Application then just override the attachBaseContext method
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
for more info:
Building Apps with Over 65K Methods

Categories

Resources