I am having trouble to properly import the Apache POI dependencies I need to run in my Java program. I do need to use some classes to manipulate a .docx file in my program. Since I am doing it in Android Studio, I am importing all the dependencies I need through gradle. However, I am facing some trouble during those imports.
Since I am manipulating some lists in my Word/docx file, I need to use the CTLevelSuffix and STLevelSuffix classes. However, if I implement just org.apache.poi:poi-ooxml:5.2.3
, those classes cannot be found.
So, I thought that I should use the org.apache.poi:poi-ooxml-full:5.2.3
implementation. However, if I do so, those 2 classes can be imported, however, all the org.apache.poi.xwpf.usermodel.*
classes are not imported.
//These imports do not work if I only use "implementation 'org.apache.poi:poi-ooxml-full:5.2.3' "
import org.apache.poi.xwpf.usermodel.XWPFAbstractNum;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFNumbering;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
//----------------------------
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLvl;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNumPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STNumberFormat;
//-----------------------------------
//These imports do not work if I only use " implementation 'org.apache.poi:poi-ooxml:5.2.3' "
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLevelSuffix;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLevelSuffix;
Then, I thought that my problems would be solved if I implemented both poi-ooxml
and poi-ooxml-full
. However, if I do so, I get plenty of building errors, which a small amount of them will be shown here:
...
Duplicate class org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShapeNonVisual found in modules jetified-poi-ooxml-full-5.2.3 (org.apache.poi:poi-ooxml-full:5.2.3) and jetified-poi-ooxml-lite-5.2.3 (org.apache.poi:poi-ooxml-lite:5.2.3)
Duplicate class org.openxmlformats.schemas.presentationml.x2006.main.CTHandoutMasterIdList found in modules jetified-poi-ooxml-full-5.2.3 (org.apache.poi:poi-ooxml-full:5.2.3) and jetified-poi-ooxml-lite-5.2.3 (org.apache.poi:poi-ooxml-lite:5.2.3)
Duplicate class org.openxmlformats.schemas.presentationml.x2006.main.CTHandoutMasterIdListEntry found in modules jetified-poi-ooxml-full-5.2.3 (org.apache.poi:poi-ooxml-full:5.2.3) and jetified-poi-ooxml-lite-5.2.3 (org.apache.poi:poi-ooxml-lite:5.2.3)
...
I get that both poi-ooxml
and poi-ooxml-full
have the same classes and that's why the building keeps failing. However, I do not know how to fix this error since I wasn't able to find a way to import the classes that I need.
Can someone help?
By the way, the implementation snippet of my build.gradle(:app) file looks like that:
...
dependencies {
...
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.github.bumptech.glide:glide:4.13.1'
implementation 'com.github.Gavras:MultiLineRadioGroup:v1.0.0.6'
implementation 'org.apache.poi:poi-ooxml-full:5.2.3'
implementation 'org.apache.poi:poi-ooxml:5.2.3'
...
}