Error:Execution failed for task ':app:transfor

2019-09-18 04:17发布

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.

1条回答
等我变得足够好
2楼-- · 2019-09-18 04:32

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.

查看更多
登录 后发表回答