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

Proper method of mixing xml layouts with Views
Android: issue with customizing ExpandableListView
Android list of choices or custom text [closed]
Android - SQLite
Resizing bitmap from InputStream
Set width of LinearLayout declared in XML Programatically
Using the jcharset library
Android HelloGoogleMaps to OSMdroid (Open Street Maps)
Access youtube account with accountmanager
How to detect USB device in Android
How to save 2 strings in SharedPreferences
Using comment box in an Android/PhoneGap app
How to implement multi selection picker using alert dialog builder in android [closed]
android achartengine - How to recognize which bar is touched in a bar chart?
android listview adapter not showing the correct data
Lazy loading images on ListView not getting refreshed

Categories

HOME
shell
notepad++
httparty
google-cloud-platform
porting
deep-learning
awk
polymer
dns
phpmyadmin
google-spreadsheet
camera
seo
3d-reconstruction
regular-language
polling
sendgrid-api-v3
mql5
zerobrane
atlassian
gruntfile
coin3d
glyphicons
database-connection
breadth-first-search
poedit
kendo-mobile
imagemap
href
flask-sqlalchemy
short-url
android-sharedpreferences
apktool
8051
datastax-enterprise-graph
paperjs
deltaspike
memory-address
gojs
lubridate
alphabetical
dm-script
connection-pool
node-mssql
health-monitoring
logback-groovy
outputcache
xmldocument
wpas
sundials
janus
py2neo
branch-prediction
cronexpression
simplepie
centrifuge
tooleap
udpclient
project-organization
dbamp
uiactionsheet
character-replacement
atoi
snackbar
contrast
sql-scripts
terminate
vsx
koala
sphinxql
ie8-compatibility-mode
gpars
onload-event
booksleeve
redis-py
adobe-media-server
apache-whirr
matlab-load
xcelsius
cdonts
presentation-layer
non-clustered-index
cfwindow
escrow
scrubyt
flvplayback
contentpresenter
cardspace

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