kotlin-examples
kotlin-examples copied to clipboard
Android Studio doesn't understand SharedCode module in mpp-iOS-Android
The mpp-iOS-Android doesn't quite work in the latest Android Studio. It builds without errors, and I am able to run it on an Anrdoid device, but the common code can't be edited inside Android Studio. Right now, I'd have to edit the Kotlin source in a basic text editor.
The attached screenshot shows how the SharedCode_commonMain
doesn't show the common source files, resulting in the createApplicationScreenMessage
function being unrecognized.
Steps to reproduce:
- Clone kotlin-examples
- Open root of mpp-iOS-Android project in the latest Android Studio (v3.2.1 as of now)
- Note that the
SharedCode_commonMain
module doesn't have any source code listed - Open
app/src/main/java/com/jetbrains/jonnyzzz/myapplication/MainActivity.kt
and note that Android Studio doesn't know where thecreateApplicationScreenMessage
function comes from, so it thinks it's an error
@jonnyzzz, if there's anything I can help to investigate, let me know.
What I'm doing as a workaround for now is using the "Project" view in Android Studio, which lets me access the commonMain
source code. After I build the project, navigating to createApplicationScreenMessage
takes me to the decompiled source code. From there, I associate the decompiled code with the commonMain
module. Since I'm running on Linux, I still get errors because of the iOS project; I had to "unload" those modules.
I also changed ext.kotlin_version
to 1.3.0
and the Gradle plugin version to 3.2.1
. I don't know if that made any difference.
Shout out to @PeeJWeeJ for helping me find a workaround.
It does not work for me too. Please follow the issue for Kotlin MPP. https://youtrack.jetbrains.com/issue/IDEA-202036
I was able to compile the project (no matter there were the errors in the editor), did you?
That's correct; I can compile the project. The static analysis is limited, but the workaround I mentioned has been helpful.
I'm facing this same issue, @jonnyzzz @r3h0 how did you guys fix it?
The original problem with the tooling is not yet fixed. You may watch for the https://youtrack.jetbrains.com/issue/KT-25941
Thanks @jonnyzzz I created the project using IntelliJ IDEA and after opened on Android Studio and it worked
For my part, I just needed to add the dependency to the SharedCode
module in the build.gradle
of the android project
.
dependencies {
...
implementation project(':SharedCode')
...
}
Then sync your gradle, and your references should now resolve.
Misreading the above advice, I instead added implementation project(':SharedCode')
to the project's build.gradle
file. This created an error, so I removed that line, and gradle rebuilt along with the bin
directory. Not sure what I inadvertently did, but if anybody has an explanation, this iOS dev would appreciate it 😄
I also ran into where the xcode-frameworks
directory wasn't getting created. Running ./gradlew build
from the command line seemed to fix this.