首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用gradle构建工具开发android应用程序时,配置项目时出错

使用gradle构建工具开发android应用程序时,配置项目时出错
EN

Stack Overflow用户
提问于 2019-11-08 23:30:09
回答 2查看 47关注 0票数 0

我是一个安卓开发新手,我正在构建安卓应用,我正在使用gradle,我收到了错误信息A problem occurred configuring project ':app'

代码语言:javascript
运行
复制
buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'
        //classpath 'ext.supportLibraryVersion = 27.1.1'

        classpath 'com.android.support:support-v4:27.1.1'
        classpath 'com.google.gms:google-services:4.3.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

上面的代码是build.gradle文件的项目级别。以下代码是build.gradle文件的应用程序级别。

代码语言:javascript
运行
复制
apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "mm.com.fairway.firebaseauth"
        minSdkVersion 22
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'



    implementation 'com.google.firebase:firebase-analytics:17.2.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'


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

我搜索了解决方案来修复这个错误,但我还没有找到解决方案。对这个错误有任何想法,谢谢。

EN

回答 2

Stack Overflow用户

发布于 2019-11-08 23:52:20

代码语言:javascript
运行
复制
classpath 'com.android.support:support-v4:27.1.1

上面的代码行在错误的Gradle文件中。另外,将其从类路径更改为实现。

所以就像这样:

代码语言:javascript
运行
复制
buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.2'
        //classpath 'ext.supportLibraryVersion = 27.1.1'
        classpath 'com.google.gms:google-services:4.3.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

代码语言:javascript
运行
复制
apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "mm.com.fairway.firebaseauth"
        minSdkVersion 22
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:28.0.0'


    implementation 'com.google.firebase:firebase-analytics:17.2.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'


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

请注意,我将项目更新为28,其他依赖项也进行了升级。我这样做是因为我不再安装SDK 27。

票数 0
EN

Stack Overflow用户

发布于 2019-11-08 23:57:31

将Gradle构建工具升级到3.2或更高版本将解决此问题。

例如:

代码语言:javascript
运行
复制
buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        //classpath 'ext.supportLibraryVersion = 27.1.1'

        classpath 'com.android.support:support-v4:27.1.1'
        classpath 'com.google.gms:google-services:4.3.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

这为我解决了问题,似乎也解决了另一个人的问题:

I have a gradle sync error JAVA_LETTER_OR_DIGIT when trying to add Firebase to my android project

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58769485

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档