版权声明:本文为HaiyuKing原创文章,转载请注明出处!

前言

本Demo采用的是其中一个方案,其他方案请阅读参考资料《Android Studio中统一管理版本号引用配置》

使用步骤

一、项目组织结构图

注意事项:

1、  导入类文件后需要change包名以及重新import R文件路径

2、  Values目录下的文件(strings.xml、dimens.xml、colors.xml等),如果项目中存在,则复制里面的内容,不要整个覆盖

二、导入步骤

(1)新建项目后查看app/build.gradle文件,获取版本号(compileSdkVersion、buildToolsVersion、minSdkVersion、targetSdkVersion、support:appcompat、constraint-layout等)

其中,buildToolsVersion的可选值在sdk安装目录下的build-tools中查看(对了,如果使用AS3.0.1新建项目,可能在app/build.gradle文件中看不到buildToolsVersion,那么最后可加可不加,本Demo就不添加了):

新建项目后的app/build.gradle文件:

apply plugin: 'com.android.application'android {compileSdkVersion 27defaultConfig {applicationId "com.why.project.androidcnblogsdemo"minSdkVersion 16targetSdkVersion 27versionCode 1versionName "1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}
}dependencies {implementation fileTree(dir: 'libs', include: ['*.jar'])implementation 'com.android.support:appcompat-v7:27.1.1'implementation 'com.android.support.constraint:constraint-layout:1.1.2'testImplementation 'junit:junit:4.12'androidTestImplementation 'com.android.support.test:runner:1.0.2'androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'}

(2)在项目的build.gradle文件中添加以下代码【根据实际情况扩充,写法类似】

// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript {repositories {jcenter()maven {url 'https://maven.google.com/'name 'Google'}}dependencies {classpath 'com.android.tools.build:gradle:3.1.2'// NOTE: Do not place your application dependencies here; they belong// in the individual module build.gradle files}
}allprojects {repositories {jcenter()google()}
}task clean(type: Delete) {delete rootProject.buildDir
}//Android Studio统一管理依赖版本号引用配置
ext {//修改compileSdkVersion并不会影响我们的我们生成的app在手机先的行为。最理想的情况就是把compileSdkVersion设置到最高。globalCompileSdkVersion = 27//构建工具的版本号是多少,规则是可以用高的构建工具来构建低版本Sdk的工程。使用build-tools目录中的最大版本号即可globalBuildToolsVersion = "27.0.3"//targetSdkVersion的设置主要是当系统版本高于设置的target的时候。然后targetSdkVersion最好和compileSdkVersion一样。globalTargetSdkVersion = 27//这个就是程序运行的最低的要求的Sdk版本号,在低于这个版本号的手机设备上无法安装。globalMinSdkVersion = 16supportLibraryVersion = "27.1.1"/*=================================常用的引用============================================*///supportLibVersion 的头数字是和targetSdkVersion 版本一样的。androidDependencies = [appcompat_v7 : "com.android.support:appcompat-v7:${supportLibraryVersion}",design        : "com.android.support:design:${supportLibraryVersion}",support_v4    : "com.android.support:support-v4:${supportLibraryVersion}",recyclerView : "com.android.support:recyclerview-v7:${supportLibraryVersion}",]/*=================================module中公共用到的引用============================================*/globalDependencies = [//constraintLayout引用constraintLayout : "com.android.support.constraint:constraint-layout:1.1.2",//glide的引用glide : "com.github.bumptech.glide:glide:4.7.1",]
}

(3)修改app/build.gradle

apply plugin: 'com.android.application'android {compileSdkVersion rootProject.ext.globalCompileSdkVersiondefaultConfig {applicationId "com.why.project.androidcnblogsdemo"minSdkVersion rootProject.ext.globalMinSdkVersiontargetSdkVersion rootProject.ext.globalTargetSdkVersionversionCode 1versionName "1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}
}dependencies {implementation fileTree(dir: 'libs', include: ['*.jar'])implementation androidDependencies.appcompat_v7implementation globalDependencies.constraintLayouttestImplementation 'junit:junit:4.12'androidTestImplementation 'com.android.support.test:runner:1.0.2'androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'}

(4)参考app/build.gradle的修改方法修改其他module中的build.gradle文件

混淆配置

参考资料

Android Studio中统一管理版本号引用配置

如何查看buildToolsVersion的版本

Android Studio配置统一管理依赖版本号引用相关推荐

  1. Android Studio中统一管理版本号引用配置

    转载注明gao_chun的Blog:http://blog.csdn.net/gao_chun/article/details/58105089 Gradle统一管理版本号引用配置 为了提高项目开发效 ...

  2. Android studio配置代理下载依赖

    android在开发的时候需要下载gradle或者依赖包是国外的,可以通过设置国内源的方式,接下来介绍使用代理方式进行下载和导入. Gradle代理模式 AS代理 gradle代理 AS代理 AS代理 ...

  3. android studio开发工具介绍,Android应用开发之Android开发工具介绍、Android Studio配置...

    本文将带你了解Android应用开发之Android开发工具介绍.Android Studio配置,希望本文对大家学Android有所帮助. 2.1   Android Studio配置 2.1.1 ...

  4. Maven父工程(统一管理依赖)

      之前一段时间,我和在其他公司工作的同行朋友聊天时无意间聊到项目依赖问题,发现很多公司(包括我们公司)都是有自己一个统一的父工程,而这个工程没有任何的逻辑代码,说起来只有一个pom.xml文件,而这 ...

  5. 【Android NDK 开发】Android.mk 配置静态库 ( Android Studio 配置静态库 | 配置动态库与静态库区别 | 动态库与静态库打包对比 )

    文章目录 I . Android Studio 中使用 Android.mk 配置静态库 总结 II . 第三方动态库来源 III . 配置 Android.mk 构建脚本路径 IV . 预编译 第三 ...

  6. 【Android NDK 开发】Android.mk 配置动态库 ( Android Studio 配置动态库 | 动态库加载版本限制 | 本章仅做参考推荐使用 CMake 配置动态库 )

    文章目录 I . Android Studio 中使用 Android.mk 配置动态库 总结 II . 第三方动态库来源 III . 配置 Android.mk 构建脚本路径 IV . 预编译 第三 ...

  7. java版本号管理_微服务项目中如何管理依赖版本号?

    本文是微服务项目代码组织形式三部曲中的第三篇,也是最后一篇,通过这三篇文章,相信大家对于如果组织微服务中的代码已经有了一个基本认知,前面两篇分别是: 第三篇相对来说要简单一些,本来没打算写,但是上周有 ...

  8. android studio方法的调用树,Android Studio 多层级 Module 对 aar 引用问题解决方法

    最近碰到这么个恶心的问题 问题:有个arr文件被放到Module A中引用,现在Module B又依赖了Module A,则在编译过程中会发生错误,Module B找不到aar文件.(同时如果又有Mo ...

  9. 微服务项目中如何管理依赖版本号?

    本文是微服务项目代码组织形式三部曲中的第三篇,也是最后一篇,通过这三篇文章,相信大家对于如果组织微服务中的代码已经有了一个基本认知,前面两篇分别是: 微服务项目搭建,到底要不要聚合工程? 在微服务项目 ...

最新文章

  1. 【自动驾驶】欧拉角和旋转矩阵之间的转换
  2. inxni扫地机器人_实用型助手,inxni以内扫地机器人 X332
  3. VTK:图片之ImageDivergence
  4. Java 套接字Socket
  5. [Golang] GoConvey测试框架使用指南
  6. python实时监控文件大小_python实现实时监控文件的方法
  7. 西交大计算机考博学术英语,2018年西安交通大学考博英语真题
  8. 博弈树α-β剪枝搜索学习参考资料
  9. sublime java 编译_03 sublime text3下配置Java的编译运行环境
  10. Windows Server 2008 Server Core模式
  11. win7序列号(可激活所有版本)
  12. xp计算机限制打开u盘,XP系统无法读取u盘的解决设置方法
  13. SSE为兼容ie浏览器使用event-source-polyfill
  14. 2019版本ppt如何导出论文所需300dpi像素以上的高清图片
  15. 电力系统风力发电机组测控专用隔离变送器
  16. 机器学习笔记十五之图片文字识别
  17. 全国计算机二级考试设置地点,黑龙江2020年3月全国计算机等级考试考点设置
  18. 一键生成smtp发件服务器文件,附录 D:创建 SMTP 服务器
  19. 静态路由、策略路由与NQA联动
  20. RSD 教程 —— 0 关于 RSD

热门文章

  1. 分享一个 org.w3c.dom XML 封装
  2. JSONObject JSONArray各种用法以及js eval()函数与JSON.parse的区
  3. web service
  4. overflow:hidden;zoom:1 理解转__
  5. 孩子,来生我们一起走
  6. asp自定义函数可以返回数组或者对象
  7. 【转】从源码分析Handler的postDelayed为什么可以延时?
  8. Hbase数据存储架构
  9. WF4.0实战(四):博客申请流程
  10. scala中Stream理解