新版Android studio 新建項目一直運行不了問題, gradle版本過高

問題總結(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'
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容