【问题标题】:Android Studio build.gradle warning message [duplicate]Android Studio build.gradle 警告消息 [重复]
【发布时间】:2018-07-05 20:43:33
【问题描述】:

在我成功更新到 Android Studio 3.1 Canary 9 后,我收到警告消息

Warning:Configuration 'compile' is obsolete and has been replaced with 'implementation'.
It will be removed at the end of 2018

我知道这个警告至少目前不会在我的项目中造成任何问题。但是我想完全删除它,以便将来完全没有问题。但是在查看了我的 build.gradle 文件后,我根本找不到任何调用此警告的代码行。

这是我的 build.gradle 文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "app.project.virtualdiary"
        minSdkVersion 21
        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 'com.google.firebase:firebase-auth:11.8.0'
    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'
    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'
    implementation 'com.android.support:support-v4:27.0.2'
    implementation 'com.android.support:support-vector-drawable:27.0.2'
}


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

【问题讨论】:

标签: android android-studio android-gradle-plugin


【解决方案1】:

问题出在apply plugin: 'com.google.gms.google-services'

Google 服务插件正在代表您添加依赖项。希望他们在未来修复它。

【讨论】:

  • 问题已解决。我在 gradle 项目中更新了谷歌服务:classpath 'com.google.gms:google-services:3.2.1'
  • 我正在使用 com.google.gms:google-services:4.2.0 但仍然出现警告
  • 未来一年。在 3.2.1 使用 google 服务时仍会遇到此问题
  • 现在仍然遇到这个问题。
【解决方案2】:

我对 com.google.gms:google-services 也有同样的警告。

解决方案是在 build.gradle 项目的文件中将 classpath com.google.gms:google-services 升级为 classpath 'com.google.gms:google-services:3.2.0':

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'

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

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

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

在 Android Studio 版本 3.1 的依赖中,complie 字被替换为 实施

在 android studio 3.1 中带有警告的依赖项

dependencies {
            compile fileTree(dir: 'libs', include: ['*.jar'])
            compile 'com.android.support:appcompat-v7:27.1.0'
            compile 'com.android.support.constraint:constraint-layout:1.0.2'
            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'
    }

依赖关系OK在android studio 3.1

    dependencies {
            implementation fileTree(dir: 'libs', include: ['*.jar'])
            implementation 'com.android.support:appcompat-v7:27.1.0'
            implementation 'com.android.support.constraint:constraint-layout:1.0.2'
            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'

    }

Android Studio 3.1 为新项目生成 Gradel。

访问https://docs.gradle.org/current/userguide/dependency_management_for_java_projects.html

详情https://docs.gradle.org/current/userguide/declaring_dependencies.html

祝你好运

【讨论】:

  • 我已尝试更改为 com.google.gms:google-services:3.2.0,但警告仍然出现
  • 如果你把complie的所有依赖都改成了implementation。问题是你可以是外部依赖。 Google 在 com.google.gms 版本中对实现进行了更改:google-services: 3.2.0,但其他依赖项可能不是最新的。您可以尝试更新其他依赖项,看看我们是否在新版本中修复了问题。
【解决方案3】:

我同意尼克拉斯的观点。我将compile 更改为implementation,但仅在更改build.gradle(Project: .....)

后警告才消失

之前:

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

之后:

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

【讨论】:

    【解决方案4】:

    首先选择:

    1. 构建
    2. 清理项目然后构建
    3. 在 Android 工作室中制作项目

    【讨论】:

      【解决方案5】:

      当 AndroidManifest.xml 包名与 build.gradle 包名不同时,我会收到此错误

      配置“编译”已过时并已替换为 '执行'。将于 2018 年底移除

      Java compile error

      【讨论】:

      • 取决于您的目标,但您是对的,从本月底开始,我们必须将目标设为 26> 并且在 26> 中,compile 已弃用。但这不是这个问题的问题。
      【解决方案6】:

      将“编译”改为“实现”。这个问题将得到解决!它可以在我的电脑上运行。

      【讨论】:

      • 在上面的例子中,所有的“依赖”都已经变成了“实现”,我想这就是为什么这被否决了。我在上面的部分忽略了它,所以这条评论对我有帮助。
      • 仔细阅读问题!
      • 取决于您的目标,但从本月底开始,我们必须定位 26> 和 26> compile 已弃用。但这不是这个问题的问题。
      猜你喜欢
      • 1970-01-01
      • 2016-02-25
      • 2018-01-18
      • 1970-01-01
      • 2017-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多