【问题标题】:can't build android project it shows error无法构建android项目它显示错误
【发布时间】:2017-11-06 01:38:59
【问题描述】:

项目分级

// 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
}

App 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”时出现问题。

无法解析配置“: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.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 要求: 项目:

【问题讨论】:

标签: java android android-studio android-gradle-plugin build.gradle


【解决方案1】:

正如已经回答的here

Google 有新的 maven repo,所以这可能是原因。

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.html https://developer.android.com/studio/build/dependencies.html#google-maven

将 Google 的 Maven 存储库添加到 buildscript 存储库部分以修复它,就像 @KG87 对 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'
        ...
    }
}

正如here解释的那样:

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

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

还有here:

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

正如here宣布的那样:

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

所以,尝试通过添加 Google 的 Maven 存储库来修复它。

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 等支持库:

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

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

区别解释here

“buildscript”块只控制 buildscript 的依赖关系 进程本身,而不是针对顶层的应用程序代码 “依赖项”块控件。

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

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

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

【讨论】:

    【解决方案2】:

    写这些 gradles..

    compile 'com.android.support:appcompat-v7:25.0.2'
    compile 'com.android.support:design:25.0.2'
    classpath 'com.android.tools.build:gradle:2.2.3'
    

    【讨论】:

    • 我用的是最新版本有什么问题
    • 添加这个:classpath 'com.android.tools.build:gradle:2.2.3'
    • OP 可能想要使用不带retrolamda 的lambdas,而他正是需要那个gradle 版本,为什么他应该使用旧版本?
    【解决方案3】:

    今天早上我也遇到了同样的问题! 正如 Vishal 所说,没有 gradle-3.0.0-alpha3.. 我敢肯定,自从我下载了“Android studio 3.0 Canary (Alpha3)”后,我使用的是同一版本的 gradle (3.0.0 alpha3),并且它有效! (从今天开始)。

    所以我已经把:classpath 'com.android.tools.build:gradle:2.3.2' 来编译。

    编辑:我有两个版本的 Android Studio,当我使用 Android Studio 3.0 时,它会将 gradle 更改为 gradle 3.0.0-alpha3 !

    【讨论】:

      【解决方案4】:

      使用这个..这可能有效,因为这在我的情况下有效:

      dependencies {
      classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
      classpath 'com.google.gms:google-services:2.0.0-alpha3'
      }
      

      并将其放在应用级 build.gradle 文件的末尾(在依赖项之后)。

       apply plugin: 'com.google.gms.google-services'
      

      我不知道为什么把它放在最后(而不是放在开头)可以解决错误。

      好的……所以尝试结束你们在我的解决方案中遇到的所有问题

      这是我的最终应用程序级别 gradle

      apply plugin: 'com.android.application'
      
      android {
      compileSdkVersion 23
      buildToolsVersion "23.0.2"
      
      defaultConfig {
          applicationId "your-app-name"
          minSdkVersion 16
          targetSdkVersion 23
          versionCode 1
          versionName "1.0"
          }
          buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 
              'proguard-rules.pro'
          }
          }
           }
      
         repositories {
          jcenter()
          }
      
      dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      testCompile 'junit:junit:4.12'
      compile 'com.android.support:appcompat-v7:23.1.1'
      compile 'com.google.android.gms:play-services:8.4.0'
      compile 'com.android.support:design:23.1.1'
      compile 'com.mcxiaoke.volley:library:1.0.6@aar'
      }
      
       apply plugin: 'com.google.gms.google-services'
      

      这是我的最终项目级 gradle

      // 顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项。

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

      将此与您自己的 gradle 文件进行比较,并添加或修改任何与我编写的不同的值。

      【讨论】:

        【解决方案5】:

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

        【讨论】:

          猜你喜欢
          • 2017-11-11
          • 2014-03-19
          • 2020-12-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-06-09
          • 2015-12-01
          • 2019-05-05
          相关资源
          最近更新 更多