# Android target in Kotlin MPP project

**URL:** <https://discuss.kotlinlang.org/t/android-target-in-kotlin-mpp-project/28062>\
**Category:** Multiplatform\
**Created:** [January 30, 2024, 3:18pm UTC](https://discuss.kotlinlang.org/t/android-target-in-kotlin-mpp-project/28062 "2024-01-30T15:18:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vk](https://avatars.discourse-cdn.com/v4/letter/v/cab0a1/32.png) [@vk](https://discuss.kotlinlang.org/u/vk)\
**Post date:** [January 30, 2024, 3:18pm UTC](https://discuss.kotlinlang.org/t/android-target-in-kotlin-mpp-project/28062/1 "2024-01-30T15:18:58Z")

</div>

Another day - another gradle\kotlin tooling glitch ☹ 😠

Kotlin MPP project - common, js, jvm and (_new_) **android** traget. **androidMain is not added as proper source root** in most recent Idea 2023.3.3, it does not have implicit dependency on commonMain. Again it is impossible to figure out what needs to be done to setup this type of project. Kotlin documentation does not have enough of details. Can anybody help please?

**Example project is attached.**  
[GradleMultiplatformWithAndroidTarget.zip](https://discuss.kotlinlang.org/uploads/short-url/2djyarZiyeeIPDgHG2gvU86Xsdd.zip) (5.6 KB)

```auto
plugins {
    id 'org.jetbrains.kotlin.multiplatform'
    id 'com.android.library'
    id 'maven-publish'
}

android {
    compileSdk 34
    namespace = "com.gradle_glitches"

    defaultConfig {
        //applicationId = "com.gradle_glitches"
        minSdk = 26
        targetSdk = 34
        versionCode = 1
        versionName = "1.0"
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlin {
        jvmToolchain(8)
    }
}

kotlin {
    def ENV = System.getenv()
    def ANDROID_HOME = ENV['ANDROID_HOME']

    androidTarget("main") {
    }

    sourceSets {
        androidMain {
            dependencies {
                //compileOnly files("C:/tools/android-sdk/platforms/android-34/android.jar")
                compileOnly files("$ANDROID_HOME/platforms/android-${android.compileSdk}/android.jar")
            }
        }
    }
}

```

 ![image](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/2/27d15f5001ab3244814139b05c06e606fcd778bb.png)

---

<div class="post-metadata">

**Author:** ![vk](https://avatars.discourse-cdn.com/v4/letter/v/cab0a1/32.png) [@vk](https://discuss.kotlinlang.org/u/vk)\
**Post date:** [January 30, 2024, 4:53pm UTC](https://discuss.kotlinlang.org/t/android-target-in-kotlin-mpp-project/28062/2 "2024-01-30T16:53:09Z")

</div>

> [@vk](#):
>
> `androidMain`

**Solved**. This does the trick:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/5/5a733f0b73b0360c656dc6ed0e112c282d04a3d3.png)

But androidMain should implicitly depend on commonMain, should not it?

And now I am getting a warning:

```auto
The Default Kotlin Hierarchy Template was not applied to 'project ':Core'':
Explicit .dependsOn() edges were configured for the following source sets:
[androidMain]

Consider removing dependsOn-calls or disabling the default template by adding
    'kotlin.mpp.applyDefaultHierarchyTemplate=false'
to your gradle.properties

```

**UPD** : Probably this is the reason

```auto
Kotlin doesn't currently support sharing a source set for these combinations:

* Several JVM targets
* JVM + Android targets

```

---

<div class="post-metadata">

**Author:** ![vk](https://avatars.discourse-cdn.com/v4/letter/v/cab0a1/32.png) [@vk](https://discuss.kotlinlang.org/u/vk)\
**Post date:** [January 30, 2024, 8:46pm UTC](https://discuss.kotlinlang.org/t/android-target-in-kotlin-mpp-project/28062/3 "2024-01-30T20:46:26Z")

</div>

No, it is unbereable. One blocker after another. Android classes are not linked, kotlin methods from standard library are not linked in Idea 2023.3.3. All this tooling is just AWFUL! Idea 2023.3.3 has one set of glitches, 2023.2.4 has another. Nothing works anywhere! 😡 Instead of doing work I am spending my time hitting head against walls(

Idea 2023.3.3:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/f/f2f19b2689e097b1f7cd2594bdddaa957545d196.png)

Idea 2023.2.4:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/b/b7a974cfb41e2f9334ad225a6251c3b909a7e986.png)

---

<div class="post-metadata">

**Author:** ![vk](https://avatars.discourse-cdn.com/v4/letter/v/cab0a1/32.png) [@vk](https://discuss.kotlinlang.org/u/vk)\
**Post date:** [January 31, 2024, 11:24am UTC](https://discuss.kotlinlang.org/t/android-target-in-kotlin-mpp-project/28062/4 "2024-01-31T11:24:47Z")

</div>

**UPD2** : It appears androidTarget works only in Android Studio
