android


Canonical way to write gradle task for adding new Android product flavors


I want to automate work with flavors in Android project, using custom Gradle tasks.
For example, implement addFlavor task with 2 parameters: flavorName and flavorLogo. The task should add new flavor, by making next steps:
Update productFlavors section in build.gradle file, by adding a new flavor to it:
flavorName {
buildConfigField 'String', 'PARTNER', '"flavorName"'
packageName 'com.stackoverflow.askquestion.flavorname'
}
Add flavor folder and copy flavorLogo .png file to flavorName/res/drawable-xxhdpi/ic_launcher.png
What is the correct and canonical way to do it with custom a Gradle task?
You cannot use tasks to create Flavors. Flavors describe the model used to create tasks, so it won't work the other way around.
However, you can diretly put code in your build.gradle that will create this for you everytime the build.gradle is executed (basically everytime you run a Gradle command). You could write something like:
String[] customFlavors = ['flavor1', 'flavor2']
customFlavors.each { name ->
def flavor = android.productFlavors.create(name)
flavor.buildConfigField('String', 'PARTNER', "\"${name}\""
flavor.packageName("com.so.question.${name}")
}

Related Links

handling token changes in notification groups fcm
Multiple colors in Toolbar title?
Intent overlap the dialog box?
Calling a Fragment Method in an Activity causes a Null Pointer Exception
How can obfuscate Sqlite Database in android
Snackbar Not working on API 17
How can I edit the header in a blank activity?
How do i access local area code in Android from locale?
Image from Android to PC
Charles Proxy + Android HTTPS
ScaleGestureDetector and GestureDetector in same view
Is there a performance impact on changing color of vector drawables programmatically?
Android web view does not load specific url
Attempt to invoke virtual method 'void android.widget.CompoundButton.setOnCheckedChangeListener on a null object reference on TabLayout [duplicate]
Retrieve all data from mysql database and display in listview android
Native Activity, GLES2.0: Uploading pixel array to screen

Categories

HOME
shell
facebook-oauth
developer-tools
polymer
apache-flink
vscode-extensions
nuget
mvc5
jquery-ui-sortable
commonjs
openpyxl
cmdb
endpoint
enterprise-architect
heat
standards
intershop
video-editing
google-container-registry
shortest-path
sigma.js
topology
articulate-storyline
springfox
roslyn
short-url
mount
interbase
licensing
ms-access-web-app
panoramas
playstation-portable
installscript
release
print-css
manova
google-cse
er-diagram
bbpress
libjpeg
pybrain
reachability
rocks
cubism.js
i386
respondcms
data-protection
nupic
grass
design-principles
asyncdisplaykit
state-restoration
sapi
grgit
gocql
visual-sourcesafe-2005
sony-lifelog-api
viola-jones
uncompress
baasbox
google-refine
zxspectrum
cross-join
ejb-2.x
nodelist
uncaught-typeerror
lambda-architecture
kissfft
rcaller
wxformbuilder
dct
extjs2
getopt
scriptaculous
hibernate-entitymanager
model-driven-development
mbunit
jeromq
script#
tlf
gpars
pclzip
alice
onmousemove
fragmenttransaction
rmiregistry
paginator
catransform3d
cdonts
timertask
hbm2java
addchild
fault-tolerance
business-model
pbcopy

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App