无法构建android项目它显示错误 [英] can't build android project it shows error

查看:24
本文介绍了无法构建android项目它显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

项目梯度

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha3'
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

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

应用 Gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.arun4fms.efix"
        minSdkVersion 17
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        packagingOptions {
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/LICENSE-FIREBASE.txt'
            exclude 'META-INF/NOTICE'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.google.firebase:firebase-database:10.2.0'
    compile 'com.google.firebase:firebase-crash:10.2.0'
    compile 'com.google.firebase:firebase-auth:10.2.0'
    compile 'com.chabbal:slidingdotsplash:1.0.2'
    compile 'com.google.firebase:firebase-core:10.2.0'
    compile 'com.firebase:firebase-client-android:2.5.2'
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support:design:25.2.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

错误:配置根项目webapp"时出现问题.

Error:A problem occurred configuring root project 'webapp'.

无法解析配置:classpath"的所有依赖项.找不到 com.android.tools.build:gradle:3.0.0-alpha3.在以下位置搜索:文件:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle/3.0.0-alpha3/gradle-3.0.0-alpha3.pom文件:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle/3.0.0-alpha3/gradle-3.0.0-alpha3.jarhttps://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0-alpha3/gradle-3.0.0-alpha3.pomhttps://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0-alpha3/gradle-3.0.0-alpha3.jar要求:项目:

Could not resolve all dependencies for configuration ':classpath'. Could not find com.android.tools.build:gradle:3.0.0-alpha3. Searched in the following locations: file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle/3.0.0-alpha3/gradle-3.0.0-alpha3.pom file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle/3.0.0-alpha3/gradle-3.0.0-alpha3.jar https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0-alpha3/gradle-3.0.0-alpha3.pom https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0-alpha3/gradle-3.0.0-alpha3.jar Required by: project :

推荐答案

如已回答这里:

Google 有新的 maven 存储库,所以这可能是原因.

Google have new maven repo, so it could be the reason.

https://android-developers.googleblog.com/2017/05/android-studio-3-0-canary1.html

部分 Google 的 Maven 存储库

https://developer.android.com/studio/preview/features/new-android-plugin-migration.htmlhttps://developer.android.com/studio/build/dependencies.html#google-maven

将 Google 的 Maven 存储库添加到 buildscript 存储库部分以修复它,就像 @KG87 在此处所做的那样.

Add Google’s Maven Repository to the buildscript repositories section to fix it like @KG87 did here.

buildscript {
    repositories {
        jcenter()
        maven { url "https://maven.google.com" } // Add this line to fix it
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha3'
        ...
    }
}

此处所述:

buildScript 块中的存储库用于获取您的 buildScript 依赖项的依赖项.这些是放在构建的类路径上的依赖项,并且您可以从您的构建文件中引用.例如,额外的插件存在于互联网上.

The repositories in the buildScript block are used to fetch the dependencies of your buildScript dependencies. These are the dependencies that are put on the classpath of your build and that you can refer to from your build file. For instance, extra plugins that exist on the internet.

根级别的存储库用于获取依赖项您的项目所依赖的.所以你需要的所有依赖编译你的项目.

The repositories on the root level are used to fetch the dependencies that your project depends on. So all the dependencies you need to compile your project.

还有这里:

buildScript 块决定了哪些插件、任务类和其他类可用于构建脚本的其余部分.没有 buildScript 块,您可以使用随附的所有内容Gradle 开箱即用.如果您还想使用第三方插件、任务类或其他类(在构建脚本中!),你必须在buildScript中指定对应的依赖阻止.

The buildScript block determines which plugins, task classes, and other classes are available for use in the rest of the build script. Without a buildScript block, you can use everything that ships with Gradle out-of-the-box. If you additionally want to use third-party plugins, task classes, or other classes (in the build script!), you have to specify the corresponding dependencies in the buildScript block.

正如此处:

Android Gradle Plugin 3.0.0-alpha3 也通过maven.google.com.

The Android Gradle Plugin 3.0.0-alpha3 was also released through maven.google.com.

因此,尝试通过添加 Google 的 Maven 存储库来修复它.

So, try to fix it by adding Google’s Maven Repository.

buildscript {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

还要在此处为​​其他依赖项添加存储库,例如支持库,例如 this:

Also add the repository here for other dependencies like the support libraries like this:

确保 repositories 部分包含一个 maven 部分https://maven.google.com" 端点.例如:

Make sure that the repositories section includes a maven section with the "https://maven.google.com" endpoint. For example:

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

区别解释这里

buildscript"块只控制buildscript的依赖进程本身,而不是应用程序代码,这是顶层依赖项"块控件.

The "buildscript" block only controls dependencies for the buildscript process itself, not for the application code, which the top-level "dependencies" block controls.

例如,您可以在buildscript/classpath"中定义依赖项代表构建过程中使用的 Gradle 插件.那些插件不会被引用为应用程序代码的依赖项.

For instance, you could define dependencies in "buildscript/classpath" that represent Gradle plugins used in the build process. Those plugins would not be referenced as dependencies for the application code.

正如@lugegege 此处所评论的,Bintray JCenter 中不存在此版本:

As commented here by @lugegege, this version doesn't exist in Bintray JCenter:

com.android.tools.build.gradle最新版本是 2.5.0-alpha-preview-02,没有 3.0.0-alpha3

com.android.tools.build.gradle latest version is 2.5.0-alpha-preview-02, there is no 3.0.0-alpha3

这篇关于无法构建android项目它显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