-
Android Studio版本
- Arctic Fox(2020.3.1)时间:更新时间2021/7/30
- 该版本支持Compose和Preview等最新功能
-
如果更新到该Android Studio版本可以直接新建一个Compose项目
-
这里记录一下我遇到的问题
-
因为今天刚更新的Android Studio,前天创建项目时并没有上面的那个创建Compose项目的选项,而是创建了一个Empty Acticity一个普通的Android项目。通过遇到的问题以及对创建的两个项目进行对比,在原先的项目中添加如下设置也可以使用Compose。
- gradle版本:这里出现很多问题,因为Compose是一个比较新的内容,我将原先的gradle版本以及插件替换为最新的版本就解决了这个问题。
#Fri Jul 30 20:04:17 CST 2021 distributionBase=GRADLE_USER_HOME distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME
-
根目录下的build.gradle:该gradle运行的jdk环境为11
buildscript { ext { compose_version = '1.0.0' kotlin_version = '1.4.32' } repositories { google() mavenCentral() } dependencies { classpath "com.android.tools.build:gradle:7.0.0" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } }
-
app目录下的build.gradle
buildFeatures { // Enables Jetpack Compose for this module compose true } // 简洁的依赖 implementation 'androidx.compose.ui:ui:1.0.0' // Tooling support (Previews, etc.) implementation 'androidx.compose.ui:ui-tooling:1.0.0' // Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.) implementation 'androidx.compose.foundation:foundation:1.0.0' // Material Design implementation 'androidx.compose.material:material:1.0.0' // Material design icons implementation 'androidx.compose.material:material-icons-core:1.0.0' implementation 'androidx.compose.material:material-icons-extended:1.0.0-rc02' // Integration with activities implementation 'androidx.activity:activity-compose:1.3.0' implementation 'androidx.core:core-ktx:1.5.0' implementation 'com.google.android.material:material:1.4.0'
-