The componentization of a person
Componentized development can improve the long-term productivity of teams, even if there is only one person.
Component isolation, module debugging
Android Component Modularization in Mobile Application Development (Preface)
Restrict each library to relying only on framework code and add a uniform debugging shell to it, rather than turning into an app, wasting conversion time and not having to write two manifest files.
A brief introduction to Gradle will help you build your projects faster.
Gradle projects are built in three phases: initialization, configuration, and execution. When debugging, load only modules that need debugging or joint debugging to speed up the build a bit.
settings.gradle
Gradle initializes Gradle by looking for setting. Gradle.
- To find the
setting.gradle
File. - If not, go to one that has the same nesting level as the current directory
master
Directory lookup. - If not, go to the parent directory.
- If not, proceed to a single-project build.
- If found, Gradle checks the current project in
settings.gradle
Is there a definition in. If not, do a single-project build, otherwise do a multi-project build.
Multi-project projects must have setting.gradle files in the root directory. Single-project projects do not need this file.
In this file we configure the Library we need to debug
include ':app'
/ / necessary
include ': necessary XXX '
// Shell app to load Library
gradle.ext.isAppMap =
[/** -1; 0 libaray; 1 APP*/
': placeholder' : 2 -.':libraryA': 0.':libraryB': - 1,
]
gradle.ext.isDebug = true
gradle.ext.debugModelApp = false
for (String libraryName : gradle.ext.isAppMap.keySet()) {
if. Decide whether to load libaray}Copy the code
The build of the app. Gradle
. dependencies { ...for (String modelName : gradle.ext.isAppMap.keySet()) {
if (gradle.ext.isDebug) {
if (gradle.ext.isAppMap.get(modelName) == 0) {
implementation project(modelName)
}
} else {
implementation project(modelName)
}
}
}
Copy the code
Build. gradle for each library
switch (rootProject.getLoadType(getName())) {
case - 1:
return
case 0:
apply plugin: 'com.android.library'
break
}
Copy the code
The new config. Gradle
ext {
android = [
compileSdkVersion : 29. ] }def config = rootProject.ext.android
// Related library dependencies
subprojects {
afterEvaluate { mProject ->
if (mProject.hasProperty('android')) {
android {
compileSdkVersion config.compileSdkVersion
......
defaultConfig {
if (mProject.getName().equals('app')) {
applicationId "applicationId"
}
minSdkVersion config.minSdkVersion
targetSdkVersion config.targetSdkVersion
}
}
}
dependencies {
}
}
}
Copy the code
In the root project build. Gradle
apply from: "config.gradle"
Copy the code
In this way, creating a new Module requires little configuration. Code can be implemented in this Modulen, and ARouter can be used for different library page jumps, etc.
. To be continued…