一、前言
现在AndroidStudio应该是大家都在使用的Android开发环境了,但是许多人在安装开发环境时会遇到各种问题,今天就Android配置的几个问题详细讲解一下。
二、详细配置
(1)build配置
repositories {
//本地仓库配置地址
maven { url "http://192.168.0.0:9090/****/public/" }
//国内仓库配置,一般的都能下,下不了可以加一个google()
jcenter(){ url 'http://jcenter.bintray.com/'}
}
(2)classpath的配置
新建项目的时候就是自己studio的版本,但是也可以和studio版本不一致,但需要和gradle--wrapper--gradle-wrapper.properties的配置一致
classpath 'com.android.tools.build:gradle:2.2.3'
三、compileSdkVersion,buildToolsVersion配置
(1)compileSdkVersion
告诉 Gradle 用哪个 Android SDK 版本编译你的应用。使用任何新添加的 API 就需要使用对应 Level 的 Android SDK。就是说这个和运行时无关,只和自己编码时书写的代码规范有关,如代码中有横线等内容就和配置的这个有关
(2)minSdkVersion
minSdkVersion 则是应用可以运行的最低要求。minSdkVersion 是 Google Play 商店用来判断用户设备是否可以安装某个应用的标志之一。如果你的程序要兼容4.0以上的android系统,那就需要写14,如果兼容4.4以上版本就需要写19
(3)
targetSdkVersion
一个Android系统,对外提供一套API,如何选择targetSdkVersion
取决于应用程序需要实现的功能,如果你的应用程序使用API 7就可以实现的功能,可以不用考虑使用API 24,使用低版本API的其中一个好处,可以让更多的Android系统运行的效果保持一致,即兼容性更好,打个比方:API 7开发的APP可能兼容98%以上的Android手机,而API 24开发的APP可能兼容仅有60%,所谓的不兼容并不是无法正常运行,而是在不同Android系统的手机运行的效果差异比较大,会让用户感觉难以接受;使用低版本API的其中一个不足,显示的效果比较OUT,提供的可用的接口或类比较少,本来一句代码可以完成的功能(封装的类或接口),需要自己花一天琢磨写很多的代码,也就是有高版本API的其中一个原因,提供更多的或封装好的应用程序接口让开发者使用。
3、说了这么多,你的APP要是想上架各大官网APP,必须将targetSdkVersion设置为26以上,因为为了安全考虑,以后APP发布的时候要求targetSdkVersion必须>=26.
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.huanyunsoft.portal"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
四、代理配置
可能大家的公司会有网络限制,则需要对studio进行联网,就需要配置代理:File--setting--Appearence--SystemSetting--HTTP proxy;选择Manual proxy configuration进行配置。
配置好以后下载sdk啥的完全没问题,但是下载jar包就会提示证书问题,可能会无法下载,所以尽量不要配置。
五、知识点
在buildType中写resValue,其效果和在string中写values的用法是一致的,可以将一些配置文件放到这里。写法如下:
buildTypes {
debug {
buildConfigField "String", "API_ENV", '"dev"'
resValue "string", "update_url", "{}
signingConfig signingConfigs.Neusoft
minifyEnabled false
}
上面代码的buildConfigFiled,在程序编译时会自动生成buildConfig,可以通过设置不同的debug和release来设置环境的正式版和测试版。
六、附上一个API对应的系统版本对照表
什么是 API 级别?
API 级别是一个对 Android 平台版本提供的框架 API 修订版进行唯一标识的整数值。