Simon
Simon

Reputation: 2066

Cant run an Android Studio project with Apache POI libraries

For the second time I decided to give a try to Android Studio. So I imported a project that uses Apache POI libraries, and others. This is my dependencies:

compile 'com.google.http-client:google-http-client-gson:1.19.0'
compile 'com.google.code.gson:gson:2.1'
compile 'com.android.support:appcompat-v7:19.1.0'
compile 'com.google.android.gms:play-services:+'
compile files('libs/commons-codec-1.9.jar')
compile files('libs/commons-logging-1.1.3.jar')
compile files('libs/google-api-client-1.16.0-rc.jar')
compile files('libs/google-api-client-android-1.16.0-rc.jar')
compile files('libs/google-api-services-drive-v2-rev111-1.16.0-rc.jar')
compile files('libs/google-http-client-1.16.0-rc.jar')
compile files('libs/google-http-client-android-1.16.0-rc.jar')
compile files('libs/google-http-client-jackson-1.16.0-rc.jar')
compile files('libs/google-http-client-jackson2-1.16.0-rc.jar')
compile files('libs/google-oauth-client-1.16.0-rc.jar')
compile files('libs/jackson-core-2.1.3.jar')
compile files('libs/jsr305-1.3.9.jar')
compile files('libs/log4j-1.2.17.jar')
compile files('libs/poi-3.11-20141221.jar')

When I try to run, I have this error:

04:27:59.765 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
04:27:59.766 [ERROR] [org.gradle.BuildExceptionReporter] 
04:27:59.767 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
04:27:59.768 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':app:dexDebug'.
04:27:59.769 [ERROR] [org.gradle.BuildExceptionReporter] > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_75\bin\java.exe'' finished with non-zero exit value 2

When compiling with --stacktrace --info --debug, I get this:

04:27:59.754 [ERROR] [org.gradle.api.Project] AGPBI: {"kind":"SIMPLE","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","position":{},"original":"UNEXPECTED TOP-LEVEL EXCEPTION:"}
AGPBI: {"kind":"SIMPLE","text":"com.android.dex.DexException: Multiple dex files define Lcom/google/api/client/util/StreamingContent;","position":{},"original":"com.android.dex.DexException: Multiple dex files define Lcom/google/api/client/util/StreamingContent;"}

I noticed that when I remove the poi-3.11-20141221.jar everything works fine.

I searched for a long time this issue but I'm starting to get sick of it and considering seriously to return to eclipse for good.

So my question is: What I am suppose to do to get my project works in Android Studio with POI libaries?

Thank you

Upvotes: 3

Views: 3699

Answers (1)

Simon
Simon

Reputation: 2066

I get it!!!

I realize the problem was using Apache POI, google drive and Google Play service libraries in the same project. All these libs introduce too many methods in my project.

To avoid the compile error, I just enable the multiDex in the build gradle:

defaultConfig {
    multiDexEnabled = true
}

And it works! So happy now :)

I found this solution here: Unable to execute dex: method ID not in [0, 0xffff]: 65536

Upvotes: 4

Related Questions