首页 文章

无法构建android项目它显示错误

提问于
浏览
1

项目gradle

// 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要求:项目:

5 回答

  • 16

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

  • 1

    正如已经回答here

    谷歌有新的maven回购,所以这可能是原因 . 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等支持库:

    确保存储库部分包含带有“https://maven.google.com” endpoints 的maven部分 . 例如:

    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

  • -1

    使用此..这可能有效,因为这适用于我的情况:

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

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

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

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

    好的...所以试图结束你们所遇到的所有问题我的解决方案

    这是我最后的应用程序级别

    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'
    

    这是我最后的项目级别

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

    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文件进行比较,并添加或修改与我编写的不同的任何值 .

  • 0

    今天早上我遇到了同样的问题!正如Vishal所说,没有gradle-3.0.0-alpha3 ..我确信,自从我下载了“Android studio 3.0 Canary(Alpha3)”之后,我就开始使用相同版本的gradle(3.0.0 alpha3),它工作了! (从今天起) .

    所以我把:classpath'com.android.tools.build:grad:2.3.2'编译 .

    编辑:我有两个版本的Android工作室,当我使用Android Studio 3.0时,它改变了gradle to gradle 3.0.0-alpha3!

  • 0

    写下这些渐变..

    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'
    

相关问题