3

I have a build problem with Android Studio in a new project I've recreated. Please follow what I've done and if anyone has any idea how to proceed, do tell!

I started a new project, selecting 'Navigation Drawer Activity' as my initial start-point (could be anything I guess). I instantly built my new 'empty' app and debugged it on a real device (a nexus 9). All runs fine.

I then added an office-file-creating library I want to use for creating xlsx files, so I added the following line to my build.gradle app file (in dependencies):

compile 'org.apache.poi:poi-ooxml:3.13'

I resync and it builds ok (within seconds). I then attempt to debug this on a real device but it doesn't build anymore (takes 10x longer to attempt build) and I get an error:

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_25\bin\java.exe'' finished with non-zero exit value 1

I looked this up and every place I look people are telling others to use "multiDex". I understand this applies if you are exceeding 65K methods. I guess with the POI library I might well be exceeding that. After finding no other alternative course of action I implemented multiDex by adding the following lines to my build.gradle app file:

multiDexEnabled true
compile 'com.android.support:multidex:1.0.1'

and adding the following line to my Manifest file:

android:name="android.support.multidex.MultiDexApplication"

I assume I've implemented the multiDex ok. The app builds ok but when I attempt to debug it I am met with this error (takes about 7sec to get here):

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/xmlbeans/xml/stream/Location.class

No other files were tampered with. If I remove the compile POI library line from build.gradle then all is ok. I put the library back in, it fails in the same way. I've tried to figure out how to tell it to ignore the duplicate library in xmlbeans (again other posts tell coders this is what needs to be done) but I'm not sure how to do that and if that is the best way forwards ie should I still be multiDex'ing?

It's taken me a few days on-and-off to get this far and it's my first time using Android Studio - migrating away from Eclipse because I'm fed up of not being able to build my apps for days for no good reason.

Someone who knows what this all means... help me please!

Edit: I have cleaned & rebuilt the project and also tried deleting the build files but to no avail.


Program stats:

Android Studio 1.5.1
Build #AI-141.2456560, built on December 1, 2015
JRE: 1.8.0_25-b18 amd64
JVM: Java HotSpot(TM) 64-Bit Server VM by Oracle Corporation
Gradle ver: 2.8
Android plugin ver 1.5.0

'build.gradle' app file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'org.apache.poi:poi-ooxml:3.13'
    compile 'com.android.support:multidex:1.0.1'
}

'AndroidManifest.xml' file

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.kane.testproject"
          xmlns:android="http://schemas.android.com/apk/res/android">
    <application
        android:name="android.support.multidex.MultiDexApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>
MooMoo
  • 63
  • 9
  • Try to Rebuild project. Deleting Build directories might be helpful too. Also make sure that you don't use same library twice. – hornet2319 Dec 10 '15 at 13:32
  • @hornet2319 yup, already done that but just to be certain I rebuilt it but to no change. Then I deleted any directory within '...app\build' and still the same. – MooMoo Dec 10 '15 at 14:41
  • Did you solved? I really have this issue and not resolved yet – Bhavesh Hirpara Feb 19 '16 at 05:17
  • @BhaveshHirpara Yes. http://stackoverflow.com/questions/35441524/errorexecution-failed-for-task-apptransformclasseswithdexfordebug-after-add – zackygaurav Feb 19 '16 at 12:45

1 Answers1

0

Add the following lines in build.gradle(Module app)

dexOptions {
        javaMaxHeapSize "2g"
    }
F. Knorr
  • 3,045
  • 15
  • 22
Sudhir
  • 1
  • I added this to my `Android` block but it made no difference. Even if I change the heap size to something larger (or smaller) it fails with the same 'duplicate entry' error. – MooMoo Jan 07 '16 at 11:22