简体   繁体   中英

How to customize mutliple app in Android Studio?

I have a project in Android Studio and two different app module but both of them are using this same Android library (core code). I want change some resources and logic in application but this code is in core (Android library). How do I approach this? How to customize core code?

I've been asking the same question and after some research, I've found that you have different approach:

Gradle Flavors:

Why Product Flavors?

  • They address the issue of having separate project code for each version of the app while still having one project code.
  • Given a scenario where you have a free and a paid app you can limit features in the free and expose all the other features in the paid version of the app.
  • Given another scenario where you want to implement region-specific functions depending on the country, you can use product flavors for such a use case.
  • White labeling (these are apps that are developed by a certain company, and they are re-branded and resold by other companies).

Pros

  • They address the issue of having a separate project code base for each version of the app.

  • They keep the code tidy and makes it much easier and faster to navigate through the code base as everything related to the specific product flavor would be kept in their corresponding folders.

Cons

  • (Scaling Up) The more variants, the greater the complexity which thereby makes it harder to maintain the codebase. -IDEs sometimes takes time to build the project after switching between variants.

Source: https://levelup.gitconnected.com/simple-guide-to-android-product-flavors-674106455038


Multi-Module

Why?

  • Faster build times.
  • Fine-grained dependency control.
  • Improve reusability across other apps.
  • Improves the ownership & the quality of the codebase.
  • Stricter boundaries when compared to packages.

Pros

  • Scales well as the application grows with new features
  • Medium to large development teams are able to work on different modules without affecting each other (Merge Conflicts)
  • Encapsulates unit and ui tests to their specific features
  • Keeps Resources separated between modules. Which improves readability and organization
  • Keeps logic contained in their own modules, which can be hidden behind interfaces
  • Forces the developer to keep their code better organized and structured
  • Improved build speed, as changes in a module means only that module will need to be rebuilt

Cons

  • Adds additional boilerplate around the construction of the modules
  • More development time overall
  • Requires a maven/gradle file for each module
  • Navigation between module activities can be difficult to setup correctly
  • Requires a lot more pre-planning on how best to structure code, and determining where shared code bases are stored.
  • Limited amount of online resources showing best practices

Source:

Also look at the gradle doc to start with modularizing.

You can build the library's aar and use it in your main projects by simply copying into lib folder in your project directory.

Or you can build it with services like Jitpack and add it to your project by the implementation method in Gradle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM