如何在Android Studio中修复Gradle错误。

huangapple 未分类评论47阅读模式
英文:

How can ı fix the gradle error on Android Studio

问题

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

  1. 在类型为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()'。

我尝试了以下解决方案,但问题没有解决;

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

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

  3. 用I,İ替换了build.gradle(module.app)中的内容。

  4. 添加了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;

  1. 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.
  • 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 ;

  1. My computer language is English.

  2. I deleted the gradle folder and reloaded it.

  3. build.gradle(module.app) in replaced with I,İ

  4. 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'
}

huangapple
  • 本文由 发表于 2020年5月5日 18:14:59
  • 转载请务必保留本文链接:https://java.coder-hub.com/61610743.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定