gradle 7.0 + 配置

Maven 镜像地址的设置

原来在项目根目录的 build.gradle 中进行设置,但是现在里面只有plugins。

工程的build.gradle的dependencies修改为plugins,替代了引用原来的Gradle版本。

复制代码
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.4.2' apply false
    id 'com.android.library' version '7.4.2' apply false
}

想使用旧的依旧可以在项目build.gradle里面按照原来方式添加,不影响旧方法。

复制代码
buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30"
    }
}

或者使用buildscript+plugins同时存在的模式,注意顺序不能错,否则会提示错误的

apply from 自定义配置清单还是能够使用

复制代码
//注意 buildscript节点有可能没有 自己添加需要注意与plugins的顺序
buildscript {
    ext {
        kotlin_version = '1.6.10'
    }
    dependencies {
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.28-alpha'
    }
}
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.5.31' apply false
}
//apply from: "config.gradle"//自定义配置清单还是能够使用
task clean(type: Delete) {
    delete rootProject.buildDir
}

原来工程中 build.gradle 的buildscriptallprojects移动至setting.gradle

改名为pluginManagementdependencyResolutionManagement。里面的东西依旧可以按照原来的copy过来。

include 方法还是老样子

复制代码
pluginManagement {
    repositories {

        // 国内镜像
        maven { url 'https://maven.aliyun.com/repository/google/' }
        maven { url 'https://maven.aliyun.com/repository/jcenter/' }
        maven { url 'https://maven.aliyun.com/nexus/content/repositories/releases/' }
        maven { url 'https://maven.aliyun.com/nexus/content/repositories/central' }
        maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
        maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }
        maven { url 'https://maven.aliyun.com/nexus/content/repositories/google' }
        maven { url 'https://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }

        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        // 国内镜像
        maven { url 'https://maven.aliyun.com/repository/google/' }
        maven { url 'https://maven.aliyun.com/repository/jcenter/' }
        maven { url 'https://maven.aliyun.com/nexus/content/repositories/releases/' }
        maven { url 'https://maven.aliyun.com/nexus/content/repositories/central' }
        maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
        maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }
        maven { url 'https://maven.aliyun.com/nexus/content/repositories/google' }
        maven { url 'https://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }

        google()
        mavenCentral()
    }
}
rootProject.name = "xxxxx"
include ':app'

APP项目下的 build.gradle

原有的 apply plugin 变更为 plugins,其他的影响不大。

复制代码
apply plugin: 'com.android.application'

plugins {
    id 'com.android.application'
}
相关推荐
通玄31 分钟前
Jetpack Compose 入门系列(十):Paging 3 分页加载
android
hunterandroid37 分钟前
DataStore 工程化实践:迁移、并发更新与异常恢复
android·前端
程序员-珍3 小时前
报错下载android sdk失败
android·java
齊家治國平天下4 小时前
AAOS 电源管理深度解析:休眠/唤醒/功耗优化
android·车载系统·aaos·aosp·电源管理·休眠唤醒·carpowermanager
Xzaveir4 小时前
企业号码展示不可观测怎么办:状态机、拨测事件与异常回放
android·人工智能
2501_916007475 小时前
iOS和macOS应用程序性能分析和优化工具使用综合指南
android·macos·ios·小程序·uni-app·iphone·webview
黄林晴5 小时前
Nearby Connections 重大变更:不再自动开启 Wi-Fi / 蓝牙,适配指南
android
恋猫de小郭5 小时前
Flutter 全新真 3D 实现,用 flutter_scene 能开发一个「我的世界」
android·前端·flutter
HLC++18 小时前
Linux的进程间通信
android·linux·服务器
爱笑鱼1 天前
Binder(二):AIDL 生成的 Proxy、Stub 和 Parcel 到底在做什么?
android