Android Studio版本:
Android Studio Bumblebee | 2021.1.1 Patch 2Build #AI-211.7628.21.2111.8193401, built on February 17
1.打开AS后,新建一个默认工程
这里我们新建一个底部带有导航栏的默认工程
Minimum SDK表示最低兼容到什么版本,这里我们选择最低兼容到 SDK25,对应的是Android7.1.1
点击finish之后,开始同步gradle
项目结构:
build.gradle(demo)用来配置应用的插件版本号
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
buidl.gradle(:app)用来配置项目依赖库,包括开源的三方库
plugins {
id 'com.android.application'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.mz.demo"
minSdk 25 //最低兼容sdk版本
targetSdk 31 //目标sdk版本
versionCode 1 //上架后的app,每次迭代需要自增
versionName "1.0" //app版本号,迭代发布时用到
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
//JDK版本 gradle7.0+需要11
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'androidx.navigation:navigation-fragment:2.3.5'
implementation 'androidx.navigation:navigation-ui:2.3.5'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
gradle-wrapper.properties用来配置gradle版本
gradle-7.2为版本号
#Thu Mar 17 10:33:49 CST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
gradle的版本号需要和应用插件的版本对应
官方查看地址
插件版本 | 所需的 Gradle 版本 |
---|---|
1.0.0 - 1.1.3 | 2.2.1 - 2.3 |
1.2.0 - 1.3.1 | 2.2.1 - 2.9 |
1.5.0 | 2.2.1 - 2.13 |
2.0.0 - 2.1.2 | 2.10 - 2.13 |
2.1.3 - 2.2.3 | 2.14.1 - 3.5 |
2.3.0+ | 3.3+ |
3.0.0+ | 4.1+ |
3.1.0+ | 4.4+ |
3.2.0 - 3.2.1 | 4.6+ |
3.3.0 - 3.3.3 | 4.10.1+ |
3.4.0 - 3.4.3 | 5.1.1+ |
3.5.0 - 3.5.4 | 5.4.1+ |
3.6.0 - 3.6.4 | 5.6.4+ |
4.0.0+ | 6.1.1+ |
4.1.0+ | 6.5+ |
4.2.0+ | 6.7.1+ |
7.0 | 7.0+ |
7.1 | 7.2+ |
7.2 | 7.3+ |
配置完成后build项目
PS:
JDK SDK路径的配置