Why I have syntax error in IDE after adding a gradle project to another repo even when the building works?

I have a kotlin multiplatform project A setup for iOS and Android, it works well. It has a common module for sharing business logic, and platform-android and platform-ios module for implementing the platform API.

After I adding the common and platform-android module from project A to another Android project B, the Android Studio IDE reports tons of syntax error, but the codes build and run from Android studio without a problem.

The syntax looks like the kotlin-stdlib is not there while it's indeed in the build.gradle, otherwise it won't build.

For instance:

val filterMap = mutableMapOf<String, MenuFilter>()

Android studio will say Unresolved reference: mutableMapOf

Some facts:

  • common module has the problem
  • no problem for platform-android.
  • and of course, no problem when I use IDEA to edit project A

my build.gradle for common module looks like this:

apply plugin: 'kotlin-platform-common'

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
    testCompile "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version"
    testCompile "org.jetbrains.kotlin:kotlin-test-common:$kotlin_version"
}

sourceSets {
    main.kotlin.srcDirs += 'main/'
    test.kotlin.srcDirs += 'test/'
}

task sourcesJar(type: Jar) {
    classifier = 'sources'
    from sourceSets.main.kotlin
}

artifacts {
    archives sourcesJar
}

kotlin {
    experimental {
        coroutines "enable"
    }
}

The rootProject build.gradle in Android Studio is:

buildscript {
    ext{
        kotlin_version = '1.2.41'
        anko_version = '0.10.4'
        dagger_version = '2.15'
        support_lib_version = '27.1.1'
    }

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

And this is the settings.gradle file for Android project B

def projectA_path = "path/to/projectA"

include(":common")
project(":common").projectDir = new File("$projectA_path/common")

include(":platforms:android")
project(":platforms:android").projectDir = new File("$projectA_path/platforms/android")

Even the two are from different projects, according to the setup here. Shouldn't the two just work? What am I missing here?

IDE version:

  • IDEA Ultimate 2018.1
  • Android studio 3.1.2