Android gradle基于架构加载和编译库

我使用以下语句在我的android应用程序中包含了opencv:

compile group: 'org.bytedeco', name: 'javacv', version: '0.11'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', classifier: 'android-x86'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.6.1-0.11', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.6.1-0.11', classifier: 'android-x86'

现在仅使用了四分之二,这既浪费空间,又可能浪费速度.有没有办法只加载/编译属于体系结构的库?我已经读过Gradle android build for different processor architectures,但是该目录使用libs文件夹,因此具有自己的包含.我有所有通过gradle导入的库.

解决方法:

您可以使用gradle口味(documentation).

productFlavors {
    arm {
        ...
    }

    x86 {
        ...
    }

    all {
        ...
    }
}

...

dependencies {
    // For arm
    armCompile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', classifier: 'android-arm'
    armcompile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.6.1-0.11', classifier: 'android-arm'

    // For x86
    x86Compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', classifier: 'android-x86'
    x86Compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.6.1-0.11', classifier: 'android-x86'

    // For all
    allCompile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', classifier: 'android-arm'
    allcompile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.6.1-0.11', classifier: 'android-arm'
    allCompile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', classifier: 'android-x86'
    allCompile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.6.1-0.11', classifier: 'android-x86'
}

然后使用所需的构建变体.

上一篇:Spring(31)——WebClient介绍


下一篇:undefined reference to `std::__cxx11::basic_string