AS升级到gradle 7.0时遇到的若干问题

阿里云仓库编译无法通过的问题

我们使用阿里镜像去下载库,升级到7.0时会出现以下错误:

opt-in, is unsupported. Switch Maven repository 
'maven(http://maven.aliyun.com/nexus/content/groups/public/)' to redirect to a secure 
protocol (like HTTPS) or allow insecure protocols.

解决办法:在项目的build.gradle中加入allowInsecureProtocol = true,如下:
在这里插入图片描述
参考资料:
https://www.cnblogs.com/langkyeSir/p/14877709.html

No signature of method

报错信息:

No signature of method: build_6yelzgvzgvo56ckx44as1sptq.android() is applicable for argument types: (build_6yelzgvzgvo56ckx44as1sptq$_run_closure2) values: [build_6yelzgvzgvo56ckx44as1sptq$_run_closure2@1af01979]

在module的build.gradle中删除以下代码即可:

javaCompileOptions {
            annotationProcessorOptions {
                arguments = [fragmentArgsLogWarnings: 'false']
                includeCompileClasspath true
            }
        }

在这里插入图片描述
参考资料:https://stackoverflow.com/questions/67418660/no-signature-of-method-android-is-applicable-for-argument-types-exception-i

Android Gradle plugin requires Java 11

这里是需要安装 jdk 11,在官网下载这个版本的jdk安装即可
报错信息:

A problem occurred evaluating project ':cachewebviewlib'.
> Failed to apply plugin 'com.android.internal.library'.
   > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
     You can try some of the following options:
       - changing the IDE settings.
       - changing the JAVA_HOME environment variable.
       - changing `org.gradle.java.home` in `gradle.properties`.

参考资料:http://nfail.com/q/39mEKy
在这里插入图片描述

you anti-virus program might be impacting your build performance

AS每次打开的时候都会报出以下警告:
在这里插入图片描述
将上面出现的文件夹加入杀毒白名单即可。
我电脑上安装的是360,所以在360的白名单中加入之后,就没有再报了。
在这里插入图片描述
参考资料:
https://www.jmwww.net/file/10235.html
https://www.pianshen.com/article/71351202014/

gralde加速构建方法

在这里插入图片描述

## Project-wide Gradle settings.
#
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# 编译时使用守护进程
org.gradle.daemon=true
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# JVM最大允许分配的堆内存,按需分配
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# 使用并行编译
org.gradle.parallel=true
# 启用新的孵化模式
org.gradle.configureondemand=true
#

参考资料:https://blog.csdn.net/ccj659/article/details/51324389

gradle编译错误问题

在Terminal中输入graldew assembleRelease后,会报如下错误:

* What went wrong:
Execution failed for task ':xrecyclerview:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.tasks.VerifyLibraryResourcesTask$Action
   > Android resource linking failed
     ERROR:C:\Users\it21sj\.gradle\caches\transforms-3\a3e21b353ed623e8bb168c30ebae0d6d\transformed\appcompat-1.0.0\res\values-v28\values-v28.xml:5:5-8:13: AAPT: error: resource androi
d:attr/dialogCornerRadius not found.

     ERROR:C:\Users\it21sj\.gradle\caches\transforms-3\a3e21b353ed623e8bb168c30ebae0d6d\transformed\appcompat-1.0.0\res\values-v28\values-v28.xml:9:5-12:13: AAPT: error: resource andro
id:attr/dialogCornerRadius not found.

     ERROR:C:\Users\it21sj\.gradle\caches\transforms-3\1e404282fde982dcc25bc5f2e987f739\transformed\core-1.0.0\res\values\values.xml:57:5-88:25: AAPT: error: resource android:attr/font
VariationSettings not found.

     ERROR:C:\Users\it21sj\.gradle\caches\transforms-3\1e404282fde982dcc25bc5f2e987f739\transformed\core-1.0.0\res\values\values.xml:57:5-88:25: AAPT: error: resource android:attr/ttcI
ndex not found.

关键报错信息:AAPT: error: resource android:attr/ttcIndex not found.

出现这个问题的原因是,在一个项目中有module的 compileSdkVersion版本在28以下,将所有的module改为28及以上版本即可
参考资料:
https://www.jianshu.com/p/c8e1735bf72c
https://www.cnblogs.com/yunshangyue71/p/13424766.html

Execution failed for task

在执行Build→Rebuild Project的时候,会在build控制台出现以下报错信息
在这里插入图片描述
出现这种问题,点击Run with --info可以看到报错的详细信息,根据提示去修改。
我这里具体是集成buggly有问题,我将buglly更新、热更新全部删掉,重新集成后不会报错了。弄好了之后回头来看问题应该是下面截图位置的错误,将bugly的插件相关信息删除即可。
在这里插入图片描述

jitpack发布出现的问题

Failed to apply plugin ‘com.github.dcendents.android-maven’.

git上的仓库release之后在jitpack.io上发布的时候会报一下错误:

FAILURE: Build failed with an exception.

* Where:
Script '/script/maven-plugin.gradle' line: 2

* What went wrong:
A problem occurred evaluating script.
> Failed to apply plugin 'com.github.dcendents.android-maven'.
   > Could not create plugin of type 'AndroidMavenPlugin'.
      > Could not generate a decorated class for type AndroidMavenPlugin.
         > org/gradle/api/publication/maven/internal/MavenPomMetaInfoProvider

解决办法,在对应的module的gradle.build文件里面增加以下配置

plugins {
    ...
    id 'maven-publish'
}

afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                from components.release
                groupId = 'com.petterp'
                artifactId = 'statex'
                version = '1.0-dev02'
            }
        }
    }
}
  • groupId 是你的包名除 labrary 之前的全称
  • artifactId 对应 labrary id ,即组件ID
  • version 版本号

然后在提交上去,重新发布即可。
部分项目还有可能碰到Java 11的问题,报错如下,请参阅资料里面有解决方法。

Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.

此错误参阅资料:
https://python.iitter.com/other/141094.html
https://www.aisoutu.com/a/934402

  • 4
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 16
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值