我是 Android Studio 的新手,每次嘗試將專案與 gradle 同步時都會收到此錯誤。例如,我提供了對三個檔案的參考。
1)專案級build.gradle檔案
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.example.myfirstapp"
minSdk 24
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
testImplementation 'junit:junit:4. '
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
2) Gradle Scripts build.gradle 檔案
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
mavenLocal()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0-RC2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
3) gradle-wrapper.properties
#Fri Nov 05 11:37:25 IST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
我使用的是帶有 Android Studio Arctic Fox 2020.0.1 補丁 3 的 Windows 10
我得到的完整錯誤訊息是
Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.0.2/gradle-7.0.2.pom'. Received status code 405 from server: Method Not Allowed
uj5u.com熱心網友回復:
好吧,看來沒問題,我只能猜測是連接問題。
嘗試在瀏覽器中使用此鏈接https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.0.2/gradle-7.0.2.pom以確保您可以連接去谷歌 。
如果您可以訪問該站點,那么您可能需要使用 proxy/vpn 。
這樣做的方法是下載psiphon并導航到設定,例如將本地埠設定為 1234。
然后轉到 Users/%USERNAME%/.gradle 并添加 gradle properties ,使用以下內容
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=1234
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=1234
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/350487.html
上一篇:有沒有辦法將從APISAUCEAPI收到的回應存盤到異步存盤中作為快取,并在ReactNative的平面串列中顯示它
