2

If i write in my gradle file this code

 apply plugin: 'com.android.library'

    android {
        compileSdkVersion 22
        buildToolsVersion '22.0.1'

        defaultConfig {
            minSdkVersion 9
            targetSdkVersion 22
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile 'com.android.support:appcompat-v7:22.0.0'
    }

all work cool. but if i change

compile 'com.android.support:appcompat-v7:22.1.0'

my app crash. Android studio recomended me change version to 22.1.0 but if i chage version - crash.

Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    C:\Users\zen_75\AppData\Local\Android\sdk\build-tools\22.0.1\dx.bat --dex --no-optimize --output C:\projects\android-customer\app\build\intermediates\dex\debug --input-list=C:\projects\android-customer\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
    2
Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
        at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
        at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
        at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
        at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
        at com.android.dx.command.dexer.Main.run(Main.java:246)
        at com.android.dx.command.dexer.Main.main(Main.java:215)
        at com.android.dx.command.Main.main(Main.java:106)

how do I fix it or leave it?

EDIT:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 22
    buildToolsVersion '22.0.1'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.1.0'
}

i change file - not work!!!

ip696
  • 6,574
  • 12
  • 65
  • 128

2 Answers2

1

You have Over 65K Methods in you project, seems like Google has add a lot of now methods to the appcomapt-v21.1 libs.

Anyway, For now you have those options:
1. Use Multidex, Follow the instructions below, more info here
2. Use the ProGuard
3. Cut down the number of methods you have in your project

You have to keep in mind:

  • Multidex may not work on devices running Android v3.x-, check all limitations here
  • ProGuard is not guaranteed to solve the problem
  • Re-write you code to cut down the number of methods is not easy.

Add multidex support:

build.gradle

android {
    ...
    ...

    defaultConfig {
        ...
        ...
        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

dependencies {
  ...
  ...
  compile 'com.android.support:multidex:+'
}

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="x.xxx.xx">
    <application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>

PS: You can count the number of methods you have in your project using dex-method-counts, it will give you a clear idea about your situation.

JafarKhQ
  • 8,676
  • 3
  • 35
  • 45
0

A possible solution is to start using ProGuard's minify capability. Please note that it breaks Dagger dependency injection over version 1.0.1.

    buildTypes {
        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

Test your application extensibly, as this removes unused methods, and does many other things.

http://developer.android.com/tools/help/proguard.html

EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428