Android Studio Arctic Fox gradle 配置

Android Studio Arctic Fox build.gradle allprojects 第三方maven库配置

  • build.gradle 配置
    • 1. 找不到依赖
    • 2.allprojects() 错误
    • 解决方法

build.gradle 配置

Android Studio Arctic Fox 已经发布,用了全新的命名规则,在使用过程中,配置 build.gradle 出现了以下问题,记录以下。

1. 找不到依赖

Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find com.github.ideastudios:IdealRecorder:2.0.4.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/github/ideastudios/IdealRecorder/2.0.4/IdealRecorder-2.0.4.pom
       - https://repo.maven.apache.org/maven2/com/github/ideastudios/IdealRecorder/2.0.4/IdealRecorder-2.0.4.pom
       - https://jcenter.bintray.com/com/github/ideastudios/IdealRecorder/2.0.4/IdealRecorder-2.0.4.pom
	   

出现 Execution failed for task ‘:app:checkDebugAarMetadata’ 错误

2.allprojects() 错误

在 工程 的 build.gradle 添加 allprojects {}出错

Build file 'D:\workspace\AndroidStudio\AndroidStudioProjects\TestApplication\build.gradle' line: 18

A problem occurred evaluating root project 'TestApplication'.
> Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'TestApplication'.
	at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
	at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.lambda$apply$0(DefaultScriptPluginFactory.java:133)
	at org.gradle.configuration.ProjectScriptTarget.addConfiguration(ProjectScriptTarget.java:77)
	at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:136)
	at org.gradle.configuration.BuildOperationScriptPlugin$1.run(BuildOperationScriptPlugin.java:65)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:75)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:68)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:153)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:68)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.run(DefaultBuildOperationRunner.java:56)

Build was configured to prefer settings repositories over project repositories but repository ‘Google’ was added by build file 'build.gradle’报错

解决方法

以上两个问题,都是谷歌瞎折腾导致,最终的解决方案是,在 settings.gradle 中将原来 allprojects 中的内容拷贝进来。build.gradle 无需修改。

settings.gradle 如下

//settings.gradle
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
        maven { url 'https://jitpack.io' }
    }
}
rootProject.name = "TestApplication"
include ':app'

build.gradle 不用修改,保持原样,如下

//build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.0"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}


task clean(type: Delete) {
    delete rootProject.buildDir
}

你可能感兴趣的:(android-studio,gradle)