5

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?

  • https://groups.google.com/forum/#!topic/adt-dev/iSZuHNSdJHI – CommonsWare Oct 09 '14 at 20:28
  • possible duplicate of [How to get current buildType in Android Gradle configuration](http://stackoverflow.com/questions/25739163/how-to-get-current-buildtype-in-android-gradle-configuration) – bummi Dec 12 '14 at 14:19
  • I answered here: http://stackoverflow.com/a/42839705/468360 (easiest solution) – Codeversed Mar 16 '17 at 16:31

1 Answers1

2

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

see my answer for similar problem.

Community
  • 1
  • 1
Alexander Blinov
  • 393
  • 3
  • 13