The use and configuration of config.gradle in android

config.gradle is a unified configuration file that uniformly configures the same third-party dependency libraries that most modules need to rely on and the basic configuration of the app.
The general model is not used, it is more commonly used in component development. Unified configuration in different modules to prevent possible problems caused by module-dependent version differences.

config.gradle:

ext { //此处为网上找的config配置代码
             android = [
         compileSdkVersion: 27,
        buildToolsVersion: "27.0.3",
        supportVersion   : "27.+",
        targetSdkVersion : 27,
        minSdkVersion    : 17,
        versionCode      : 236,
        versionName      : "2.3.6"
]


// api 测试
apidebug = [
        // 服务器域名
        HostName     : '"http://120.1.1.1"',
        // 用户版端口
        Port_01      : '"8043"'
]

// api 正式
apirelease = [
        // 服务器域名
        HostName     : '"http://120.1.1.1"',
        // 用户版端口
        Port_01      : '"1115"'
]
}
dependencies = [
	okhttputils       : "com.zhy:okhttputils:2.6.2",
        gson          : "com.google.code.gson:gson:2.8.5",
        okhttp3       : "com.squareup.okhttp3:okhttp:3.11.0",
        greendao      : "org.greenrobot:greendao:3.3.0" ,

]

Add at the top of the build.gradle of the total project

		    	apply from: "config.gradle" 

Introduce configuration

Then configure in the module's build.gradle


Please note that when configuring the configuration type, add the suffix name according to the configuration type.
When configuring the android:
introduce the configuration method of config, here pay attention to the configuration of ext.android in rootProject.ext.android.minSdkVersion, after ext is android

	  minSdkVersion rootProject.ext.android.minSdkVersion

The definition in config is

	 minSdkVersion    : 23,

When configuring dependencies

Introducing method, note here that after ext is dependencies. Corresponds to the configured prefix

	implementation rootProject.ext.dependencies.recyclerview

The definition in config is

	recyclerview : 'androidx.recyclerview:recyclerview:1.0.0',

After configuring the SP chameleon, the configuration is complete.

Guess you like

Origin blog.csdn.net/weixin_41422638/article/details/108316869