0

I am running Android Studio and my app has been running perfect until I do the following. When I add "compile 'com.amazonaws:aws-java-sdk:1.10.1'" to my gradle file, I get the following warnings when I do a project re-build.

Warning:Dependency commons-logging:commons-logging:1.1.3 is ignored for debug as it may be conflicting with the internal version provided by Android. In case of problem, please repackage it with jarjar to change the class packages

Warning:Dependency org.apache.httpcomponents:httpclient:4.3.6 is ignored for debug as it may be conflicting with the internal version provided by Android. In case of problem, please repackage it with jarjar to change the class packages

Warning:Dependency commons-logging:commons-logging:1.1.3 is ignored for release as it may be conflicting with the internal version provided by Android. In case of problem, please repackage it with jarjar to change the class packages

Warning:Dependency org.apache.httpcomponents:httpclient:4.3.6 is ignored for release as it may be conflicting with the internal version provided by Android. In case of problem, please repackage it with jarjar to change the class

When I run the app, I get the 4 warnings like above and 1 error I get when I run my mobile application:

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) Error:Execution failed for task ':mobile:dexDebug'.

I'm thinking this is the main error here:

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 2

UPDATE: nirs answered the reason for this problem. However, it is still not compiling and giving the same errors.

Here is my current gradle file with MultiDex functionality:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.android.uamp"
        minSdkVersion 21
        targetSdkVersion 22
        versionCode 2
        versionName "1.1"

        // Enabling multidex support.
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    lintOptions {
        abortOnError true
    }
    dexOptions {
        preDexLibraries = false
    }

    afterEvaluate {
        tasks.matching {
            it.name.startsWith('dex')
        }.each { dx ->
            if (dx.additionalParameters == null) {
                dx.additionalParameters = ['--multi-dex']
            } else {
                dx.additionalParameters += '--multi-dex'
            }
        }
    }
}

repositories {
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services-cast:7.5.0'
    compile 'com.google.android.support:wearable:1.2.0'
    compile 'com.android.support:support-v4:22.2.0'
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:cardview-v7:22.0.0'
    compile 'com.android.support:mediarouter-v7:22.0.0'
    compile(name: 'CastCompanionLibrary-debug', ext: 'aar')
    compile 'com.github.amlcurran.showcaseview:library:5.0.0'
    compile 'com.amazonaws:aws-java-sdk:1.10.1'
    compile 'com.android.support:multidex:1.0.1'
}

In my main activity, I added this:

public class UAMPApplication extends MultiDexApplication

Instead of this:

public class UAMPApplication extends Application

I have added everything that is required to have a MultiDex Application, but its still not compiling.

Daniel Hair
  • 270
  • 1
  • 4
  • 15

2 Answers2

3

It seems that when you added the Amazon SDK your app reached the maximum method count allowed in Android (over 65K). see here on how to configure your app for multidex: https://developer.android.com/tools/building/multidex.html

nirs
  • 333
  • 1
  • 5
  • Thank you. I really would like to limit the dependencies as discussed in the link, but I'm not sure where to go in order to do that. Would I exclude some parts of the dependencies? Or do you know what website could help me with this? – Daniel Hair Jun 22 '15 at 15:51
  • Unless you have dependencies you don't really use / can strip and take only the relevant code, I would suggest to go to the multi dex path: http://stackoverflow.com/a/27284064/785121 – nirs Jun 23 '15 at 07:51
1

I am going to answer this question and explain why my gradle had errors. (Neville Bonavia from HackHands helped me understand why). It was not a MultiDex problem. In my gradle file, I needed to compile the Android SDK instead of the Java SDK. These are the changes I made:

build.gradle BEFORE

...
    compile 'com.amazonaws:aws-java-sdk:1.10.1'
...

build.gradle AFTER

...
    compile 'com.amazonaws:aws-android-sdk-core:2.2.4'
    compile 'com.amazonaws:aws-android-sdk-s3:2.2.4'
...

My program is now running great! Hope this helps. Lastly, to know if it really is a MultiDex problem, use this program to tell you: https://github.com/mihaip/dex-method-counts from GitHub.

Daniel Hair
  • 270
  • 1
  • 4
  • 15