Just downloaded and started trying M3. Am an Andro...
# eap
s
Just downloaded and started trying M3. Am an Android Studio user, so installed current Intellij Idea also so I could try out the new MPP project wizard. I created a new project in Idea for targets IOS and Android. I added two additional MP modules for a total of five modules in the project(I changed the common module names); iosApp, androidApp, ioCommon, jillcess, monayCommon. The last three modules are all multiplatform, intended for use by both iosApp and androidApp. monayCommon will dependsOn ioCommon and jillcess. The wizard generated all of the directories and related gradle files, then I noticed that each of the three multiplatform modules had the same issue: androidMain and androidTest subdirectories of src are not recognized by Idea as sourceSets, In each of the modules, the src subdirectory had these subs built by the wizard (as expected).
Copy code
src
        androidMain
        androidTest
        commonMain
        commonTest
        iosMain
        iosTest
I manually added a buildSrc setup, just an FYI, don't think it's relevant to the question. In order to add dependencies for each of the environments, I ended up having to add this snippet to the kotlin sourceSets definition to add these as sourceSets:
Copy code
val androidMain by creating {
        dependsOn(commonMain)
        dependencies {
            ...
        }
    }
    val androidTest by creating {
        dependsOn(commonMain)        dependencies {
            ...
        }
    }
commonMain and commonTest were already sourceSets, so I could use the "by getting" clause to work with those. But androidMain and androidTest were not according to gradle, so "by creating" was required. Once I did this, after resync Idea and gradle both show them as sourceSets, but not quite identically. See attached file to see what the Idea project window shows after the above. Is this expected behavior? Seems like if these dirs gets created by the wizard, the android directories should also be configured as sourcesets like the common and IOS stuff is. Also my gradle skills are poor, so I'm having trouble getting androidTest to be treated as a unit test sourceSet. I'm using Kotest 4.1.1 in the ioCommon.androidTest directory (testing code in commonMain) and am having trouble running unit tests in debug from the IDE because of various gradle-related classpath issues. So my build.gradle.kts is still not correct for what I need. I'd appreciate any info if I'm doing something wrong. Am also willing to send whatever would be helpful if this really is an actual issue. The project has very little source in it as of yet, so it is easy to try changes until the setup is correct. So if anyone has suggestions of stuff to try, I can also do those. Thanks in advance forr any info...
r
Despite different markings on Android directories, it should still work as intended, does it? I mean navigation in code and resources and other stuff. I believe this is caused by specifics of how Android plugin for IDEA handles it's internal project model. This looks different even for usual single-platform JVM and Android projects, IIRC.
s
Hmm, I think you are right. The reason I went down this rabbit hole was difficulty with Kotest that I was blaiming on sourceSet issues. So today I started a clean new project in Intellij, with only one shared module. Here's the exact steps I've done so far:
Damn every time I hit enter it posts my note. I'm not used to Slack UI yet 🙂 I'll post one separate reply with my steps.
I'm guessing this is a known issue, but after create the initial sync fails:
Copy code
IOException prevents gradle sync
I had to edit the generated local.properties line:
Copy code
D:\Android\sdk to D:\\Android\\sdk
The generated one did not escape "\" properly (I'm on windows). After that sync works, except then I did these steps (mostly minor)
Copy code
```
• Changed dependency on jdk7 to jdk8
• updated androidx.core:core-ktx:1.3.0 from 1.2.0 in shared
• inserted these in shard androidTest kotlin sourceSet
dependencies { implementation("io.kotestkotest core jvm4.1.1") implementation("io.kotestkotest assertions core jvm4.1.1") implementation("io.kotestkotest runner console jvm4.1.1") runtimeOnly("org.junit.jupiterjunit jupiter engine5.6.2") }``` sync resulted with this:
Copy code
11:30 AM   The IDE modules below were removed by the Gradle project reload:
                   shared.iosMain
                   shared.iosTest
                   shared.commonMain...
Do you know why this happens? I chose to open dialog and recover all 4. which created .iml files for the various shared modules - seems like an error. Anyway, forging ahead • Copied in three source files
Copy code
2 kotlin files in commonMain
    1 kotlin file in androidTest (BasicsTest)
At this point the source files look like they will build fine - no syntax errors • Installed the newest Kotest plugin from the marketplace • Attempted to use Kotest plugin to run the one test in debug. Result:
Copy code
Exception in thread "main" java.lang.ClassNotFoundException: BasicsTest
So maybe this is a Kotest plugin issue? As far as I can see the Gradle build triggered by the plugin doesn't compile the BasicsTest class, so it isn't on the classpath. Anyway I'm still experimenting. If you think this sounds more appropriate for posting in the kotest channel, lemme know...
r
Didn't really work with kotest, so not sure. First, I'd try to run tests using
./gradlew
via terminal to check whether the project can be built and tests can be run by Gradle -- so it this IDE-only issue or not. It's also probably more logical to move to either #kotest or #multiplatform depending on the outcome.
s
One ore note, the Kotest plugin uses the "shard" module classpath for this. If I open the Edit Run Configuration dialog for this test class, and drop down the "use classpath of module" list, shared.AndroidTest isn't an option. shared.androidMain is not either.
Ok just saw your reply. Will dig in some more and then post in Kotest. Thanks!
Haven't been able to work on this until recently. Took your advice Andrew (thanks!) and have also simplified the problem setup. Steps now are: • Create new mobile app with the EAP plugin from 1.4-M3 • Add one test into commonTest. Can be anything, I created this one guaranteed to fail if it runs:
Copy code
import kotlin.test.Test
    import kotlin.test.assertTrue
    
    class AnyTest {
        @Test
        fun failingTest() {
            assertTrue(false)
        }
    }
• Build project. This succeeds with the default gradle 6.3 and also 6.4.1. Fails on 6.5.1 so I left mine on 6.4.1, but 6.3 acts the same as 6.4.1 • Run check task. The project level "check", and the shared level "check" both fail with the same compile error:
Copy code
> Task :shared:compileReleaseJavaWithJavac

> Task :shared:compileReleaseUnitTestKotlinAndroid FAILED
e: D:\WorkingIntelliJ\untitled\shared\src\commonTest\kotlin\FooTest.kt: (1, 20): Unresolved reference: Test
e: D:\WorkingIntelliJ\untitled\shared\src\commonTest\kotlin\FooTest.kt: (2, 20): Unresolved reference: assertTrue
e: D:\WorkingIntelliJ\untitled\shared\src\commonTest\kotlin\FooTest.kt: (5, 6): Unresolved reference: Test
e: D:\WorkingIntelliJ\untitled\shared\src\commonTest\kotlin\FooTest.kt: (7, 9): Unresolved reference: assertTrue
So despite gradle being able to build the project ok, and the IDE showing the test source buildable with no problem, for some reason gradle isn't seeing the "kotlin.test" classes during the test tasks. It looks to me like the wizard generates the correct dependencies in the commonTest sourceset:
Copy code
val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
I'm unsure what can cause gradle to fail with a missing dependency running tests that it can compile/build just fine. Any suggestions where I should take this next?
More info, these test-specific build tasks also fail from the gradle console:
Copy code
:shared:compileDebugAndroidTestSources
    :shared:compileDebugUnitTestKotlinAndroid
I was forgetting that project builds don't build tests. Sorry. Anyway, somehow the test builds are not using the commonTest dependencies for source in the commonTest sourceset.
r
Does androidTest target have corresponding kotlin-test-junit (or something along those lines) dependency?
s
I left it exactly as the wizard generates it, so the current androidTest sourceSet in shared:build.gradle.kts is stubbed, just like the ios ones:
Copy code
val androidTest by getting
        val iosMain by getting
        val iosTest by getting
