Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Adding some flavor to our apps

Adding some flavor to our apps

Having many applications to manage and maintain can be a pain. Being a multi-brand company, tripsta needs to publish one app per brand (airtickets, travelplanet24 and tripsta). Through this presentation, you will get a glimpse on how we tackle this problem using the flavor mechanism provided by Gradle. What are the benefits as well as the problems and how to overcome them.

Georgios Sarris

December 06, 2017
Tweet

Other Decks in Technology

Transcript

  1. 3 about us 3 Trusted Brands Available in over 50

    countries Available in 20 countries Available in Greece
  2. about us The problems 7 1. High development time 2.

    More bugs 3. Difficult maintenance 4. More unhappy droids Having 3 separate codebases means: !
  3. 9 gradle Gradle build tool • Officially supported by Google

    • Open source • XML vs Groovy • Product Flavors Version Gradle -> 4.1 Gradle build tool -> 3.0.0 Android Studio -> 3.0
  4. 10 gradle Build types A set of properties used when

    building your app Usually configured for different stages of the development lifecycle (i.e debug, release) At least one is required 3 build types Release Debug Staging
  5. 11 gradle Product flavors • Useful for creating multiple versions

    of your application • Maintainability • Per-flavor configurations • Single code base 2 product flavors Full Demo
  6. 12 gradle Flavor dimensions A flavor dimension can be used

    to combine multiple flavors into a group • At least one dimension Error:All flavors must now belong to a named flavor dimension. • Group flavors (brand, type etc) • Ordering matters As of Gradle plugin 3.0 and later
  7. 14 gradle Variants The combination of build types, flavor dimensions

    and product flavor creates a build variant A total of 12 different variants
  8. 15 gradle Source sets Each flavor has its own source

    set(s). By default Android Studio will generate the “main” source set and directory which is used by all flavors. Additional source sets for each flavor can also be created. Can even overwrite default source sets. * Caution when defining .java classes. *
  9. 16 gradle Flavor-specific configuration Variant filters • For cases were

    a specific flavor should be omitted, a variant filter can be used All staging build types for fdroid flavor will be ignored Less clutter
  10. 17 gradle Flavor-specific configuration Flavor specific dependencies • Add different

    dependancies for according to the variant of your app • Add different version of dependancies if targeting different api levels per flavor
  11. 18 gradle Flavor-specific configuration Dynamic manifest • Each flavor gets

    their own manifest • Cross-flavor requirements can be applied using the ${applicationId} variable in the main manifest: <permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature" />
  12. 19 gradle Building Ordering is important! • Source code in

    the java/ is combined into a single output • Manifests and values/ (xml) are merged • Resources in the res/ and asset/ directories are packaged together assemble<flavor(s)><buildType> assembleFdroid -> Builds all Fdroid variants assembleFullPlaystoreRelease -> Builds the FullPlaystore flavor for Release
  13. 24 our implementation Properties • Different endpoints • Different markets

    based on brand • Analytics • Testable • No merging !
  14. 25 our implementation UI elements ../airtickets/res/mipmap/ic_launcher.png ../airtickets/res/values/strings.xml airtickets App icon

    and name travelplanet24 ../travelplanet24/res/mipmap/ic_launcher.png ../travelplanet24/res/values/strings.xml
  15. 26 our implementation UI elements main flavor colors.xml airtickets flavor

    colors.xml tripsta flavor colors.xml Same goes for themes! Colors
  16. 27 our implementation UI elements Drawables, Layouts & Strings •

    Keep things that are common under the main flavor folder • Split layouts into multiple sub-layouts. Easier to reuse and ideal for flavoring • Branded strings are split into their respective flavor folder Strings are merged. Drawables and layouts are not! Remember
  17. 28 Common sidebar_row.xml Per flavor Menu drawables Selector style String

    texts our implementation UI elements - Example
  18. 32 our implementation Deep linking Must have different URI per

    brand Achievable by making a manifest file for each flavor travelplanet24 manifest snippet airtickets manifest snippet
  19. 33 our implementation Release Jenkins https://jenkins.io/
 
 Automation Server
 Continuous

    Integration 
 Continuous Delivery Fastlane
 https://fastlane.tools/
 
 Automation Tool
 Android and iOS
 Written in Ruby
  20. 35 Create lanes for any task you want to automate

    Create .env files for each flavor Fastfile our implementation fastlane alpha --env airtickets fastlane beta --env travelplanet24 Deploy airtickets flavor on alpha channel Promote travelplanet24 flavor to beta channel fastlane <lane> - -env <flavor>
  21. 36 our implementation Monitor - Analytics Each flavor is represented

    as a different app in analytics Easier to keep track Engage to users Run campaigns specifically for certain flavors
  22. 38 Tests Robolectric (http://robolectric.org/) Unit Test Framework Run tests from

    within the JVM of your workstation No Emulators " Ideal for CI (Jenkins etc) BUT problems Doesn’t play well with flavors! android.content.res.Resources$NotFoundException: Unable to find resource ID #0x0 in packages [android, gr.airtickets.activities.dev]
  23. 39 Tests Create a custom test runner Specify the different

    package name amongst other options problems
  24. 40 Annoyances Keep track of what goes where can also

    be time consuming and not clear at first Decide on what can can be split in flavors Refactor can be a pain problems
  25. contact Bye for Now :( We are hiring in product

    development! What are we looking for? ✓ Lead Software Architect! ✓ Scrum Master! ✓ Software Engineers! • Back-end Engineers (with knowledge of Java and/or PHP and/or Python) • Senior Front-end Engineers • iOS Developer • QA Engineer Contact us For questions or further information about this presentation or our company please contact: Georgios Sarris [email protected] [email protected] Please find all details at: http://www.travelplanet24.com/jobs