Android工程结构
目录说明
目录项
- app
- manifasts
- AndroidManifest.xml
- java
- com.example.helloworld
- com.example.helloworld(androidTest)
- com.example.helloworld(test)
- res
- drawable
- layout
- mipmap
- values
- manifasts
- Gradle Scripts
- build.gradle(Project:Hello World)
- build.gradle(Module:app)
- proguard-rules.pro(ProGuard Rules for app)
- gradle.properties(Project Properties)
- settiongs.gradles(Project Settings)
- local.properties(SDK Location)
说明
- app
- manifasts
- AndroidManifest.xml
APP的配置文件
- AndroidManifest.xml
- java
- com.example.helloworld
APP源代码 - com.example.helloworld(androidTest)
- com.example.helloworld(test)
两个APP测试代码
- com.example.helloworld
- res
APP资源文件- drawable 图形描述文件与用户图片
- layout App页面的布局文件
- mipmap 启动图标
- values
一些常量定义文件
字符串常量string.xml
像素常量dimens.xml
颜色常量colors.xml
样式风格定义style.xml
- manifasts
- Gradle Scripts
- build.gradle(Project:Hello World) 项目级编译规则
- build.gradle(Module:app) 模块级编译规则
- proguard-rules.pro(ProGuard Rules for app) Java文件代码的混淆规则
- gradle.properties(Project Properties) 配置编译工程的命令行参数,一般无需改动
- settiongs.gradles(Project Settings) 配置哪些模块在一起编译。初始内容为include ‘:app’,表示只编译App模块
- local.properties(SDK Location) 项目的本地配置,一般无需改动。在工程编译时自动生成,用于描述开发者本机的环境配置,如SDK的本地路径、NDK的本地路径等
编译配置文件build.gradle
项目级build.gradle一般无需改动
下面是初始的build.gradle文件中补充文字注释
apply plugin: 'com.android.application'
android {
//指定编译用的版本号
compileSdkVersion 29
//指定编译工具的版本号。这里的头两位字母数字必须与compileSdkVersion保持一致,具体的版本号可在sdk安装目录的“adk\build-tools”下找到
buildToolsVersion "29.0.2"
defaultConfig {
//指定该模块的应用编号,即App的包名该参数为自动生成,无需修改
applicationId "com.example.myapplication"
//指定App适合运行的最小SDK版本号。
minSdkVersion 15
//指定目标设备的SDK版本号,即该App最希望运行的版本
targetSdkVersion 29
//指定App的应用版本号
versionCode 1
//指定App的应用版本名称
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
//只当是否开启代码混淆功能 true代表开启混淆,false代表无需混淆
minifyEnabled false
//指定代码混淆规则文件的文件名
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
//指定App编译的依赖信息
dependencies {
//指定引用jar包的路径
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//指定单元测试编译用的junit版本号
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
App运行配置AndroidManifest.xml
AndroidManifest.xml用于指定App内部的运行配置
这是一个.xml文件,根节点为manifest。根节点的package制定了该App的包名
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<application //App的自身属性
android:allowBackup="true" //指定是否允许备份
android:icon="@mipmap/ic_launcher" //指定该App在手机屏幕上显示的图标
android:label="@string/app_name" //指定该App在手机屏幕上显示的名称
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" /*true表示支持阿拉伯语/波斯语等
从右往左的文字排列顺序*/
android:theme="@style/AppTheme"> //指定App的显示风格
<activity android:name=".DisplayMessageActivity"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
manifest还有uses-permission子节点
App运行过程中需要用于声明App运行过程中需要的权限名称
application还有
activity 活动
service 服务
receiver 广播接收器
provider 内容提供器
等子节点
学习资料来源:
《Android Studio开发实战 从零基础到App上线》第一章部分内容
–清华大学出版社
本文详细介绍了Android应用的基本工程结构,包括`app`、`manifests`、`java`、`res`目录以及`build.gradle`和`AndroidManifest.xml`的重要性。在`AndroidManifest.xml`中,解释了如何配置App的运行参数和权限声明。此外,还提到了测试代码的位置和资源文件的作用,如`drawable`、`layout`、`values`等。
616

被折叠的 条评论
为什么被折叠?



