问题总结:
1.项目构建失败 gradle问题 解决:第2,3点
2.依赖库下载慢,下载源问题 解决:第5点
1.这里参考版本:Android Studio Electric Eel | 2022.1.1 Patch 1
Android studio 较新版本2.项目 build.gradle 文件
// 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
}
3. gradle-->wrapper--gradle-->wrapper.properties 文件
#Thu Mar 30 09:12:07 CST 2023
#不是越高越好 没有特殊要求,能用就行
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
4.主模块 app目录下 build.gradle 文件
plugins {
id 'com.android.application'
}
android {
namespace 'com.example.myapplication'
compileSdk 32
defaultConfig {
applicationId "com.example.myapplication"
minSdk 24
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
//这里新版的gradle 最低支持 VERSION_11
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
5.settings.gradle 文件
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
//阿里仓库,解决库 下载慢问题
maven { url 'https://maven.aliyun.com/nexus/content/repositories/releases/' }
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
//阿里仓库,解决库 下载慢问题
maven { url 'https://maven.aliyun.com/nexus/content/repositories/releases/' }
}
}
rootProject.name = "My Application"
include ':app'
网友评论