alle!Gradle erhalten aktuellen Build-Typ
Ich versuche Gradle zu generieren verschiedene Dateien (Android.mk und Application.mk) für die Veröffentlichung und Debug-Builds. Standardweise, grandle android plugin does so passt mir nicht, weil es nicht erlaubt, Application.mk zu ändern, möchte ich. Das Hauptproblem ist, dass ich den aktuellen Build-Typ nicht identifizieren kann. Ich habe versucht, die folgenden:
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
}
aber festgestellt, dass die Einstellung der Parameter 2-mal durchgeführt wird, das heißt, für jede Art von Build, unabhängig von der aktuellen Build-Typ. Das führt dazu, dass für jede Art von Build Debug-Optionen gesetzt werden. Kann mir jemand raten, wie ich dieses Problem lösen kann?
https://groups.google.com/forum/#!topic/adt-dev/iSZuHNSdJHI – CommonsWare
mögliches Duplikat von [So erhalten Sie den aktuellen BuildType in Android Gradle-Konfiguration] (http://stackoverflow.com/questions/ 25739163/how-to-get-current-buildtype-in-android-gradle-konfiguration) – bummi
Ich antwortete hier: http://stackoverflow.com/a/42839705/468360 (einfachste Lösung) – Codeversed