【错误记录】Android Studio 中最新的 Gradle 配置中设置插件依赖 ( 2023 年 8 月 24 日 | 最新 Gradle 中配置插件依赖的变化 | 增加 Maven 仓库源 )

2023-08-24 17:50:24





一、最新 Gradle 中配置插件依赖的变化



当前最新的 Android Studio 开发环境 , 生成的 Gradle 配置脚本使用了最新 API , 用起来不太习惯 ;

根目录下的 build.gradle 构建脚本变成了下面的样式 , 单纯的用于配置 Android 应用编译所需插件的 插件 和 版本 ;

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

原来应用中配置插件 , 是在 根目录下的 build.gradle 中的 buildscript / dependencies 中配置编译过程中所需的插件 ;

这种方式目前已经淘汰了 ;

buildscript {
    repositories {
        google()
        mavenCentral()
        jcenter()
        maven {
            url 'https://maven.aliyun.com/repository/public/'
        }
        maven{
            url 'https://maven.aliyun.com/repository/google/'
        }
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.3.1"
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

这里说明一下插件关系 , 导入了

classpath "com.android.tools.build:gradle:7.3.1"

插件 , 就相当于导入了 最新 Gradle 配置中的

    id 'com.android.application' version '7.3.1' apply false
    id 'com.android.library' version '7.3.1' apply false

这两个插件 , 一个是 Android 应用编译所需的插件 , 一个是 Android 依赖库编译所需的插件 ;


导入的

classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20'

插件 是 Kotlin 语言插件 , 如果在 开发中使用 Kotlin 进行开发 , 就必须导入该插件 ,

对应最新 Gradle 配置中的

id 'org.jetbrains.kotlin.android' version '1.7.20' apply false

插件 ;





二、报错信息



现在有一个需求 , 就是在 Navigation 组件开发 界面跳转 时 , Bundle 数据传递是类型不安全的 , 这里需要进行 安全数据传递 ,

需要导入

classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.3.0-alpha06'

中的

id 'androidx.navigation.safeargs' version '2.3.0-alpha06' apply false

插件 , 前者是下载地址 , 后者是真实导入的 插件名称 和 插件版本号 ;


尝试在根目录中配置 androidx.navigation.safeargs 插件 ,

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.3.1' apply false
    id 'com.android.library' version '7.3.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
    id 'androidx.navigation.safeargs' version '2.3.0-alpha06' apply false
}

结果报如下错误 : 提示找不到 2.3.0-alpha06 版本的 androidx.navigation.safeargs 插件 ;

Build file 'D:\002_Project\002_Android_Learn\Navigation\build.gradle' line: 6

Plugin [id: 'androidx.navigation.safeargs', version: '2.3.0-alpha06', apply: false] was not found in any of the following sources:

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

* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'androidx.navigation.safeargs', version: '2.3.0-alpha06', apply: false] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'androidx.navigation.safeargs:androidx.navigation.safeargs.gradle.plugin:2.3.0-alpha06')
  Searched in the following repositories:
    Gradle Central Plugin Repository
    Google
    MavenRepo
	at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.resolveToFoundResult(DefaultPluginRequestApplicator.java:243)




三、增加 Maven 仓库源



在 settings.gradle 中的 pluginManagement / repositories 中增加 jcenter 和 阿里云的自定义源 , 这个源配置已经很全了 , 基本上能解决所有的问题 ;

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
        jcenter()
        maven {
            url 'https://maven.aliyun.com/repository/public/'
        }
        maven{
            url 'https://maven.aliyun.com/repository/google/'
        }
    }
}

使用上述源 , 还是报错 ,

Build file 'D:\002_Project\002_Android_Learn\Navigation\build.gradle' line: 6

Plugin [id: 'androidx.navigation.safeargs', version: '2.3.0-alpha06', apply: false] was not found in any of the following sources:

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

* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'androidx.navigation.safeargs', version: '2.3.0-alpha06', apply: false] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'androidx.navigation.safeargs:androidx.navigation.safeargs.gradle.plugin:2.3.0-alpha06')
  Searched in the following repositories:
    Gradle Central Plugin Repository
    Google
    MavenRepo
    BintrayJCenter
    maven(https://maven.aliyun.com/repository/public/)
    maven2(https://maven.aliyun.com/repository/google/)
	at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.resolveToFoundResult(DefaultPluginRequestApplicator.java:243)

在这里插入图片描述





五、使用老版本方式导入插件



使用上述 源 还是无法下载 androidx.navigation.safeargs 插件 , 这里暂时不在这个方面进行尝试了 , 不使用 plugins 新方式导入插件 ;

id 'androidx.navigation.safeargs' version '2.3.0-alpha06' apply false

使用之前的老版本的导入 编译插件 的方法 ;

首先 , 将整个 build.gradle 中 配置 plugins 插件的内容全部注释掉 ;

在这里插入图片描述
然后 , 在 settings.gradle 中添加如下代码 , 这是老版本的方式导入编译时依赖库 ;

buildscript {
    repositories {
        google()
        mavenCentral()
        jcenter()
        maven {
            url 'https://maven.aliyun.com/repository/public/'
        }
        maven{
            url 'https://maven.aliyun.com/repository/google/'
        }
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.3.1"
        classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.3.0-alpha06'
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

上面的 dependencies 中的三个依赖 , 与下面的四个插件是对应的 , com.android.tools.build:gradle:7.3.1 包含着 com.android.applicationcom.android.library 两个插件 ;

plugins {
    id 'com.android.application' version '7.3.1' apply false
    id 'com.android.library' version '7.3.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
    id 'androidx.navigation.safeargs' version '2.3.0-alpha06' apply false
}

然后再进行编译 , 即可编译通过 ;

在这里插入图片描述


完整的代码可查看 【Jetpack】Navigation 导航组件 ④ ( Fragment 跳转中使用 safe args 安全传递参数 ) https://hanshuliang.blog.csdn.net/article/details/131406972 中的博客源码快照 ;

这是开发 Navigation 导航组件时遇到的报错问题 ;

更多推荐

Java AOP Framework概述

JavaAOPFramework概述1.AspectJ1.1使用AspectJ进行切面编程2.SpringAOP2.1使用SpringAOP进行切面编程2.2如何决定使用哪种动态代理2.3如何通过配置指定代理方式2.4SpringAOP和AspectJ的关系3.SpringBootAOP4.扩展4.1AspectJ织入

面向面试知识--MySQL数据库与索引

面向面试知识–MySQL数据库与索引优化难点与面试点什么是MySQL索引?索引的MySQL官方定义:索引是帮助MySQL快速获取数据的数据结构。动力节点原文:MysQL官方对于索引的定义:索引是帮助MySQL高效获取数据的数据结构。MysQL在存储数据之外,数据库系统中还维护着满足特定查找算法的数据结构,这些数据结构以

HarmonyOS Codelab 优秀样例——溪村小镇(ArkTS)

一、介绍溪村小镇是一款展示溪流背坡村园区风貌的应用,包括园区内的导航功能,小火车行车状态查看,以及各区域的风景展览介绍,主要用于展示HarmonyOS的ArkUI能力和动画效果。具体包括如下功能:打开应用时进入启动页,启动页轮播展示溪村小镇风景图,之后进入应用首页。在首页的“地图浏览”标签页,可以拖动和缩放查看地图,并

Kubernetes Ingress:灵活的集群外部网络访问的利器

《KubernetesIngress:集群外部访问的利器-打造灵活的集群网络》前提条件您已经拥有一个Kubernetes集群,并且可以访问该集群。您已经安装了kubectl命令行工具。版本选择安装前需要选择兼容你Kubernetes的版本,不能会失败ingress由两部分组成:IngressController:负责处

【踩坑日记】springboot MultipartFile上传,@Async异步执行时报错:java,io.FileNotFoundException

项目场景:springboot项目中使用MultipartFile上传文件导入时,文件内容过大会导致页面等待时间较长,所以考虑使用上传文件时用@Async异步处理数据的方式来解决页面等待问题。问题描述给处理MultipartFile文件的方法添加@Async注解后,上传文件时出现异常,找不到临时文件异常如下:(org.

RISC-V Reader 笔记(七)RV64,特权架构,未来可选扩展

RV64比起RV32,其实扩展不多。主要是添加了一系列字,双字为单位的操作。各个ISA3264比较x86:变量都存在寄存器里,不像32存在内存里,因此指令数少很多,但是因此添加了很多新操作码来操作更多的寄存器,因此指令长度变长了(添加前缀来区分),代码体积大很多。arm:有一系列和arm32类似的问题,:分支指令使用的

重庆思庄技术分享——linux du 命令

linuxdu命令inuxdu(英文全拼:diskusage)命令用于显示目录或文件的大小。du会显示指定的目录或文件所占用的磁盘空间。语法du[-abcDhHklmsSx][-L<符号连接>][-X<文件>][--block-size][--exclude=<目录或文件>][--max-depth=<目录层数>][-

Nodejs 第十六章(ffmpeg)

FFmpeg是一个开源的跨平台多媒体处理工具,可以用于处理音频、视频和多媒体流。它提供了一组强大的命令行工具和库,可以进行视频转码、视频剪辑、音频提取、音视频合并、流媒体传输等操作。FFmpeg的主要功能和特性:格式转换:FFmpeg可以将一个媒体文件从一种格式转换为另一种格式,支持几乎所有常见的音频和视频格式,包括M

Linux arm64 pte相关宏

文章目录一、pte和pfn1.1pte_pfn1.2pfn_pte二、其他宏参考资料一、pte和pfn//linux-5.4.18/arch/arm64/include/asm/pgtable.h#definepte_pfn(pte)(__pte_to_phys(pte)>>PAGE_SHIFT)#definepfn_

Zebec 生态 AMA 回顾:Nautilus 以及 $ZBC 的未来

在9月7日,Zebec创始人Sam做客社区,并进行了“NautilusChain以及$ZBC的未来”主题的AMA访谈。Sam在本次访谈中对NautilusChain生态的价值捕获、Zebec生态布局规划、可能会推出的NautilusChain治理通证NAUT进行了解读。本文将对本次AMA进行回顾与总结。主持人:社区新的

java顺序表的基本操作

Java中的顺序表通常可以使用数组来实现。顺序表是一种线性数据结构,它包含一组按照顺序排列的元素。以下是顺序表的基本操作:创建顺序表:int[]array=newint[capacity];//创建一个具有指定容量的整数数组作为顺序表插入元素://在指定位置插入元素voidinsert(int[]array,intin

热文推荐