I've got a base git commit of this guinea pig project that is all the files from the wizard without changes, I'm going to just focus on getting the one bogus multiplatform test to run next, and will commit useful changes, if I find any. If I find useful changes, I'll do granular commits with comments on each until (hopefully) I get a successful run of the shared:test task.
I added this to the shared module's build.gradle.kts to dump out the task and its inputs.
Copy code
gradle.taskGraph.whenReady(closureOf<TaskExecutionGraph> {
    println("Found task graph: $this")
    println("Found " + allTasks.size + " tasks.")
    allTasks.forEach { task ->
        println(task)
        task.dependsOn.forEach { dep ->
            println("  - $dep")
        }
        task.inputs.files.forEach {
            println("Input - ${it.absolutePath}")
        }
    }
})
And running shard:test gradle task produced this for the failing subtask:
Copy code
task ':shared:compileDebugUnitTestKotlinAndroid'
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk7\1.4-M3\3d648cd3e9ac8cea2febc25dccd42fa2667fac75\kotlin-stdlib-jdk7-1.4-M3.jar
Input - C:\Users\skols\.gradle\caches\transforms-2\files-2.1\656cf8328a1f1d2fa1bdeb986a444437\core-ktx-1.2.0-api.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-test-common\1.4-M3\7b9619fe019c49b8d6991a348e9a84af7102e11b\kotlin-test-common-1.4-M3.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-test-annotations-common\1.4-M3\23cc8a186707afc74a144ad3acd1ec840a6d0490\kotlin-test-annotations-common-1.4-M3.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-android-extensions-runtime\1.4-M3\fba99da6f19ee1bf749fe1e32b26612ddd0bbca3\kotlin-android-extensions-runtime-1.4-M3.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.4-M3\d434fee0dcf45da74fbb897d7db3e24993e6be2c\kotlin-stdlib-1.4-M3.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.4-M3\9f0db946b8160929e99f26df2ae3e65356978141\kotlin-stdlib-common-1.4-M3.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar
Input - C:\Users\skols\.gradle\caches\transforms-2\files-2.1\61e1b3b81ccbb7a0671a1bba91af7b93\core-1.2.0-api.jar
Input - C:\Users\skols\.gradle\caches\transforms-2\files-2.1\bccb0d8a706b37d7233824b303cf1493\lifecycle-runtime-2.0.0-api.jar
Input - C:\Users\skols\.gradle\caches\transforms-2\files-2.1\b7c02a65a494426908f214e4c4207d13\versionedparcelable-1.1.0-api.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\androidx.lifecycle\lifecycle-common\2.0.0\e070ffae07452331bc5684734fce6831d531785c\lifecycle-common-2.0.0.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\androidx.arch.core\core-common\2.0.0\bb21b9a11761451b51624ac428d1f1bb5deeac38\core-common-2.0.0.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\androidx.collection\collection\1.0.0\42858b26cafdaa69b6149f45dfc2894007bc2c7a\collection-1.0.0.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\androidx.annotation\annotation\1.1.0\e3a6fb2f40e3a3842e6b7472628ba4ce416ea4c8\annotation-1.1.0.jar
Input - D:\WorkingIntelliJ\Mpp2\shared\build\intermediates\javac\debug\classes
Input - D:\WorkingIntelliJ\Mpp2\shared\build\tmp\kotlin-classes\debug
Input - D:\WorkingIntelliJ\Mpp2\shared\build\intermediates\compile_only_not_namespaced_r_class_jar\debug\R.jar
Input - D:\Android\sdk\platforms\android-29\android.jar
Input - D:\WorkingIntelliJ\Mpp2\shared\src\commonTest\kotlin\FooTest.kt
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-compiler-embeddable\1.4-M3\67dfdd73f5fdc275f857d9aab325bd205003fdd6\kotlin-compiler-embeddable-1.4-M3.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-reflect\1.4-M3\a00dc5d9fe4c80832afd33c61310e9ad69d7af16\kotlin-reflect-1.4-M3.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-script-runtime\1.4-M3\f41bf9bc6b35b83040eedcdd482651d2f843e12f\kotlin-script-runtime-1.4-M3.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-daemon-embeddable\1.4-M3\b214990d2189e8eb24f79b4564f834023f8f7192\kotlin-daemon-embeddable-1.4-M3.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\org.jetbrains.intellij.deps\trove4j\1.0.20181211\216c2e14b070f334479d800987affe4054cd563f\trove4j-1.0.20181211.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-scripting-compiler-embeddable\1.4-M3\4883c12980036982b3bf069c7fa4ab693befe237\kotlin-scripting-compiler-embeddable-1.4-M3.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-android-extensions\1.4-M3\fcb9dabe0c5e505d2fe2d147e0ed005db31a279f\kotlin-android-extensions-1.4-M3.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-scripting-compiler-impl-embeddable\1.4-M3\8b3469ce9d46ec8cc68e5ba1154b757df6527102\kotlin-scripting-compiler-impl-embeddable-1.4-M3.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-scripting-jvm\1.4-M3\766489c2c88ab457ccd7b246163b35baad8feb97\kotlin-scripting-jvm-1.4-M3.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-scripting-common\1.4-M3\b1e0404ba3ecbc27b5fab4a2a2008ba827405e21\kotlin-scripting-common-1.4-M3.jar
Input - C:\Users\skols\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlinx\kotlinx-coroutines-core\1.3.7\8e2eb78158638b33793d204ffef0b65c4a578e1c\kotlinx-coroutines-core-1.3.7.jar
Digging though all that shows kotlin-test-common-1.4-M3.jar and kotlin-test-annotations-common-1.4-M3.jar as inputs, which I thought were the jars that contain the missing stuff. Still trying to figure out what's wrong...
Ok one last bit of info, cuz I think I'm stuck after this 🙂. I looked in the kotlin-test-common jar in the gradle cache that are inputs to this compile, and at a high level (file names and folders only) compared them to the 1.3.72 version. They contain almost identical files, with the exception that the 1.3.72 version contains an org/junit/Test.kotlin_metadata file that is not in the 1.4-M3 version. I'm basically clueless about what kotlin_metadata stuff contains, so could easily be reading this wrong. But it's the only diff I can see, so don't know if this is related to the build error or not. Any ideas what I should try next?
I've been unable to determine the root cause, so opened an issue: https://youtrack.jetbrains.com/issue/KT-40571