android-compose/sample问题汇总

最近项目不忙 就想学下compose. 官方github代码地址
https://github.com/android/compose-samples

嗯,第一步clone下来,是个文件夹,随便打开个项目先看下项目结构


image.png

编译一下,这里出现了第一个错误

This version of the Android Support plugin for IntelliJ IDEA (or Android Studio) cannot open this project, please retry with version 2020.3.1 or newer.

报as版本不是最新的
修改这里

  //  const val androidGradlePlugin = "com.android.tools.build:gradle:7.0.0-alpha14"
    const val androidGradlePlugin ="com.android.tools.build:gradle:4.2.0-rc01"

问题搞定 继续编译
出现了第二个问题

e: This version (1.0.0-alpha13) of the Compose Compiler requires Kotlin version 1.4.30 but you appear to be using Kotlin version 1.4.31 which is not known to be compatible.  Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).

我以为是kotlin版本问题修改之后 发现根本解决不了,kotlin版本位置如下


    object Kotlin {
        private const val version = "1.4.30"
        const val stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$version"
        const val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$version"
        const val extensions = "org.jetbrains.kotlin:kotlin-android-extensions:$version"
    }

后来看到后面有一句这个suppressKotlinVersionCompatibilityCheck,根据这个问题查到这个文章

https://stackoverflow.com/questions/66369899/why-kotlin-collections-is-not-implicitly-imported-after-upgrading-to-jetpack-com

在app下的build.gradle加入以下代码


image.png
            //freeCompilerArgs += ["-P", "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"]

又解决一个问题,但是还没完,运行完装好了打开app就崩溃报错

java.lang.NoSuchFieldError: No static field Companion of type Landroidx/compose/foundation/layout/BoxScope$Companion; in class Landroidx/compose/foundation/layout/BoxScope; or its superclasses (declaration of 'androidx.compose.foundation.layout.BoxScope' appears in /data/app/com.example.jetcaster-r7o7MJoqD6RW9icxLk5_1Q==/base.apk)

明天再改吧。。。。
这个问题发现是改动了compose的版本问题,保持不动就好了

            private const val version = "1.0.0-beta04"

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 夜莺2517阅读 127,784评论 1 9
  • 版本:ios 1.2.1 亮点: 1.app角标可以实时更新天气温度或选择空气质量,建议处女座就不要选了,不然老想...
    我就是沉沉阅读 11,831评论 1 6
  • 我是黑夜里大雨纷飞的人啊 1 “又到一年六月,有人笑有人哭,有人欢乐有人忧愁,有人惊喜有人失落,有的觉得收获满满有...
    陌忘宇阅读 12,718评论 28 53
  • 兔子虽然是枚小硕 但学校的硕士四人寝不够 就被分到了博士楼里 两人一间 在学校的最西边 靠山 兔子的室友身体不好 ...
    待业的兔子阅读 7,492评论 2 9