問題總結(jié):
1.項目構(gòu)建失敗 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'