Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Level Up with Android Build Variants
Phil Shadlyn
July 07, 2015
Programming
0
42
Level Up with Android Build Variants
Phil Shadlyn
July 07, 2015
Tweet
Share
More Decks by Phil Shadlyn
See All by Phil Shadlyn
Kotlin Sequences: Deep Dive
physphil
1
120
Dealing with Imposter Syndrome
physphil
4
31
What is Kotlin Serialization? (And should I use it?)
physphil
0
87
I Wrote an App with Architecture Components
physphil
6
800
Android Auto - Drive Your Car, Use Your Phone, and Don't Hurt Anyone
physphil
0
200
Grokking Android Studio
physphil
0
140
Download This! Tips for Successfully Promoting Your Android App
physphil
0
44
Android Networking (Without Going Crazy)
physphil
0
41
Other Decks in Programming
See All in Programming
Use KMM to call the API of the National Tax Agency
akkeylab
0
300
OSSから学んだPR Descriptionの書き方
fugakkbn
4
130
Qiita Night PHP 2023
fuwasegu
0
11k
新卒でサービス立ち上げから Hasuraを使って3年経った振り返り
yutorin
0
220
まだ日本国内で利用できないAppActionsにトライしてみた / MoT TechTalk #15
mot_techtalk
0
110
Zynq MP SoC で楽しむエッジコンピューティング ~RTLプログラミングのススメ~
ryuz88
0
350
Amazon QuickSightのアップデート -re:Invent 2022の復習&2022年ハイライト-
shogo452
0
220
Gradle build: The time is now
nonews
1
460
Swift Expression Macros: a practical introduction
kishikawakatsumi
2
720
Cloudflare Workersと状態管理
chimame
3
480
TypeScript 4.9のas const satisfiesが便利
tonkotsuboy_com
9
2.3k
%q is for Quine
koic
0
410
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
499
110k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
13
5.4k
Music & Morning Musume
bryan
37
4.6k
The Mythical Team-Month
searls
210
40k
The Web Native Designer (August 2011)
paulrobertlloyd
76
2.2k
JazzCon 2018 Closing Keynote - Leadership for the Reluctant Leader
reverentgeek
175
9.1k
Building Your Own Lightsaber
phodgson
96
4.9k
Principles of Awesome APIs and How to Build Them.
keavy
117
15k
Design by the Numbers
sachag
271
18k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
6
840
VelocityConf: Rendering Performance Case Studies
addyosmani
317
22k
How to name files
jennybc
47
73k
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?