【问题标题】:I am getting error: Configuration 'compile' is obsolete and has been replaced with 'implementation'. It will be removed at the end of 2018我收到错误:配置“编译”已过时,已替换为“实现”。将于 2018 年底移除
【发布时间】:2018-03-30 01:16:19
【问题描述】:

我在更新 Android Gradle 插件和 Android Studio 后收到此错误。

我已经检查了这个问题 (Android Studio build.gradle warning message),但我无法运行该项目。

【问题讨论】:

    标签: android-studio gradle plugins


    【解决方案1】:

    逐步解决方案

    1- 转到 build.gradle(module app)

    2- 在依赖中,你会看到这样的代码

    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile  'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:support-v4:23.3.0'
    compile 'com.android.support:design:23.3.0'
    

    3- 现在您必须仅将 compile 替换为 implementation,并将 testCompile 替换为 testImplementation。像这样

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation  'junit:junit:4.12'
    implementation  'com.android.support:appcompat-v7:23.3.0'
    implementation  'com.android.support:support-v4:23.3.0'
    implementation  'com.android.support:design:23.3.0'
    

    4- 就是这样。现在点击立即同步按钮。

    注意-不要更改代码中指定的数字或版本。

    【讨论】:

      【解决方案2】:

      这里是完整的解决方案:

      步骤

      1) 在 gradle 文件中使用新的依赖配置 用实现替换 compile 例如:

      dependencies {
          compile 'com.android.support:support-v4:27.0.3'
      }
      

      应该是:

      dependencies {
          implementation 'com.android.support:support-v4:27.0.3'
      }
      

      b) 将testCompile 替换为testImplementation

      例如:

      testCompile 'junit:junit:4.12'
      

      应该是

      testImplementation 'junit:junit:4.12'
      

      c) 对于库,将 compile 替换为 api

      2) 将 build.gradle 文件中的类路径 com.google.gms:google-services 升级为类路径 'com.google.gms:google-services:3.2.0'(使用最新的)

      3) 文件 -> 使缓存无效

      仍然无法正常工作:然后尝试以下步骤

      1)关闭项目。

      2) 删除 .gradle 文件夹。

      3)再次打开项目

      现在可以了

      【讨论】:

        【解决方案3】:

        查看 build.gradle 中的依赖项。在您编译的任何地方,更改为实现。 例如:

        dependencies {
            compile 'com.android.support:support-v4:27.0.3'
        }
        

        应该是:

        dependencies {
            implementation 'com.android.support:support-v4:27.0.3'
        }
        

        【讨论】:

          【解决方案4】:

          只需转到您的应用>>“Gradle Scripts”并打开 build.gradle(Project:"your project name") 并更改此行 (classpath 'com.google.gms:google-services:3.1. 0')到(类路径'com.google.gms:google-services:3.2.0')。当前版本 4.0.1

          【讨论】:

            【解决方案5】:

            说明:

            由于 compile 在 2018 年已过时,您必须按如下方式更改此配置: 1. 打开 build.gradle(module:app) 应用文件并在其中进行以下更改。 2. 将 compile 替换为 api 任何 api ref。 like: volley, GitHubdependancy.strong 文本使用和 3. 使用 implementation 替换 compile 以防使用 play-services-maps、appcompat-v7 等 Android 库。

            示例: 老办法

              dependencies {
                 testCompile'junit:junit:4.12'
                compile 'com.android.volley:volley:1.1.0' 
            

            改成:

             dependencies {
                testImplementation 'junit:junit:4.12'
                implementation 'com.android.volley:volley:1.1.0'
            

            如果问题仍然存在:

            打开build.gradle(项目:yourproject)文件 并将 google gms 服务更改为最新的

            dependencies {
                    classpath 'com.android.tools.build:gradle:3.2.1'
            
            
                    // NOTE: Do not place your application dependencies here; they belong
                    // in the individual module build.gradle files
                }
            

            如果 gradle 同步仍然失败:

            打开 gradle-wrapper.properties 文件并将其替换为以下内容:

            distributionBase=GRADLE_USER_HOME
            distributionPath=wrapper/dists
            distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
            zipStoreBase=GRADLE_USER_HOME
            zipStorePath=wrapper/dists
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2018-09-17
              • 2018-10-28
              • 2018-11-30
              • 2018-11-24
              • 2019-12-06
              • 2019-06-15
              • 2018-07-20
              • 1970-01-01
              相关资源
              最近更新 更多