android studio build variants

14
Android Studio Build Variants

Upload: edipo-souza

Post on 08-Jan-2017

932 views

Category:

Presentations & Public Speaking


0 download

TRANSCRIPT

Page 1: Android studio build variants

Android Studio Build Variants

Page 2: Android studio build variants

About me

Édipo Souza

● Work at GREat/UFC in SeDAn project.

● Édipo Souza has over 3 years experience in android development with degree in Sistemas e Mídias Digitais by Federal University of Ceará.

● He has certifications Oracle Certified Associate Java SE 8 Programmer and Microsoft Programming in HTML5 with JavaScript and CSS3 Specialist.

http://www.ediposouza.com

Page 3: Android studio build variants

● What’s Build Variant?

● Build Variant Advantages

● How to Use Create

● Build Variant and Build Type

● How to Use It

● References

Schedule

Page 4: Android studio build variants

It’s a feature of build system that allows you to create different versions of same app in a single project.

What’s Build Variant?

Page 5: Android studio build variants

● Demo version (incomplete app)

● Free version (full app advertising)

● Pro version (full app without advertising)

● Trial version (full app for a limited time)

● Specific version for devices with physical buttons

What’s Build Variant?

Page 6: Android studio build variants

● Centralize and organize all code related to your application

● Avoid code duplication in separate projects

● Facilitate the implementation of maintenance

● Keep all versions always updated

Build Variant Advantages

Page 7: Android studio build variants

● For each new version of the app, declare a flavor within item productFlavors in app build.gradle with a name that define it.

● You can overwrite any existing items in DefaultConfig like applicationId in example bellow.

productFlavors { demo { applicationId "com.ediposouza.app_name.demo" } full { }}

How to Create

Page 8: Android studio build variants

● Create a folder with same flavor name in src directory with java within it.

● You can also create Assets and res folders with files for this specific version.

● The variant can also have a Manifest with particular configuration that will be merged with main Manifest.

How to Create

Page 9: Android studio build variants

● Each build variant is a formed with combination of a flavor and a build type.

● All versions can be builded as debug or release type.

● You can still use BuildConfig.DEBUG boolean value to make adaptations between test version and production version. Ex: boolean serverUrl = BuildConfig.DEBUG ? testUrl : prodUrl;

Build Variant and Build Type

Page 10: Android studio build variants

● The classes and resources of active build variant will be merged with the main files.

● You can’t have a class in any variant with same name of one in main folder. However between two variant you often have classes with same name. The same is valid for resources.

● When create a new class or move an existing one, choose where it will be saved.

How to Use It

Page 11: Android studio build variants

● You can work only with a Build Variant at time and if have some flavor declared, at lest one have to be active.

● Does make sense to define just one flavor, because you main files will always be merged with same Variant files.

● To create test classes for a Build Variant, create a folder androidTest***flavor name***.

● The active variant can be changed in Build Variant tab and Each module have it own Build Variants..

How to Use It

Page 12: Android studio build variants

Demo

Page 13: Android studio build variants

Cool Links:

● http://ediposouza.com/android-studio-build-variant

● https://developer.android.com/tools/building/configuring-gradle.html#workBuildVariants

Questions?

Page 14: Android studio build variants

Contato:[email protected]

www.great.ufc.br

THANKS!!!