android-studio-3.0apache-poi-4

How to fix the Java Compiler error in Android Studio when using Apache POI


I'm developing an Android App in Android Studio with Java Coding. In this app when user clicks a button an excel file gets saved in external storage with some data.

For this I'm using Apache POI 4.1.0. I have added this in dependencies, but when I run the app error is coming as below

Error: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)

android {    

    compileSdkVersion 27
    defaultConfig {
    applicationId "xxxxxxx"
    minSdkVersion 23
    targetSdkVersion 27
    versionCode 4
    versionName "1.0.3"
    testInstrumentationRunner 
    "android.support.test.runner.AndroidJUnitRunner"
    signingConfig signingConfigs.config
}
    buildTypes {
      release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
}
dependencies {    
    implementation 'org.apache.poi:poi:4.1.0'
    implementation 'org.apache.poi:poi-ooxml:4.1.0'
}

Solution

  • Finally I got the solution for my issue. Instead of using Apache POI, I used FileWriter for CSV format. Below is the reference for this.

    https://stackabuse.com/reading-and-writing-csvs-in-java/