java - 如何在Android Studio上修复Gradle错误

标签 java android android-studio gradle android-gradle-plugin

我开始学习Android Studio。我创建了第一个项目,但遇到以下错误;

1)在类型org.gradle.api.internal.artifacts.dsl.dependencies.defaultDependencyhandler的对象上找不到参数[junit:junit:4.13]的方法测试mplementation()。

2)*出了什么问题:
配置项目':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:任务执行完成'Main.main()'。

我为解决方案应用了以下方法。但是问题没有解决;

1)我的计算机语言是英语。

2)我删除了gradle文件夹并重新加载了它。

3)将build.gradle(module.app)替换为I,İ

4)添加了androidTestImplementation'androidx.test.ext:junit:1.1.1。(build.gradle(module.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'
}

最佳答案

即使不是您问题的完整答案,我也找到了解决此问题的方法:
转到项目结构>项目>并更改
摇篮版本:4.6
Android插件版本:3.2.1
根据此处给出的表:
https://developer.android.com/studio/releases/gradle-plugin#updating-gradle

编辑:第一次尝试没有成功,但是在我更改之后,我进入İ了。尊敬穆罕默德·埃尔多杜(Mehmet Erdogdu)!

testİmplementation'junit:junit:4.12'
androidTestİmplementation'com.android.support.test:runner:1.0.2'
androidTestİmplementation'com.android.support.test.espresso:espresso-core:3.0.2'

关于java - 如何在Android Studio上修复Gradle错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61610743/

相关文章:

java - 递归 - 删除重复项

java - 如何在java中验证这个时间/日期字符串?

android - 获取 Android 上的照片库列表

android - 错误 : cause android. compileSdkVersion 丢失

java - HttpUtils.httpConnection() 被拒绝

java - 堆栈问题,不存储值

java - 如何让通用图像加载器加载图像按钮?

android - 登录页面状态失败的断言问题

android - 同时具有宽度和高度的 Fresco 图像 - match_parent 不显示

java - 如何在 Android Studio 中导入并使用 txt 文件?