简体   繁体   English

Gradle / android:单个ndk构建多种口味?

[英]Gradle/android: single ndk build for multiple flavors?

i've got a build.gradle file setup with the following (i've obviously excluded parts that shouldn't matter for brevity): 我有一个build.gradle文件设置与以下(我显然排除了为简洁起见无关紧要的部分):

android { defaultConfig { ndk { abiFilters 'armeabi', 'armeabi-v7a', 'x86' } }
productFlavors {
    flavor1 { ... }
    flavor2 { ... }
    flavor3 { ... }
    flavor4 { ... }
    flavor5 { ... }
}
buildTypes {
    debug {
        externalNativeBuild { ndkBuild { cFlags '-DDEBUG' } }
        ...
    }
    release {
        externalNativeBuild { ndkBuild { cFlags '-DRELEASE' } }
        ...
    }
}
externalNativeBuild {
    ndkBuild {
       path 'jni/Android.mk'
    }
}

it works , but it compiles the native code for each flavor+buildType. 工作 ,但它编译每个flavor + buildType的本机代码。 so not only debug and release, but also flavor1Debug, flavor2Release, etc., which takes forever 所以不仅调试和发布,而且还有flavor1Debug,flavor2Release等,这需要永远

how do i tell gradle to only do the externalNativeBuild for the two build types, and to use those for all the flavors? 我如何告诉gradle只为两种构建类型执行externalNativeBuild,并将它们用于所有类型?

This is true, if you look into the file .externalNativeBuild/ndkBuild/flavor1Debug/armeabi/ndkBuild_build_command.txt , you will see something similar to mine: 这是真的,如果你查看文件.externalNativeBuild/ndkBuild/flavor1Debug/armeabi/ndkBuild_build_command.txt ,你会看到类似于我的东西:

Executable : ~/Library/Android/sdk/ndk-bundle/ndk-build
arguments : 
NDK_PROJECT_PATH=null
APP_BUILD_SCRIPT=~/proj/jni/Android.mk
APP_ABI=armeabi
NDK_ALL_ABIS=armeabi
NDK_DEBUG=1
APP_PLATFORM=android-21
NDK_OUT=~/app/build/intermediates/ndkBuild/flavor1/debug/obj
NDK_LIBS_OUT=~/app/build/intermediates/ndkBuild/flavor1/debug/lib
APP_SHORT_COMMANDS=false
LOCAL_SHORT_COMMANDS=false
-B
-n
jvmArgs : 

and so on for each buildVariant . 等等每个buildVariant What you can do to reduce build time? 你可以做些什么来减少构建时间?

  1. Extract the time-consuming part into a static library (or a set of static libraries), and leave only final link for the integrated ndkBuild . 将耗时的部分提取到静态库(或一组静态库)中,并仅为集成的ndkBuild保留最终链接。 Use these static libraries as $(PREBUILT_STATIC_LIBRARY) . 将这些静态库用作$(PREBUILT_STATIC_LIBRARY)

  2. Disable the integrated ndkBuild altogether, and set 完全禁用集成的ndkBuild,然后设置

     jniLibs.srcDir 'src/main/libs' 

    The easiest way to disable integrated ndkBuild is by pointing 禁用集成ndkBuild的最简单方法是通过指向

     jni.srcDirs = [] 

    But you can also keep Android Studio indexing of your cpp files, but disable the gradle task: 但您也可以保留Android Studio索引cpp文件,但禁用gradle任务:

     tasks.all { task -> if (task.name.startsWith('compile') && task.name.endsWith('Ndk')) { task.enabled = false } } 

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

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