如何在Android Build.gradle中替换实现以进行编译。 (Android Studio 2.3.3)

时间:2017-10-13 13:56:13

标签: android android-gradle build.gradle

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

网址:Barcode Scanner URL Here

我的Android Studio版本是2.3.3

我总是在build.gradle(module:app)中使用compile,但我发现这个库建议使用实现来代替编译

我通过互联网搜索编译被Android studio 3.0中的实现取代,但我必须在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中使用这个库

2 个答案:

答案 0 :(得分:5)

您需要在顶级 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/'
    }
}

答案 1 :(得分:1)

将Maven repo添加到项目级别gradle中,如下所示:

allprojects {
    repositories {

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

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