android-studio - 更新 Android Studio 和 Gradle 后 Gradle 项目同步失败
问题描述
在 Android Studio 中将Gradle 更新应用到版本3.3.0
后,在同步有关 junit 4.12 的 Gradle 时发生错误。
错误是:在类型为 `org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler 的对象上找不到参数 [junit:junit:4.12] 的方法 testImplementation()。
更新前没有错误。当我将最后三个依赖项(junit、test runner、test espresso)添加到 gradle 文件时,会发生错误。我已经查看了以前的问题,但还没有找到解决方案。这是我的gradle文件:
项目 Gradle 文件
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
应用 Gradle 文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.hhs.haberler"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
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:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:customtabs:28.0.0'
implementation 'com.android.support:preference-v7:28.0.0'
implementation "android.arch.lifecycle:extensions:1.1.1"
implementation 'com.android.support:support-vector-drawable:28.0.0'
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.github.curioustechizen.android-ago:library:1.4.0'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
implementation 'com.github.chrisbanes:PhotoView:2.1.4'
implementation 'gr.pantrif:easy-android-splash-screen:0.0.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'
}
解决方案
Android Studio 有一个错误。我猜你电脑的语言是土耳其语。如果您将“androidTestApi”包含“androidTestImplementation”写入您的 gradle 文件,Android Studio 会给出如下警告:
警告:配置 'androidTestApi' 已过时,已替换为'androidTestİmplementation'。它将在 2018 年底被删除。有关更多信息,请参阅:http ://d.android.com/r/tools/update-dependency-configurations.html 受影响的模块:app
注意警告处的强文本。androidTestİmplementation内部有大写的İ,因为您的 PC 的语言是土耳其语,而土耳其语的字母表中有大写的 İ。
因此,如果您将androidTestImplementation替换为androidTestİmplementation,问题将得到解决。
或者将您的 PC 语言设置为英语 :)
推荐阅读
- java - java中数字的正则表达式
- javascript - 如何生成批量二维码
- javascript - 取消注释 jquery 如何导致 Rails 服务器工作?
- r - 在四个数据框列上应用两个不同的公式
- c# - 从 Web Api 返回计算结果的正确方法
- python-3.x - 如何在 Python 中使用两条 grep 行
- android - 由于指纹不正确,无法将签名的 apk 上传到 Google Play 商店
- inno-setup - Inno Setup:设置 ActiveControl 属性时“无法聚焦禁用或不可见窗口”
- postgresql - 在 plsql - postgresql 中创建对象列表
- react-native - 在 react-navigation v3 中默认情况下,标题后退按钮不起作用