Jetpack Compose pit process

〇 Preface

Google’s official Android Developer Challenge for Jetpack Compose has today announced the fourth and final week of the topic. Faced with this new technology trend, the big guys are all gearing up, and I’m eager to watch it. I’m learning. There are still a lot of pits found, hereby record.

1. Use the preview version of Android Studio

Currently (2021-03-18) the latest stable version of Android Studio is 4.1.2, and Jetpack Compose development is not yet supported. Jetpack Compose development requires the latest preview version of Android studio 4.2 . The official website download preview version is a free installation version, open it directly\ bin\studio64.exe is fine.

Two, project configuration

When a new project is synchronized, an error will be reported directly:

Build file 'D:\AndroidCode\AndroidStudioProjects\Demo031803\app\build.gradle' line: 2


> Failed to apply plugin 'com.android.internal.application'.
> java.util.concurrent.ExecutionException: java.lang.NoSuchMethodException: java.lang.invoke.MethodHandles.privateLookupIn(java.lang.Class, java.lang.invoke.MethodHandles$Lookup)

* Try:
Run with --scan to get full insights.

This is caused by the mismatch between the gradle version and the Java version. The default Gradle version of the new project is 6.8.2, and the Gradle Plugin version is 7.0.0-alpha10:

Correspondingly, the Java version requires Java 11, and you can modify the JDK to Embedded JDK:

Or modify the appropriate Gradle and Gradle Plugin version.

Three, Jetpack Compose preview

Since Jetpack Compose is a declarative UI, it must be able to preview, but you may encounter this situation: A successful build is needed before the preview can be displayed.

At this time, you need to rebuild the project (Build -> Rebuild Project), and you can see the preview view after success. If the preview view is still not displayed, you need to close AS and reopen the project

 

Fourth, the API is abandoned

The Beta version of Jetpack Compose has just been released. The Beta version also means that its API is relatively stable. The APIs of the previous preview versions are not stable, and it is normal for the API to be deprecated. Therefore, it is not necessarily the case that the previous writing is directly used to report the red. Environmental issues, see if the API has been abandoned.
For example: ScrollableRow, ScrollableColumn functions have been marked obsolete in the alpha11 version, it is recommended to use LazyRow, LazyColumn instead.

 

Guess you like

Origin blog.csdn.net/beita08/article/details/114982410