侧边栏壁纸
  • 累计撰写 372 篇文章
  • 累计创建 60 个标签
  • 累计收到 109 条评论

目 录CONTENT

文章目录

Android Stuido Chipmunk 编译错误汇总

Z同学
2022-10-27 / 0 评论 / 2 点赞 / 217 阅读 / 1,603 字
温馨提示:
本文最后更新于 2022-10-28,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

1. 问题列表

主要记录一些Android Studio在编译过程中出现的异常错误。以及自己的一些解决方法。

很多问题大家都碰见过,并且网上也有不少的文档介绍如何解决。而这里我只是基于自身碰见的问题,进行一个汇总。方便以后进行查询和归纳。

关于更多的错误问题,我都有总结错误。可以通过:https://zinyan.com/tags/androiderror 了解。

1.1 Error :Cannot choose between the following variants of org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10:

今天在编译一个老项目的时候,突然提示这个错误。

输出:

A problem occurred configuring root project 'ModelTesting'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10.
     Required by:
         project :
      > Cannot choose between the following variants of org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10:
          - gradle70JavadocElements
          - gradle70RuntimeElements
          - gradle70SourcesElements
          - javadocElements
          - runtimeElementsWithFixedAttribute
          - sourcesElements
        All of them match the consumer attributes:
          - Variant 'gradle70JavadocElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10:
              - Unmatched attributes:
                  - Found org.gradle.category 'documentation' but wasn't required.
                  - Found org.gradle.docstype 'javadoc' but wasn't required.
                  - Required org.gradle.jvm.version '8' but no value provided.
                  - Required org.gradle.libraryelements 'jar' but no value provided.
                  - Found org.gradle.plugin.api-version '7.0' but wasn't required.
                  - Found org.gradle.status 'release' but wasn't required.
              - Compatible attributes:
                  - Required org.gradle.dependency.bundling 'external' and found compatible value 'external'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
          - Variant 'gradle70RuntimeElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10:
              - Unmatched attributes:
                  - Found org.gradle.category 'library' but wasn't required.
                  - Found org.gradle.jvm.environment 'standard-jvm' but wasn't required.
                  - Found org.gradle.plugin.api-version '7.0' but wasn't required.
                  - Found org.gradle.status 'release' but wasn't required.
              - Compatible attributes:
                  - Required org.gradle.dependency.bundling 'external' and found compatible value 'external'.
                  - Required org.gradle.jvm.version '8' and found compatible value '8'.
                  - Required org.gradle.libraryelements 'jar' and found compatible value 'jar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
          - Variant 'gradle70SourcesElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10:
              - Unmatched attributes:
                  - Found org.gradle.category 'documentation' but wasn't required.
                  - Found org.gradle.docstype 'sources' but wasn't required.
                  - Required org.gradle.jvm.version '8' but no value provided.
                  - Required org.gradle.libraryelements 'jar' but no value provided.
                  - Found org.gradle.plugin.api-version '7.0' but wasn't required.
                  - Found org.gradle.status 'release' but wasn't required.
              - Compatible attributes:
                  - Required org.gradle.dependency.bundling 'external' and found compatible value 'external'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
          - Variant 'javadocElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10:
              - Unmatched attributes:
                  - Found org.gradle.category 'documentation' but wasn't required.
                  - Found org.gradle.docstype 'javadoc' but wasn't required.
                  - Required org.gradle.jvm.version '8' but no value provided.
                  - Required org.gradle.libraryelements 'jar' but no value provided.
                  - Found org.gradle.status 'release' but wasn't required.
              - Compatible attributes:
                  - Required org.gradle.dependency.bundling 'external' and found compatible value 'external'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
          - Variant 'runtimeElementsWithFixedAttribute' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10:
              - Unmatched attributes:
                  - Found org.gradle.category 'library' but wasn't required.
                  - Found org.gradle.jvm.environment 'standard-jvm' but wasn't required.
                  - Found org.gradle.status 'release' but wasn't required.
              - Compatible attributes:
                  - Required org.gradle.dependency.bundling 'external' and found compatible value 'external'.
                  - Required org.gradle.jvm.version '8' and found compatible value '8'.
                  - Required org.gradle.libraryelements 'jar' and found compatible value 'jar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
          - Variant 'sourcesElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10:
              - Unmatched attributes:
                  - Found org.gradle.category 'documentation' but wasn't required.
                  - Found org.gradle.docstype 'sources' but wasn't required.
                  - Required org.gradle.jvm.version '8' but no value provided.
                  - Required org.gradle.libraryelements 'jar' but no value provided.
                  - Found org.gradle.status 'release' but wasn't required.
              - Compatible attributes:
                  - Required org.gradle.dependency.bundling 'external' and found compatible value 'external'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.

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

解决方法:

把我们build.gradle文件中的 classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10'

版本往前调。kotlin 1.7版本的插件,在配置文档上有比较大的改进。

总而言之,言而总之: 将1.7.10 改为 1.6.10 等版本就可以了:

    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.0'
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

不能是系统建议我们升级版本,我们就升级版本。

1.2 Error GSON.fromJson(json, Pref…urationState::class.java) must not be null

这个其实更多是缓存造成的。我们的Gradle会用到GSON。这是插件用的,和我们本身的项目没有关系哦。

Gradle会生成各种缓存配置,例如build文件夹,和cxx文件夹等。

解决方法:

手动删除项目中配置cxx缓存文件夹 和build缓存文件夹。

然后再重新构造一下你的项目。就会发现正常运行编译了。

1.3 提示: Support for ANDROID_NDK_HOME is deprecated and will be removed in the future. Use android.ndkVersion in build.gradle instead.

其实这个错误,不会影响现在的编译。他只是告诉我们对于 ANDROID_NDK_HOME 配置的环境变量。已经被Android Studio给弃用了。

之后版本会被删除(具体版本,没有说。)。然后让我们通过build.gradle中的android.ndkVersion 进行配置

解决:

android {
    compileSdkVersion 29

    defaultConfig {
       ...
	}
	ndkVersion '23.1.7779620'
}

这个ndkVersion 版本号如果比较懵逼不知道该写啥的。

可以通过 Android SDK面板中看 NDK(Side by side) 里面就是ndk的版本号了。我们本机下载了哪个版本号,就复制哪个版本号就可以了

如果你配置之后,还是出现提示?那么也没有关系。因为我们电脑上的ANDROID_NDK_HOME 环境变量还存在。所以才会提示。你如果实在不能接受。可以删除环境变量中配置的NDK值。以后也不用这么配置了。

即时是Linux系统上。也可以不用再单独下载ndk进行配置ndk的环境变量了。工具总是在不断迭代和更新的。

就先总结这些错误吧。如果有更多的再开新文档总结。

2

评论区