简体   繁体   English

根据android版本从两个版本的库中加载类

[英]Load classes from two versions of library depending on android version

I'm trying to use two modified Apache POI libraries.我正在尝试使用两个修改后的 Apache POI 库。 Each libray has modifications to work properly on android 4.+ and 5.+.每个库都有修改以在 android 4.+ 和 5.+ 上正常工作。

I need to import specific class of specific library depending on android version.我需要根据 android 版本导入特定库的特定类。

For example:例如:

Android 4.+ versions:安卓 4.+ 版本:

import org.apache.poi.xssf.usermodel.XSSFWorkbook; of compile files('libs/aa-poi-3.10-min-0.1.5.jar')compile files('libs/aa-poi-3.10-min-0.1.5.jar')

Android 5.+ versions: Android 5.+ 版本:

import org.apache.poi.xssf.usermodel.XSSFWorkbook; of compile files('libs/poi-3.12-android-a.jar')compile files('libs/poi-3.12-android-a.jar')

How could i do this?我怎么能这样做? Thanks谢谢

Define two flavours定义两种口味

productFlavors {
    android4plus {
        minSdkVersion 14
    }
    android5plus {
        minSdkVersion 21
    }
}

Now you can setup different dependencies per flavour现在您可以为每种口味设置不同的依赖项

android4plusCompile files('libs/aa-poi-3.10-min-0.1.5.jar')
android5plusCompile files('libs/poi-3.12-android-a.jar')

As result, you can switch between flavours during development and will have two APK files to distribute.因此,您可以在开发过程中在不同风格之间切换,并且将有两个 APK 文件要分发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM