kotlin-examples icon indicating copy to clipboard operation
kotlin-examples copied to clipboard

Android Studio doesn't understand SharedCode module in mpp-iOS-Android

Open r3h0 opened this issue 6 years ago • 9 comments

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.

image

Steps to reproduce:

  1. Clone kotlin-examples
  2. Open root of mpp-iOS-Android project in the latest Android Studio (v3.2.1 as of now)
  3. Note that the SharedCode_commonMain module doesn't have any source code listed
  4. Open app/src/main/java/com/jetbrains/jonnyzzz/myapplication/MainActivity.kt and note that Android Studio doesn't know where the createApplicationScreenMessage function comes from, so it thinks it's an error

r3h0 avatar Nov 08 '18 21:11 r3h0

@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.

r3h0 avatar Nov 09 '18 16:11 r3h0

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?

jonnyzzz avatar Nov 10 '18 13:11 jonnyzzz

That's correct; I can compile the project. The static analysis is limited, but the workaround I mentioned has been helpful.

r3h0 avatar Nov 12 '18 14:11 r3h0

I'm facing this same issue, @jonnyzzz @r3h0 how did you guys fix it?

RafaelPlantard avatar Jan 20 '19 02:01 RafaelPlantard

The original problem with the tooling is not yet fixed. You may watch for the https://youtrack.jetbrains.com/issue/KT-25941

jonnyzzz avatar Jan 20 '19 13:01 jonnyzzz

Thanks @jonnyzzz I created the project using IntelliJ IDEA and after opened on Android Studio and it worked

RafaelPlantard avatar Jan 20 '19 22:01 RafaelPlantard

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.

GoMino avatar Jan 29 '19 20:01 GoMino

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 😄

egarc avatar May 10 '19 02:05 egarc

I also ran into where the xcode-frameworks directory wasn't getting created. Running ./gradlew build from the command line seemed to fix this.

egarc avatar May 10 '19 18:05 egarc