Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle get current build type

all!

I'm trying to get Gradle generate different files (Android.mk and Application.mk) for the release and debug builds. Default way, gradle android plugin doing so doesn't suit me, because it doesn't allow to modify Application.mk, I want to. The main problem is that I can not identify current build type. I tried the following:

android {
    ...
    defaultConfig {
        project['CONFIGURATION_FLAGS'] = ''

        project['APP_ABI'] = ''
        project['APP_PLATFORM'] = 'android-9'
        project['APP_STL'] = 'gnustl_static'
        project['NDK_TOOLCHAIN_VERSION'] = 'clang'
    }
    buildTypes {
        release {
            project['CONFIGURATION_FLAGS'] = '-fvisibility=hidden'
            project['APP_ABI'] = 'armeabi x86'
        }
        debug {
            project['CONFIGURATION_FLAGS'] = '-g -DDEBUG -DENABLE_LOG'
            project['APP_ABI'] = 'armeabi'
        }
    }
}
task processTemplates {
    def templatesDir = System.getProperty('user.dir') + '/app/templates'
    def jniDir = System.getProperty('user.dir') + '/app/src/main/jni'

    // Android.mk
    def configFlags = project['CONFIGURATION_FLAGS']

    def androidMk = file(templatesDir + '/Android.mk').text
    androidMk = androidMk.replaceAll '<CONFIGURATION_FLAGS>', configFlags
    def newAndroidMk = new File(jniDir + '/Android.mk')
    newAndroidMk.text = androidMk

    // Application.mk
    def appAbi = project['APP_ABI']
    def appPlatform = project['APP_PLATFORM']
    def appStl = project['APP_STL']
    def toolchain = project['NDK_TOOLCHAIN_VERSION']

    def applicationMk = file(templatesDir + '/Application.mk').text
    applicationMk = applicationMk.replaceAll '<APP_ABI>', appAbi
    applicationMk = applicationMk.replaceAll '<APP_PLATFORM>', appPlatform
    applicationMk = applicationMk.replaceAll '<APP_STL>', appStl
    applicationMk = applicationMk.replaceAll '<NDK_TOOLCHAIN_VERSION>', toolchain
    def newApplicationMk = new File(jniDir + '/Application.mk')
    newApplicationMk.text = applicationMk
}

But found that the setting of parameters is performed 2 times, that is, for each type of build, regardless of the current build type. Which leads to the fact that for any type of build it set debug options. Can anyone advise me how to solve this problem?

like image 597
Mikhail Shikin Avatar asked Nov 01 '22 16:11

Mikhail Shikin


1 Answers

Add a task which depends on each assembleXxx task and property setting up after it invoked

see my answer for similar problem.

like image 81
Alexander Blinov Avatar answered Nov 15 '22 05:11

Alexander Blinov