在Android Studio中将Gradle更新应用于版本3.3.0
后,在同步Gradle关于junit 4.12时发生错误。
错误是:无法在类型为`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
}
App 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的语言是土耳其语,土耳其语的字母表中有大写字母。
因此,如果用androidTestİmplementation替换androidTestImplementation,问题就会解决。
或者将您的PC语言设置为英语:)