Android custom gradle property
When running a project on Android studio, gradle configuration is essential, but as the project grows gradually, what comes to mind is the addition of various dependency packages, countless signatures, channel packages, etc. The entire gradle becomes very messy. In fact, we can separate part of the content of gradle and put it in another custom gradle. For example, the Plugin we add at this time just assign values to it.
- step:
- Create a file in the root directory of the total project (the name can be customized)
- The custom content created in the root directory is as follows:
It should be noted that when adding additional property to Project in the file, we cannot directly define it, but should define it through ext.
Generally, the code we use closures is as follows:
ext { //Add supportLibraryVersion property supportLibraryVersion = '23.1.1' //Add dependenciesretrofitVersion property dependenciesretrofitVersion = '2.0.0-beta2' //Add dependencies array dependencies = [ retrofit : ":retrofit:$retrofitVersion", retrofitConverterGson: ":converter-gson:$retrofitVersion", retrofitAdapterRxJava: ":adapter-rxjava:$retrofitVersion", ] }
You can also not use closures
//Add supportLibraryVersion property = '23.1.1' //Add dependenciesretrofitVersion property = '2.0.0-beta2'
Of course, gradle actually provides many custom properties, some commonly used ones include:
project: Project itself
name: Project name
Description: Project description
version: Project version number
path: The absolute path to Project
buildDir: Project build result storage directory
Add under the root directory
apply from: ''
Then add the dependencies under the app project as follows:
dependencies { //Get custom array Map<String, String> dependencies = compile compile compile }
Of course, other configurations can also be configured, such as defaultConfig
defaultConfig under the current app, refer to the configuration parameters
defaultConfig { minSdkVersion targetSdkVersion }
Thank you for reading, I hope it can help you. Thank you for your support for this site!