Android Studio环境搭建
1.JDK下载安装:
https://www.oracle.com/java/index.html下载JDK1.8.0_161版本
安装后,添加环境变量
2.Android Studio下载安装
https://developer.android.google.cn/studio/index.html下载3.0.1版本
创建新项目
打开Android Studio,选择file-new-new project,输入信息保存,这里的新项目是指新的工作空间
第二个层级通过菜单File-new-new module创建,这里的新模块是指一个单独的APP工程
编译项目:
1.选择build-make project编译项目下的所有模块
2.选择菜单build-make Module ***,编译指定名称的模块
3.选择菜单build-clean project,然后选择菜单build-rebuild project,先清理项目,再对整个项目重新编译
创建模拟器
选择菜单run-run 'app',Android Studio会弹出新窗口Select Deployment Target,选择/创建模拟器
APP工程结构
1.工程目录说明:
app
...manifests
...AndroidManifest.xml----App的运行配置文件
...java
...3个java子目录,其中一个包存放的是App工程的java源代码,另外2个包存放的是测试用的java代码
...res---存放APP工程的资源文件
...drawable---目录存放的是图像描述文件与用户图片
...layout---目录存放的是App页面的布局文件
...mipmap---目录存放的是启动图标
...values---目录存放的是一些常量定义的文件
Gradle Scripts---目录是工程的编译配置文件
...build.gradle,该文件分为项目级和模块级两种,用于描述App工程的编译规则
...proguard-rules.pro,该文件用于描述java文件的代码混淆规则
...gradle.properties,该文件用于配置编译工程的命令行参数,一般无需改动
...settings.gradle,配置哪些模块在一起编译。初始内容为include ':app',表示只编译App模块
...local.properties,项目的本地配置,一般无须改动。该文件是在工程编译时自动生成,用于描述开发者本机的环境配置,如SDK的本地路径等
2.编译配置文件build.gradle
项目级别的build.gradle一般无须改动,只需要关注模块级别的build gradle.
apply plugin: 'com.android.application'
android {
//指定编译用的SDK版本号,如25表示使用Android 7.1编译
compileSdkVersion 26
defaultConfig {
//指定该模块的应用模号,即APP的包名,该参数为自动生成,无须修改
applicationId "com.syj.helloworld"
//指定App适合运行的最小SDK版本号,如15表示最少要在Android 4.0.3上运行
minSdkVersion 15
//指定目标设备的SDK版本号,即该App最希望在哪个版本的Android上运行
targetSdkVersion 26
//指定APP的应用版本号
versionCode 1
//指定App的应用版本名称
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
//指定是否开启代码混淆功能,true表示开启,false表示无须混淆
minifyEnabled false
//指定代码混淆规则文件的文件名
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
//指定App编译的依赖信息
dependencies {
//指定引用jar包的路径
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
//指定单元测试编译用的junit版本号
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
3.APP运行配置
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<!--根节点manifest,package指定了该app的包名-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.syj.helloworld">
<!--application用于指定APP的自身属性,uses-permission用于申明App运行过程中需要的权限名称,allowbackup,用于指定是否允许备份,开发阶段设置为True,上线时设置为false-->
<!--icon用于指定该APP在手机屏幕上显示的图标,label用于指定该APP在手机屏幕上线的名称,supportsRtl设置为True表示支持阿拉伯语/波斯语这种从右往左的文字排列顺序
theme用于指定该APP的显示风格-->
<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活动-service服务-广播接收器receiver-provider内容提供器-->
<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>
1.JDK下载安装:
https://www.oracle.com/java/index.html下载JDK1.8.0_161版本
安装后,添加环境变量
2.Android Studio下载安装
https://developer.android.google.cn/studio/index.html下载3.0.1版本
创建新项目
打开Android Studio,选择file-new-new project,输入信息保存,这里的新项目是指新的工作空间
第二个层级通过菜单File-new-new module创建,这里的新模块是指一个单独的APP工程
编译项目:
1.选择build-make project编译项目下的所有模块
2.选择菜单build-make Module ***,编译指定名称的模块
3.选择菜单build-clean project,然后选择菜单build-rebuild project,先清理项目,再对整个项目重新编译
创建模拟器
选择菜单run-run 'app',Android Studio会弹出新窗口Select Deployment Target,选择/创建模拟器
APP工程结构
1.工程目录说明:
app
...manifests
...AndroidManifest.xml----App的运行配置文件
...java
...3个java子目录,其中一个包存放的是App工程的java源代码,另外2个包存放的是测试用的java代码
...res---存放APP工程的资源文件
...drawable---目录存放的是图像描述文件与用户图片
...layout---目录存放的是App页面的布局文件
...mipmap---目录存放的是启动图标
...values---目录存放的是一些常量定义的文件
Gradle Scripts---目录是工程的编译配置文件
...build.gradle,该文件分为项目级和模块级两种,用于描述App工程的编译规则
...proguard-rules.pro,该文件用于描述java文件的代码混淆规则
...gradle.properties,该文件用于配置编译工程的命令行参数,一般无需改动
...settings.gradle,配置哪些模块在一起编译。初始内容为include ':app',表示只编译App模块
...local.properties,项目的本地配置,一般无须改动。该文件是在工程编译时自动生成,用于描述开发者本机的环境配置,如SDK的本地路径等
2.编译配置文件build.gradle
项目级别的build.gradle一般无须改动,只需要关注模块级别的build gradle.
apply plugin: 'com.android.application'
android {
//指定编译用的SDK版本号,如25表示使用Android 7.1编译
compileSdkVersion 26
defaultConfig {
//指定该模块的应用模号,即APP的包名,该参数为自动生成,无须修改
applicationId "com.syj.helloworld"
//指定App适合运行的最小SDK版本号,如15表示最少要在Android 4.0.3上运行
minSdkVersion 15
//指定目标设备的SDK版本号,即该App最希望在哪个版本的Android上运行
targetSdkVersion 26
//指定APP的应用版本号
versionCode 1
//指定App的应用版本名称
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
//指定是否开启代码混淆功能,true表示开启,false表示无须混淆
minifyEnabled false
//指定代码混淆规则文件的文件名
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
//指定App编译的依赖信息
dependencies {
//指定引用jar包的路径
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
//指定单元测试编译用的junit版本号
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
3.APP运行配置
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<!--根节点manifest,package指定了该app的包名-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.syj.helloworld">
<!--application用于指定APP的自身属性,uses-permission用于申明App运行过程中需要的权限名称,allowbackup,用于指定是否允许备份,开发阶段设置为True,上线时设置为false-->
<!--icon用于指定该APP在手机屏幕上显示的图标,label用于指定该APP在手机屏幕上线的名称,supportsRtl设置为True表示支持阿拉伯语/波斯语这种从右往左的文字排列顺序
theme用于指定该APP的显示风格-->
<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活动-service服务-广播接收器receiver-provider内容提供器-->
<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>