在Android Studio中构建Gradle的问题

问题描述 投票:0回答:1

我几乎在大多数项目中都会遇到这样的问题,当我想将现有项目移植到Android时,我总是遇到这样的问题,我该怎么做才能永久解决问题?

谷歌已经为伊朗人禁用了这部分,如果我想事先在Android Studio中导入任何项目,我必须连接到可以导入使用的库的VPN,有没有办法在不连接到VPN的情况下做到这一点,已下载图书馆? 我是否可以手动将所有库下载到一个文件夹中,然后将所有网址放入项目中,因为连接到 VPN 很困难,而且如果这样做速度超级慢。 或者是否有另一个可以在 Android Studio 设置中更改的地址,例如 Visual Studio 中的 Nuget,您可以在其中更改接收库的地址并从该地址下载库?

错误文字:

 Could not resolve all artifacts for configuration ':classpath'.
    Could not find gradle-4.2.2.jar (com.android.tools.build:gradle:4.2.2).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.2.2/gradle-4.2.2.jar
    Could not find builder-4.2.2.jar (com.android.tools.build:builder:4.2.2).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/4.2.2/builder-4.2.2.jar
    Could not find aaptcompiler-4.2.2.jar (com.android.tools.build:aaptcompiler:4.2.2).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/build/aaptcompiler/4.2.2/aaptcompiler-4.2.2.jar
    Could not find bundletool-1.1.0.jar (com.android.tools.build:bundletool:1.1.0).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/build/bundletool/1.1.0/bundletool-1.1.0.jar
    Could not find sdk-common-27.2.2.jar (com.android.tools:sdk-common:27.2.2).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/sdk-common/27.2.2/sdk-common-27.2.2.jar
    Could not find sdklib-27.2.2.jar (com.android.tools:sdklib:27.2.2).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/sdklib/27.2.2/sdklib-27.2.2.jar
    Could not find common-27.2.2.jar (com.android.tools:common:27.2.2).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/common/27.2.2/common-27.2.2.jar
    Could not find protos-27.2.2.jar (com.android.tools.analytics-library:protos:27.2.2).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/protos/27.2.2/protos-27.2.2.jar
    Could not find core-proto-0.0.8-alpha01.jar (com.google.testing.platform:core-proto:0.0.8-alpha01).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/google/testing/platform/core-proto/0.0.8-alpha01/core-proto-0.0.8-alpha01.jar
    Could not find zipflinger-4.2.2.jar (com.android:zipflinger:4.2.2).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/zipflinger/4.2.2/zipflinger-4.2.2.jar
    Could not find apksig-4.2.2.jar (com.android.tools.build:apksig:4.2.2).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/build/apksig/4.2.2/apksig-4.2.2.jar

build.Gradle 文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.2"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

android gradle build.gradle vpn
1个回答
0
投票

这是由禁止的 HTTP 错误 (403) 引起的。您需要 VPN 或代理才能绕过它。

我建议使用 HTTP 代理,因为 Gradle 和 Android Studio 都支持它,并且不需要复杂的配置即可使其工作。

这里有一个为 Android Studio 设置 HTTP 代理的指南

通常,配置代理设置后,Gradle 会询问您是否也想为 Gradle 使用相同的代理配置。

否则,如果 Gradle 没有提示,您应该手动执行。在全局

gradle.properties 文件中添加以下行:
systemProp.http.proxyHost=[proxy host]



systemProp.http.proxyPort=[proxy port]

    

© www.soinside.com 2019 - 2024. All rights reserved.