JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.11k stars 1.17k forks source link

New Project Wizard is flawed in multiple ways #158

Closed RaphaelTarita closed 3 weeks ago

RaphaelTarita commented 3 years ago

I hope this is the right place to report this, since the project wizard is technically part of the IntelliJ Kotlin Plugin, but the Compose for Desktop template is only related to this project and not to the kotlin plugin. If I'm wrong here, please redirect me.

The issue is that the "Jetpack Compose for Desktop - Multiplatform" project template produces a new project that already contains multiple errors. Here's a list of steps to reproduce and the errors that appear at the different stages:

  1. File -> New Project -> Kotlin -> Jetpack Compose for Desktop (Experimental) -> Multiplatform
  2. Choose name and location (I'll use test and D:\dev\test for now)
  3. Build System: Gradle Kotlin (only available option)
  4. Project JDK: 15 (I use OpenJDK 15 but I suppose the JDK vendor does not matter)
  5. Artifact Coordinates: Group ID "com.example", Artifact ID "test", Version "1.0"
  6. Click 'Next' and select Android SDK if not detected automatically
  7. Click 'Finish'

-> Error 1: During the Gradle Import, the following warning appears:

Duplicate content roots detected
        Path [D:/dev/test/common/src/androidTest/kotlin] of module [test.common.androidAndroidTest] was removed from modules [test.common.androidTest]
        Also 1 more path was deduplicated. See idea log for details
  1. Wait for the Gradle Import to finish
  2. Go to: Gradle Tool Window -> test/Tasks/build and run "build"

-> Error 2: During the Gradle Build, the following warning appears:

Warning: The 'kotlin-android-extensions' Gradle plugin is deprecated. Please use this migration guide (https://goo.gle/kotlin-android-extensions-deprecation) to start working with View Binding (https://developer.android.com/topic/libraries/view-binding) and the 'kotlin-parcelize' plugin.

-> Error 3: During the following gradle tasks:

the following warning appears:

warning: [options] source value 7 is obsolete and will be removed in a future release
warning: [options] target value 7 is obsolete and will be removed in a future release
  1. Go to: Gradle Tool Window and run "Reload All Gradle Projects" (Errors 1 and 2 will appear again)
  2. Go to: test/android/src/main/java/com/example/android/MainActivity

-> Error 4: test/android/src/main/java is not marked as Sources Root, therefore Inspections are greatly reduced for this file

  1. Mark test/android/src/main/java as "Sources Root"

-> Error 5: IntelliJ cannot find any of the imports, this causes 10 code errors in total. The imports affected are:

  1. Go to: test/common/src/androidMain/kotlin/com.example.common.platform.kt`

-> Error 6: IntelliJ marks getPlatformName() as error because "Actual function 'getPlatformName' has no corresponding expected declaration". Apparently, the expect declaration at test/common/src/commonMain/kotlin/com.example.common/platform.kt is not found.

  1. Go to: test/common/src/androidTest

-> Error 7: The directory is not marked as a module root, but instead the two subdirectories "kotlin" and "resources" are marked as module roots and test sources root. The displayed module name for "kotlin" is "androidAndroidTest" and for "resources" it's "androidTest".

As far as I know, those are all errors or weird behaviours that appear in a fresh project from the "Jetpack Compose for Desktop - Multiplatform" template that has not been edited in any way.

I'm quite confused about why I am getting all these problems in a fresh project, moreover I'd like to know how I can fix them. The gradle build seems to work (ignoring the warnings) and the sample desktop application works as expected. However, the unavailable and/or erroneous inspections for android-related modules make it really hard to properly work with Jetpack Compose for Desktop. If the error is somehow related to my configuration (although I mainly sticked to the standard), please tell me how to change it in order to fix the problems.

Environment:

olonho commented 3 years ago

Thanks for report, please make sure that you have Android SDK available.

igordmn commented 3 years ago

Thanks for the detailed report!

I checked on this configuration:

And created the project from the multiplatform template:

Can't reproduce errors 1/4/5/6. If setting Android SDK will not help, can you try on a clean configuration of IDEA, without importing the old settings? Or redownload Android SDK, it can be broken.

Error 2

Errors 3/7 need further investigation, not sure what is the cause.

RaphaelTarita commented 3 years ago

I tried to "fix" my android SDK but it seems that there was nothing wrong with it. Here are the steps I took:

  1. Control Test (still the same errors as yesterday)
  2. Checking whether Android Studio or the integrated SDK Manager detects the SDK properly (it does)
  3. I installed my android-sdk via scoop, so I used scoop uninstall android-sdk --purge to get rid of everything for a new clean installation
  4. I checked Android Studio again to see whether it detects another "hidden" SDK somewhere I might have forgotten about (was not the case)
  5. Reinstallation of the Android SDK (scoop install android-sdk)
  6. Again, I checked Android Studio, but it told me that my installation is "incomplete", so I downloaded the rest via Android Studio.
  7. New test of the original issue in IntelliJ IDEA (still the same errors)
  8. I thought that maybe the "incomplete" scoop installation might be a problem so I ran another uninstall --purge and reinstalled to a different location using only Android Studio
  9. Another test of the original issue in IntelliJ. This time I had to manually re-select the sdk location in the project wizard because it had changed. (still the same errors, but this time I got license agreement warnings for android-sdk. I accepted all licenses using sdkmanager.bat)

It really seems that this problem is not related to an android sdk problem after all, or I am missing something obvious.

I tried to further investigate the problem and found a little bit of new context:

I also noticed two additional "errors" in File -> Project Structure that might provide some more insight:

  1. In the "Modules" menu, the element "test/android/Kotlin" shows the warning "'kotlin' library not found in the module dependencies list". I double-checked that this issue only appears for this module and not for any other module in the list.

  2. In the "Problems" menu, it shows two problems:

1. Library Gradle: org.jetbrains.kotlinx:kotlinx-coroutines-core-metadata:commonMain:1.4.1 has broken classes paths:
D:\dev\test\desktop\build\tmp\kotlinMetadata\jvmMain\implementation\org.jetbrains.kotlinx-kotlinx-coroutines-core-metadata\org.jetbrains.kotlinx-kotlinx-coroutines-core-metadata-commonMain.klib [Fix]

2. Library Gradle: org.jetbrains.kotlinx:kotlinx-coroutines-core-metadata:concurrentMain:1.4.1 has broken classes paths:
D:\dev\test\desktop\build\tmp\kotlinMetadata\jvmMain\implementation\org.jetbrains.kotlinx-kotlinx-coroutines-core-metadata\org.jetbrains.kotlinx-kotlinx-coroutines-core-metadata-concurrentMain.klib [Fix]

I hope all of this can shed more light on the problem! I'm not quite certain what you mean with "try on a clean configuration of IDEA, without importing the old settings". Should I re-install the IDE without referring to my config folder?

RaphaelTarita commented 3 years ago

Just wanted to add that I just tried this again with a fresh IDE installation. My scoop installation of IntelliJ IDEA Ultimate wasn't properly updating to minor releases, so I re-installed it. But most of the config options and plugins were restored because I have "Settings Sync" activated (tbh that was very convenient).

All the errors persisted just as I have described them at first. For that reason, I can rule out that my IDE installation was broken in some way. What I can not rule out is that the problem is somehow linked to my IDE config and/or plugins. Does anyone know a safe way to revert all config options of IntelliJ to the default options, but being able to switch back to my old config later?

igordmn commented 3 years ago

way to revert all config options of IntelliJ to the default options, but being able to switch back to my old config later

To revert IDEA to default state you can just rename %APPDATA%\JetBrains\Idea* folder.

To restore - rename the folder back.

Don't know how it will work with "Settings Sync" though. Probably it should be disabled first.

RaphaelTarita commented 3 years ago

Okay, so I tried this again. I turned off the settings sync in the IDE, deleted config and system folder, did another clean re-installation, disabled all downloaded plugins and tried to set up the same basic project again. I ran into the same errors again. I don't know what's going on here.

RaphaelTarita commented 3 years ago

I fixed it.

I did two things and apparently both played a role in resolving the problems.

Firstly, I was still not sure about my Android SDK. I mean I specify its location in the project wizard, but I was still suspicious. Checking my environment variables, it turned out that I only had ANDROID_HOME (which is deprecated anyway) and ANDROID_SDK_HOME (which was probably pointing to a wrong location) set. So I deleted those and followed this StackOverflow answer to set all possibly needed envs (except for ANDROID_NDK_ROOT).

Secondly, I noticed that even though I specified the location of the SDK in the project wizard, it did not show up in Project Structure > SDKs. So I added it manually there.

This, and some re-building and re-importing actually solved the problems.

There are two reasons why I don't think the issue should be closed already:

  1. I'm not yet entirely sure what caused the problems and how my actions fixed them
  2. I think it would be expected behaviour to register the Android SDK under 'Project Structure > SDKs' when you already specify it in the project wizard. As of now, the SDK location specified in the wizard seems to be barely relevant.
akurasov commented 3 years ago

To retest on plugin 1.5.30

okushnikov commented 3 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.