0

I want to read a XLSX file, so I am using org.apache.poi:poi-ooxml:3.7

Now I have done everything, no errors so far, but when I am running the application, Android Studio is giving me a weird error

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

Now before marking this question as duplicate, let me tell you what I have done so far:

1. build.gradle File

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "in.example.excel"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
    dexOptions {
        preDexLibraries = false
        javaMaxHeapSize "4g"
    }
}

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


2. Manifest declaration for MultiDex
<application android:name="android.support.multidex.MultiDexApplication" ...

3. readExcelFile(...) method

   private void readExcelFile(String path, Context ironMaiden)
   {
    try
    {
        File iSFile = new File(path);
        FileInputStream inputStream = new FileInputStream(iSFile);

        Workbook workbook = WorkbookFactory.create(inputStream);
        org.apache.poi.ss.usermodel.Sheet sheet = workbook.getSheetAt(0);

        Row row = sheet.getRow(0);

        for (int i = 0; i < row.getLastCellNum(); i++)
        {
            Cell cell = row.getCell(i);
            Log.d("DEBUG", cell.getStringCellValue());
        }
    }
    catch (IOException | InvalidFormatException io)
    {
        io.printStackTrace();
    }
}


4. Rebuild and Clean Yes I have rebuild the project and cleaned it several times. I also did the same through command line gradlew clean and gradlew app:dependencies

I am about to give up on this library. Please Help.

zackygaurav
  • 4,369
  • 5
  • 26
  • 40

1 Answers1

0

I resolved the problem by Adding two JARs externally.

  1. poi-3.9.jar Download
  2. poi-00xml-3.9.jar Download


PS: Please add the JARs externally, adding them via maven generates a confusing error.

zackygaurav
  • 4,369
  • 5
  • 26
  • 40
  • POI 3.9 is rather old, why aren't you using the most recent? – Gagravarr Feb 16 '16 at 23:28
  • If you [check the Apache POI website](http://poi.apache.org/download.html) you can see it's 3.13 final or 3.14 beta 1 - the [list of fixes since 3.9 is very long](http://poi.apache.org/changes.html#3.9)! – Gagravarr Feb 17 '16 at 10:47