不学习,我觉得放假对我来说就是一个休息的过程。。。。完全不适合学习。
而且,这几天打联盟打的我连打字都打不熟练了,我了个擦。
今天跑肯德基来学习了,待会就去新华书店,感觉还是新华书店更安静一点应该。
继续吧,之前的内容。
因为Android Studio不同于eclipse,它是用Gradle来构建项目的,让我们来看一看这个build.gradle(就先看看最外目录下的)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
两个闭包都声明了jece
nter方法,这个jcenter是一个代码托管仓库,声明了这个之后我们就可以引用所有在jcenter上的开源项目了。
classpath声明了一个插件,因为gradle不是只为Android服务的,所以声明一下我现在要
干的活是安卓开发。
再看app目录下的这个build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.example.helloworld"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
Oh my god 怎么这么多。。。
一点一点看吧。
第一行这个com.android.application插件,表示这是一个应用程序模块,com.android.library表示这是一个库模块,应用程序模块可以直接运行,而库模块只能依附于应用程序模块运行。
Android闭包里面全是声明了一些版本号什么的,就不多做解释。
BuildTypes闭包里应该包涵release和debug两个子闭包,但是debug闭包可以不写,那就不写吧。Release闭包里面第一个minifyEnable是代码是否混淆,true和false,另一个就是指定代码混淆的规则。
Dependencies闭包(作者说功能很强大,我怎么不觉得。) 指定当前项目的依赖关系。通常Android studio项目有三种依赖关系,本地依赖、库依赖和远程依赖。
本地依赖可以对本地的jar包或目录添加依赖关系,
库依赖可以对项目中的库模块添加依赖关系,
远程依赖可以对jcenter库上的开源项目添加依赖关系。
Compile fileTree就是一个本地依赖声明,表示将libs目录下所有的jai文件添加到项目的构建路径中。
compile是远程依赖声明,com.android.support是域名部分,appcompat-v7是组名称,25.3.1是版本号。
Grandle在构建项目时会减产一下本地是否已经有这个库的缓存,如果没有的话则会去自动联网下载,然后再添加到项目的构建路径中去,
TestCompile 是声明测试用例库,我们暂时用不到,先忽略。
果然生活还是在不断的学习中才会更加充实。加油吧少年;