【问题标题】:How to replace implementation to compile in Android Build.gradle. (Android Studio 2.3.3) [duplicate]如何替换实现以在 Android Build.gradle 中编译。 (Android Studio 2.3.3)[重复]
【发布时间】:2017-10-13 13:56:13
【问题描述】:

我正在开发条码扫描器的应用程序。

网址:Barcode Scanner URL Here

我的 Android Studio 版本是 2.3.3

我一直在 build.gradle (module:app) 中使用 compile,但我发现这个库建议使用 implementation 代替 compile

我在网上搜索 compile 在 Android studio 3.0 中被 implementation 取代,但我必须在 Android studio 2.3.3 中使用这个库。

例子。

dependencies {
implementation 'com.budiyev.android:code-scanner:1.5.7'
}

当我把它放在我的 gradle 中时,它的显示错误。

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.budiyev.android:code-scanner:1.5.7' // HERE
testCompile 'junit:junit:4.12'
}

错误是:

    Error:Failed to resolve: com.android.support:support-annotations:26.1.0
    Install Repository and sync project
    Show in Project Structure dialog

请告诉我如何在我的 android studio 2.3.3 中使用这个库

【问题讨论】:

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


    【解决方案1】:

    您需要在您的顶级 build.gradle 中添加 Google 的 Maven 存储库

          allprojects {
          repositories {
            google()
    
            // If you're using a version of Gradle lower than 4.1, you must instead use:
            // maven {
            //     url 'https://maven.google.com'
            // }
            // An alternative URL is 'https://dl.google.com/dl/android/maven2/'
        }
    }
    

    【讨论】:

    • 抱歉,没有发生同样的错误信息。我在 build.gradle compile 'com.budiyev.android:code-scanner:1.5.7' 中添加了,我替换了实现来编译。
    • @Abhishekkumar 根据github.com/yuriy-budiyev/code-scanner,您应该使用implementation 'com.budiyev.android:code-scanner:1.5.7'
    • @IntelliJAmiya 对
    • 但我的 Android Studio 是 2.3.3,我无法解决错误。
    • 感谢@Amiya 的回复如果我使用的是 Android Studio 3 它工作正常但在 Android Studio 2.3.3 中仍然出现错误。
    【解决方案2】:

    像这样将 Maven 存储库添加到您的项目级 gradle:

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

    这适用于 Android Studio 版本2.3.3 或低于4.1 的 Gradle 版本

    【讨论】:

    • 我添加了但同样的错误消息来了。
    • 你的 buildToolsVersion 是什么?
    • 类路径'com.android.tools.build:gradle:2.3.3'
    猜你喜欢
    • 2019-11-12
    • 1970-01-01
    • 2018-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-22
    • 1970-01-01
    相关资源
    最近更新 更多