Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Level Up with Android Build Variants
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Phil Shadlyn
July 07, 2015
Programming
120
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Level Up with Android Build Variants
Phil Shadlyn
July 07, 2015
More Decks by Phil Shadlyn
See All by Phil Shadlyn
Kotlin Sequences: Deep Dive
physphil
1
210
Dealing with Imposter Syndrome
physphil
4
100
What is Kotlin Serialization? (And should I use it?)
physphil
0
220
I Wrote an App with Architecture Components
physphil
6
1.2k
Android Auto - Drive Your Car, Use Your Phone, and Don't Hurt Anyone
physphil
0
320
Grokking Android Studio
physphil
0
200
Download This! Tips for Successfully Promoting Your Android App
physphil
0
120
Android Networking (Without Going Crazy)
physphil
0
110
Other Decks in Programming
See All in Programming
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
0
1.4k
海上で動くGoサーバー: goroutineとchannelでさばく航行データストリーム
atsuki_seo
0
720
LoopHub - ローカルで動く GitHub で、AI と共同開発
jugyo
1
560
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
130
数年滞っていたダークモード対応をおよそ2週間で完了させる
chigichan24
0
710
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
120
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
3k
SREの越境 / SRE Collaboration
y0hgi
2
220
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
110
iOSDC2026登壇資料.pdf
riofujimon
0
170
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
2.8k
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
180
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.3k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.1k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
3
4.3k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
410
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
990
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
280
Producing Creativity
orderedlist
PRO
348
41k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
230
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
410
Code Reviewing Like a Champion
maltzj
528
40k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Transcript
Level Up with Android Build Variants
Why do I care? • It’d be nice to build
multiple variants of an Android app from a single code base • Common variants include: ◦ debug/release ◦ free/paid ◦ dev/staging/production
With Eclipse and Ant • Code base contained in library
project • Needed an additional project for each variant which referenced library project
None
With Android Studio and Gradle • All contained in single
project • Define Build Types and Product Flavours in build.gradle file • Create src directories to hold code specific to each build type/flavour
None
Build Types • Define how to build and package your
app • debug and release build types created by default • Can create your own
signingConfigs { release { storeFile file( 'release.keystore' ) storePassword 'verysecurepassw0rd'
keyAlias 'release' keyPassword 'verysecurepassw0rd' } } buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile( 'proguard-android.txt' ), 'proguard-rules.pro' signingConfig signingConfigs.release } debug{ applicationIdSuffix ".debug" signingConfig null } }
Product Flavours • Provide alternative code, resources or configuration •
Examples: ◦ Different API endpoints for dev/staging/production environment ◦ Free/paid version
Free / Paid • Provide alternative resources and code by
creating flavour directory • Gradle creates combination of each Build Type and Product Flavour
productFlavors{ free{ applicationId "com.physphil.android.sandbox.free" } paid{ applicationId "com.physphil.android.sandbox.pro" } }
} dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.2.1' compile 'de.greenrobot:eventbus:2.4.0' // Only full version requires network calls paidCompile 'com.squareup.retrofit:retrofit:1.9.0' paidCompile 'com.squareup.okhttp:okhttp:2.2.0' }
None
Free / Paid
Dev / Staging / Production • Define flavour for each
server environment • Store API base URL in a Config class • Create directory in src for each flavour, which contains an instance of Config
buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile(
'proguard-android.txt' ), 'proguard-rules.pro' signingConfig signingConfigs.release } debug { applicationIdSuffix ".debug" signingConfig null } } productFlavors { dev staging production }
None
That’s Not All! • Modify more build parameters • Include
libraries, code, Activities etc only when required • Lots of examples in official docs
Additional Resources • http://tools.android.com/tech-docs/new-build- system/user-guide • https://developer.android. com/tools/building/configuring-gradle.html • http://www.vogella.
com/tutorials/AndroidBuild/article.html
Questions?