3

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

Simon
  • 1,890
  • 19
  • 26

1 Answers1

4

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

Community
  • 1
  • 1
Simon
  • 1,890
  • 19
  • 26
  • This makes sense. The apache POI library in incredibly huge in terms of number of files. No wonder it needs a special flag. Makes me wonder if I should be using such a power tool to parse an XML sheet.. – StarWind0 Aug 25 '15 at 19:51
  • Have you experienced any issues with apache POI on Android yet? I'm thinking of using it but I'm not sure it's okay with all the old android devices.. – Jenix Feb 17 '18 at 13:43