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>