GithubHelp home page GithubHelp logo

curioustechizen / android-gradle-missing-flavors-demo Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 384 KB

Companion repo for blog post about Android Gradle and missing flavors

Home Page: https://kiranrao.in/blog/2020/03/31/gradle-missing-flavors/

License: Apache License 2.0

android-gradle

android-gradle-missing-flavors-demo's Introduction

This repo demonstrates the use of Android Gradle Plugin's matchingFallbacks and missingDimensionStrategy features. These are used when an Android project has multiple modules with dependencies on each other, and these modules do not agree on the number of flavor dimensions or flavors.

Repo structure

The app itself is a shell. It has no activities, no functionality and almost no Android code. It has 4 modules:

  1. app module. Depends on intermediate-1,intermediate-2 and leaf
  2. intermediate-1 module. Depends on leaf
  3. intermediate-2 module. Depends on leaf
  4. leaf module. Has no dependencies

Flavors

  • Only app and leaf modules care about flavors. I named the dimension as "target" and the flavors as "emulator" and "realdevice" but it doesn't really matter what you call them.
  • The intermediate modules don't care and don't even need to know about flavors.

String resources

To demonstrate how flavors work, I've created some string resources (using gradle's resValue feature) in every flavor, in every module that does care about the flavor. When I build an APK for a particular flavor, I can inspect the string resource in APK analyzer to figure out which variant was used.

In this commit

In this commit, I've basically introduced the same flavor dimensions and flavors in the intermediate modules. I know we started off saying these modules don't care about flavors, but this is the only correct way to do it. This is because the intermediate modules are both of the following

  • Providers for a module that has a flavor dimension
  • Consumers of another module that also has the same flavor dimension

Note: If you don't have these intermediate flavors setup that I demonstrate in this repo, you can absolutely use missingDimensionStrategy or matchingFallback depending on your situation.

I extracted the flavor config to a separate file for use in intermediate flavors. See flavors.gradle

android-gradle-missing-flavors-demo's People

Contributors

curioustechizen avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

android-gradle-missing-flavors-demo's Issues

App & library has multi flavorDimensions & name how pass build ?

Dear Sir

if

application build.gradle

flavorDimensions('abi', 'version', 'environment')

productFlavors {
x86 {
dimension 'abi'
}

armV7 {
dimension 'abi'
}

enterprise {
dimension "version"

}
lite {
dimension "version"

}
dev {
dimension "environment"

}
sit {
dimension "environment"

}
prod {
dimension "environment"

}
}

and

library build.gradle

flavorDimensions('abi' )

productFlavors {
pro {
dimension 'abi'
}

free{
dimension 'abi'
}
}

i add matchingFallbacks & missingDimensionStrategy still build fail

how set it ?

THX

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.