Andure 项目启动与配置教程
1. 项目目录结构及介绍
Andure 项目目录结构如下所示:
andure/
├── app/ # 应用程序目录
│ ├── main/ # 主程序目录
│ │ ├── java/ # Java 源代码目录
│ │ ├── res/ # 资源目录,包含布局文件、图片等
│ │ ├── AndroidManifest.xml # Android 清单文件
│ │ └── build.gradle # 模块构建文件
│ └── build.gradle # 应用程序构建文件
├── gradle/ # Gradle 脚本目录
├── build.gradle # 项目构建文件
├── settings.gradle # 项目设置文件
└── README.md # 项目说明文档
目录详细介绍:
- app/: 应用程序的主要目录,包含了所有与应用程序相关的文件。
- app/main/: 主程序目录,包含了 Java 源代码、资源文件和 Android 清单文件。
- app/main/java/: 存放 Java 源代码的目录。
- app/main/res/: 资源目录,包含了布局文件(layout)、图片(drawable)、字符串资源(strings)等。
- app/main/AndroidManifest.xml: Android 清单文件,描述了应用程序的名称、权限、入口点等信息。
- app/build.gradle: 应用程序模块的构建文件,定义了如何编译和打包应用程序。
- gradle/: Gradle 脚本目录,存放了一些 Gradle 相关的脚本文件。
- build.gradle: 项目构建文件,定义了整个项目的构建逻辑。
- settings.gradle: 项目设置文件,用于配置 Gradle 的项目级设置。
- README.md: 项目说明文档,介绍了项目的相关信息和如何使用。
2. 项目的启动文件介绍
项目的启动文件主要是 Android 清单文件 AndroidManifest.xml
,它位于 app/main/
目录下。以下是 AndroidManifest.xml
文件的基本内容:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.andure">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<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>
这个文件定义了应用程序的基本信息和启动活动(MainActivity)。<activity>
标签中的 <intent-filter>
指定了该活动是应用程序的启动点。
3. 项目的配置文件介绍
项目的配置文件主要是 build.gradle
文件,它位于项目根目录和 app
目录下。
项目级 build.gradle
文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这个文件定义了项目级别的构建脚本,包括所有的依赖项和仓库。
应用程序级 build.gradle
文件:
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.example.andure"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
这个文件定义了应用程序的构建配置,包括编译 SDK 版本、最低 SDK 版本、目标 SDK 版本、应用程序 ID、版本号等,以及应用程序的依赖项。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考