Android Gradle dependency sub-module

Android add-dependent, generally in the App Moudle directory  build.gradle   inside.

such as:

 

In fact, this is not impossible. But if the gradle in the app directory carries too many things, it will be ugly.

Is there a file or a module specifically responsible for managing dependencies?

The answer is yes. We specifically build a Moudle to manage the dependencies of the entire project.

 

[ Step 1: Create a new Moudle ]

 

Then select, Android Library

 

Then named: resource , of course, the name can be named arbitrarily, but it must be standardized

 

[ Step 2: Create a new configuration version name, config.gradle ]

Of course, this name can also be named arbitrarily, but it must also be standardized

Then, this must be configured, apply for config.gradle in the build.gradle of the  entire project

 

[ Step 3: Write the content of config.gradle ]

such as:

ext {

    android = [
            compileSdkVersion: 28,
            buildToolsVersion: "28.0.3",
            minSdkVersion    : 16,
            targetSdkVersion : 27,
            versionCode      : 33,
            versionName      : "2.5.1"
    ]

    version = [
            androidSupportSdkVersion: "28.0.0",
    ]


    dependencies = [
            "appcompat-v7": "com.android.support:design:${version["androidSupportSdkVersion"]}",
    ]
}

 

[ Step 4: Quote in recource Moudle ]

 

[ Of course, it can also be referenced in other Moudle, such as App Moudle ]

 

[ Finally, in other Moudles, such as App Moudle ]

 

Look, in each Moudle reference VersionCode, versionName, etc., so that changes in config.gradle, all Moudle can be applied.

Achieve unified management.

 

No problem running code tests! ! !

 

 

 

 

Guess you like

Origin blog.csdn.net/Leo_Liang_jie/article/details/93515437