英文:
How can ı fix the gradle error on Android Studio
问题
我开始学习Android Studio。我创建了我的第一个项目,但遇到了以下错误:
-
在类型为org.gradle.api.internal.artifacts.dsl.dependencies.defaultdependencyhandler的对象上找不到方法testImplementation(),参数为[junit:junit:4.13]。
-
- 出现了什么问题:
配置项目'app'时出现问题。
> 无法创建任务'app:Main.main()'。
> 找不到名称为'main'的SourceSet。
- 出现了什么问题:
-
尝试:
使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项获取更多日志输出。使用--scan获取完整的洞察力。 -
在https://help.gradle.org获取更多帮助。
此构建中使用了已弃用的Gradle功能,与Gradle 6.0不兼容。
使用'--warning-mode all'显示各个弃用警告。请参阅https://docs.gradle.org/5.6.4/userguide/command_line_interface.html#sec:command_line_warnings
构建失败,用时5秒
12:55:07 PM: 任务执行完成'Main.main()'。
我尝试了以下解决方案,但问题没有解决;
-
我的计算机语言是英语。
-
我删除了gradle文件夹并重新加载了它。
-
用I,İ替换了build.gradle(module.app)中的内容。
-
添加了androidTestImplementation 'androidx.test.ext:junit:1.1.1'(build.gradle(module.app))。
app模块的build.gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.deneme"
minSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
英文:
I started learning Android Studio. I created my first project but I met with the following errors;
-
could not find method test mplementation() for arguments [junit:junit:4.13] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.defaultdependencyhandler.
-
- What went wrong:
A problem occurred configuring project ':app'.
> Could not create task ':app:Main.main()'.
> SourceSet with name 'main' not found.
- What went wrong:
-
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. -
Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.6.4/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 5s
12:55:07 PM: Task execution finished 'Main.main()'.
I applied the following for the solution.But problem did not solved ;
-
My computer language is English.
-
I deleted the gradle folder and reloaded it.
-
build.gradle(module.app) in replaced with I,İ
-
androidTestImplementation 'androidx.test.ext:junit:1.1.1 added.(build.gradle(module.app))
The build.gradle of the app module:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.deneme"
minSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
专注分享java语言的经验与见解,让所有开发者获益!
评论