android studio 项目结构必知

来源:互联网 发布:智取数字3软件 编辑:程序博客网 时间:2024/06/14 01:40

这里写图片描述

android studio 可以切换浏览模式,有:
这里写图片描述
不同模式下,显示不同的列表视图文件。
但是本质都是一样的,只是显示分类不同。

这里我们选择“Android”进行说明。

1)android studio一个项目对应一个窗口;
Eclipse中的WorkSpace相当于Studio中的Project.
2)
build.gradle (project: 项目名)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath ‘com.android.tools.build:gradle:2.1.2’

    // NOTE: Do not place your application dependencies here; they belong    // in the individual module build.gradle files}

}

allprojects {
repositories {
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

这个对应过程的下载库的地址。 jcenter()
公用的依赖库
classpath ‘com.android.tools.build:gradle:2.1.2’
该gradle-2.1.2.jar包,项目先从本地studio安装目录下仓库中查找是否存在,我的目录:
E:\Program Files\Android\Android Studio\gradle\m2repository\com\android\tools\build\gradle
这里写图片描述
我本地仓库中有这个2.1.2的jar包,所以不需要从远程服务器下载。

如果你本地没有2.1.2版本,那么studio会自动下载,下载目录:
C:\Users\lihui20.gradle\caches\modules-2\files-2.1\
下回下载配置文件中的各类jar包(前提本地仓库没有)

3)build.gradle(Module:app)
Eclipse中的Project相当于AS中的Module(只就新建而言)。
apply plugin: ‘com.android.application’

android {
compileSdkVersion 24
buildToolsVersion “24.0.3”

defaultConfig {    applicationId "com.example.lihui20.myapplication"    minSdkVersion 10    targetSdkVersion 24    versionCode 1    versionName "1.0"}buildTypes {    release {        minifyEnabled false        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'    }}

}

dependencies {
compile fileTree(dir: ‘libs’, include: [‘*.jar’])
testCompile ‘junit:junit:4.12’
compile ‘com.android.support:appcompat-v7:24.2.1’
}

这里面都当前项目的配置。
compileSdkVersion 24
编译的sdk版本;
buildToolsVersion “24.0.3”
sdk中下载的工具;
compile fileTree(dir: ‘libs’, include: [‘*.jar’])
testCompile ‘junit:junit:4.12’
compile ‘com.android.support:appcompat-v7:24.2.1’
项目依赖的jar包和库library

4)gradle.properties(Global properties)
全局配置文件。
C:\Users\lihui20.gradle\gradle.properties

ject-wide Gradle settings.

IDE (e.g. Android Studio) users:

Settings specified in this file will override any Gradle settings

configured through the IDE.

For more details on how to configure your build environment visit

http://www.gradle.org/docs/current/userguide/build_environment.html

The Gradle daemon aims to improve the startup and execution time of Gradle.

When set to true the Gradle daemon is to run the build.

TODO: disable daemon on CI, since builds should be clean and reliable on servers

org.gradle.daemon=true

Specifies the JVM arguments used for the daemon process.

The setting is particularly useful for tweaking memory settings.

Default value: -Xmx10248m -XX:MaxPermSize=256m

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

When configured, Gradle will run in incubating parallel mode.

This option should only be used with decoupled projects. More details, visit

http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects

org.gradle.parallel=true

Enables new incubating mode that makes Gradle selective when configuring projects.

Only relevant projects are configured which results in faster builds for large multi-projects.

http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:configuration_on_demand

org.gradle.configureondemand=true

注意:
配置org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m
项目的内存 大小。
C:\Users\lihui20.gradle\gradle.properties

5)gradle.properties(project properties)
C:\Users\lihui20\Desktop\MyApplication\gradle.properties

Project-wide Gradle settings.

IDE (e.g. Android Studio) users:

Gradle settings configured through the IDE will override

any settings specified in this file.

For more details on how to configure your build environment visit

http://www.gradle.org/docs/current/userguide/build_environment.html

Specifies the JVM arguments used for the daemon process.

The setting is particularly useful for tweaking memory settings.

Default value: -Xmx10248m -XX:MaxPermSize=256m

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

When configured, Gradle will run in incubating parallel mode.

This option should only be used with decoupled projects. More details, visit

http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects

org.gradle.parallel=true

全部注释掉了,使用默认的配置

6)settings.gradle
C:\Users\lihui20\Desktop\MyApplication\settings.gradle

include ‘:app’

7)local.properties
C:\Users\lihui20\Desktop\MyApplication\local.properties

sdk.dir=C:\Users\lihui20\AppData\Local\Android\Sdk
sdk路径,可以自己指定。

记录:
sdk下载的library库 以及 jar包
E:\AndroidStudio\Local\Android\sdk\extras

studio自带的库:
E:\Program Files\Android\Android Studio\gradle\m2repository

studio自带的gradle 版本:
E:\Program Files\Android\Android Studio\gradle\gradle-2.10

本地库没有的jar包或者library,远程服务器下载:
C:\Users\lihui20.gradle\caches\modules-2\files-2.1

1 0
原创粉丝点击