i'm using apache.poi 3.15 to read xlsx file from android . my app show error in 2 conditions Condition one : if i run my app without xml-beans.jar , the app will be build and run and i can declear
XSSFWorkbook workbook = null;
so no error will be apear but if i change my code to this
InputStream fIn = cntx.getResources().getAssets().open("a.xlsx", cntx.MODE_WORLD_READABLE);
XSSFWorkbook workbook = null;
workbook=new XSSFWorkbook(fIn);
app will successfuly build , after run will stop and show this error :
java.lang.VerifyError: org/apache/poi/xssf/usermodel/XSSFWorkbook
Condition two : if i depend xmlbeans.jar , android studio will terminate build process and show this error:
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
this is my gradle :
defaultConfig {
applicationId "com.ramin.test"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
//enable Multi Dex
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
preDexLibraries false;
javaMaxHeapSize "4g"
}
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = ['--multi-dex']
} else {
dx.additionalParameters += '--multi-dex'
}
}
}
dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.1.1'
compile files('libs/poi-3.15.jar')
compile files('libs/poi-ooxml-schemas-3.15.jar')
compile files('libs/poi-ooxml-3.15.jar')
compile files('libs/xmlbeans-2.6.0.jar')}
what i should do
finally i found solution here https://github.com/andruhon/AndroidReadXLSX . just need to append this jar files not more ! :
compile files('libs/aa-poi-3.10-min-0.1.5.jar')
compile files('libs/aa-poi-ooxml-schemas-3.10-reduced-more-0.1.5.jar')
and other lines in gradle that we need to build :
defaultConfig {
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
preDexLibraries false;
javaMaxHeapSize "4g"
}
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = ['--multi-dex']
} else {
dx.additionalParameters += '--multi-dex'
}
}
}
Maybe this help some one ...