简体   繁体   English

build.gradle(项目)完全不同?

[英]build.gradle (project) completely different?

I setup a new (Kotlin) project using Android Studio.我使用 Android Studio 设置了一个新的(Kotlin)项目。 When I take a look at my build.gradle (Project) , I see this content:当我查看我的build.gradle (Project)时,我看到了以下内容:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.1.1' apply false
    id 'com.android.library' version '7.1.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}

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

However, other build.gradle s seem to be completely different.但是,其他build.gradle似乎完全不同。

I searched all files, but couldn't find any occurrences of the buildscript , dependencies or any other block.我搜索了所有文件,但找不到任何出现的buildscriptdependencies项或任何其他块。

Where are they or how do I add them?它们在哪里或如何添加它们?

There are two build.gradle files in android studio ie build.gradle(Project) & build.gradle(Module) . android studio 中有两个build.gradle文件,即build.gradle(Project) & build.gradle(Module) Required blocks like buildscript , dependencies are available in build.gradle(Module) buildscript等必需的块, dependencies项在build.gradle(Module)中可用

在此处输入图像描述

build.gradle(Module) looks like: build.gradle(Module)看起来像:

在此处输入图像描述

Hope this will help :)希望这会有所帮助:)

存储库已移至settings.gradle ,模块 Gradle 已移至app包。

buildscript was used to add the version of dependencies and classpaths. buildscript 用于添加依赖项和类路径的版本。 In the newer versions of android studio you have to mention the version directly after the dependency implementations.在较新版本的 android studio 中,您必须在依赖项实现之后直接提及版本。

So for example, I wanted to add the classpath "androidx.navigation:navigation-safe-args-gradle-plugin" to my build.gradle(Project) for the plugin id "androidx.navigation.safeargs.kotlin" , but in the newer version it has been moved to settings.gradle and is done by adding a resolutionStrategy block just after the repositories block: -因此,例如,我想将类路径"androidx.navigation:navigation-safe-args-gradle-plugin"添加到我的 build.gradle(Project) 插件 id "androidx.navigation.safeargs.kotlin" ,但在较新的版本已移至 settings.gradle 并通过在 repositories 块之后添加 resolutionStrategy 块来完成:-

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }

    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == 'androidx.navigation.safeargs.kotlin') {
                useModule("androidx.navigation:navigation-safe-args-gradle-plugin:2.4.2")
            }
        }
    }
}

after that, you can add the plugin id "androidx.navigation.safeargs.kotlin" in plugin block in the build.gradle(Module) and sync it: -之后,您可以在 build.gradle(Module) 的插件块中添加插件 ID “androidx.navigation.safeargs.kotlin”并同步它:-

plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs.kotlin'
}

Hope this is helpful!!希望这有帮助!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM