fwcd / vscode-kotlin

Kotlin code completion, debugging, linting and more for VSCode
MIT License
294 stars 36 forks source link

How to use the extension with an Android project? #8

Closed marmistrz closed 5 years ago

marmistrz commented 5 years ago

I have a simple Android project. I opened it in VS Code after installing the extension, but the Android-specific imports or the R.* paths are not found by the extension.

KLS seems to have some support for Android projects: https://github.com/fwcd/kotlin-language-server/commit/97b0282e69145788a8099bad3ed6b333c3958e3e

fwcd commented 5 years ago

Which build tool do you use? The Android support provided by KLS currently only supports Gradle (as implemented here).

marmistrz commented 5 years ago

I'm using gradle, I opened this project: https://github.com/marmistrz/OpenMeteo

I'll paste a log in a while

marmistrz commented 5 years ago

It appears that after restarting VS Code the Android project is correctly opened, all the Android specifics are recognized. Maybe the extension needs an editor restart to work properly?

fwcd commented 5 years ago

That's interesting, usually it shouldn't. But if it works for you now, that's great.

fwcd commented 5 years ago

Feel free to reopen if this issue occurs again.

marmistrz commented 5 years ago

I managed to reproduce the issue:

[Info  - 11:05:34 PM] main      Connected to client
[Info  - 11:05:34 PM] client    Adding workspace file:///home/marcin/proj/android/OpenMeteo to source path
[Info  - 11:05:34 PM] client    Adding .../openmeteo/ExampleUnitTest.kt, .../openmeteo/MainActivity.kt, .../openmeteo/ExampleInstrumentedTest.kt under /home/marcin/proj/android/OpenMeteo to source path
[Info  - 11:05:34 PM] client    Searching for dependencies in workspace root /home/marcin/proj/android/OpenMeteo
[Info  - 11:05:34 PM] client    Resolving classpath using Stdlib + [] or [] + Gradle or Backup
[Info  - 11:05:34 PM] client    Resolving dependencies for 'OpenMeteo' through Gradle's CLI...
[Info  - 11:05:34 PM] client    Creating temporary gradle file /tmp/classpath13010380394961104745.gradle
[Info  - 11:05:34 PM] client    Could not resolve dependencies using Gradle dependencies CLI: Cannot run program "/home/marcin/proj/android/OpenMeteo/gradlew" (in directory "/home/marcin/proj/android/OpenMeteo"): error=13, Permission denied
[Warn  - 11:05:34 PM] client    Could not resolve Gradle dependencies using any resolution strategy!
[Info  - 11:05:34 PM] client    Could not resolve kotlin-stdlib using Maven: null
[Info  - 11:05:34 PM] client    Successfully resolved kotlin-stdlib using Gradle
[Info  - 11:05:34 PM] client    Adding [/home/marcin/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.41/785575d6b699a02527a4ad16f0972fa2c1ee583f/kotlin-stdlib-1.3.41-sources.jar] to class path
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.jetbrains.kotlin.com.intellij.openapi.util.io.FileSystemUtil$FallbackMediatorImpl (file:/home/marcin/.config/Code%20-%20OSS/User/globalStorage/fwcd.kotlin/langServerInstall/server/lib/kotlin-compiler-embeddable-1.3.41.jar) to field java.io.File.fs
WARNING: Please consider reporting this to the maintainers of org.jetbrains.kotlin.com.intellij.openapi.util.io.FileSystemUtil$FallbackMediatorImpl
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[Info  - 11:05:34 PM] client    Updated configuration: {"kotlin":{"languageServer":{"enabled":true,"path":""},"compiler":{"jvm":{"target":"default"}},"linting":{"debounceTime":250},"completion":{"snippets":{"enabled":true}},"debugAdapter":{"enabled":true,"path":""},"debounceTime":250,"snippetsEnabled":true}}
[Info  - 11:05:34 PM] debounce0 Linting .../openmeteo/MainActivity.kt
[Info  - 11:05:34 PM] async0    Find symbols in TextDocumentIdentifier [
  uri = "file:///home/marcin/proj/android/OpenMeteo/app/src/main/java/com/marmistrz/openmeteo/MainActivity.kt"
]
[Info  - 11:05:34 PM] async0    Finished in 164 ms
[Info  - 11:05:35 PM] debounce0 Reported 27 diagnostics in MainActivity.kt
[Info  - 11:05:38 PM] async0    Hovering at file:///home/marcin/proj/android/OpenMeteo/app/src/main/java/com/marmistrz/openmeteo/MainActivity.kt 26:8
[Info  - 11:05:38 PM] async0    Re-parsing MainActivity.kt 24:5-33:6
[Info  - 11:05:38 PM] async0    Hovering DOT_QUALIFIED_EXPRESSION
[Info  - 11:05:38 PM] async0    Re-parsing MainActivity.kt 24:5-33:6
[Info  - 11:05:38 PM] async0    No hover found at MainActivity.kt 27:9
[Info  - 11:05:38 PM] async0    Finished in 74 ms
[Info  - 11:05:38 PM] async0    Hovering at file:///home/marcin/proj/android/OpenMeteo/app/src/main/java/com/marmistrz/openmeteo/MainActivity.kt 26:9
[Info  - 11:05:38 PM] async0    Re-parsing MainActivity.kt 24:5-33:6
[Info  - 11:05:38 PM] async0    Hovering DOT_QUALIFIED_EXPRESSION
[Info  - 11:05:38 PM] async0    Re-parsing MainActivity.kt 24:5-33:6
[Info  - 11:05:38 PM] async0    No hover found at MainActivity.kt 27:10
[Info  - 11:05:38 PM] async0    Finished in 81 ms

It looks like something tenaciously recreates the gradle wrapper which I don't want to use - I have my distribution for that.

fwcd commented 5 years ago

The language server does not create a wrapper, it just continues to search the PATH for a Gradle executable if no wrapper is present (see here). In this specific case, the LS apparently finds a gradlew in the OpenMeteo repo folder that does not have executable permissions and throws an exception in an attempt to read it.

RealYukiSan commented 3 months ago

I have add the gradlew to the PATH variable and also export ANDROID_SDK variable, but the extension cannot resolve the androidx package (UNRESOLVED_REFERENCE) even though the gradlew successfuly build and generate apk.

any guide how to fix this?