Add support for android MPP
#KT-18462 Fixed
This commit is contained in:
+32
@@ -1,5 +1,6 @@
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.gradle.util.VersionNumber
|
||||
import org.jetbrains.kotlin.gradle.util.getFileByName
|
||||
import org.jetbrains.kotlin.gradle.util.getFilesByNames
|
||||
import org.jetbrains.kotlin.gradle.util.isLegacyAndroidGradleVersion
|
||||
@@ -258,6 +259,37 @@ fun getSomething() = 10
|
||||
assertNotContains("Changed dependencies of configuration .+ after it has been included in dependency resolution".toRegex())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMultiplatformAndroidCompile() {
|
||||
val project = Project("multiplatformAndroidProject", gradleVersion)
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
assertContains(
|
||||
":lib:compileKotlinCommon",
|
||||
":lib:compileTestKotlinCommon",
|
||||
":libJvm:compileKotlin",
|
||||
":libJvm:compileTestKotlin",
|
||||
":libAndroid:compileDebugKotlin",
|
||||
":libAndroid:compileReleaseKotlin",
|
||||
":libAndroid:compileDebugUnitTestKotlin",
|
||||
":libAndroid:compileReleaseUnitTestKotlin"
|
||||
)
|
||||
|
||||
val kotlinFolder = if (VersionNumber.parse(gradleVersion).major > 3) "kotlin" else ""
|
||||
|
||||
assertFileExists("lib/build/classes/$kotlinFolder/main/foo/PlatformClass.kotlin_metadata")
|
||||
assertFileExists("lib/build/classes/$kotlinFolder/test/foo/PlatformTest.kotlin_metadata")
|
||||
assertFileExists("libJvm/build/classes/$kotlinFolder/main/foo/PlatformClass.class")
|
||||
assertFileExists("libJvm/build/classes/$kotlinFolder/test/foo/PlatformTest.class")
|
||||
|
||||
assertFileExists("libAndroid/build/tmp/kotlin-classes/debug/foo/PlatformClass.class")
|
||||
assertFileExists("libAndroid/build/tmp/kotlin-classes/release/foo/PlatformClass.class")
|
||||
assertFileExists("libAndroid/build/tmp/kotlin-classes/debugUnitTest/foo/PlatformTest.class")
|
||||
assertFileExists("libAndroid/build/tmp/kotlin-classes/debugUnitTest/foo/PlatformTest.class")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
maven { url 'https://maven.google.com' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "com.android.tools.build:gradle:$android_tools_version"
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
maven { url 'https://maven.google.com' }
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
apply plugin: 'kotlin-platform-common'
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package foo
|
||||
|
||||
expect class PlatformClass {
|
||||
val value: String
|
||||
}
|
||||
|
||||
class CommonClass
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package foo
|
||||
|
||||
expect class PlatformTest {
|
||||
val value: PlatformClass
|
||||
}
|
||||
|
||||
class CommonTest(val commonClass: CommonClass)
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-platform-android'
|
||||
|
||||
dependencies {
|
||||
expectedBy project(":lib")
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 23
|
||||
buildToolsVersion "25.0.2"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 23
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="platform.kotlin.android.test"
|
||||
>
|
||||
|
||||
<uses-sdk android:minSdkVersion="19" />
|
||||
|
||||
<application/>
|
||||
|
||||
</manifest>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package foo
|
||||
|
||||
actual class PlatformClass {
|
||||
actual val value: String = "Android"
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package platform.kotlin.android.test
|
||||
|
||||
class MyActivity: android.app.Activity()
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package foo
|
||||
|
||||
actual class PlatformTest {
|
||||
actual val value: PlatformClass = PlatformClass()
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
apply plugin: 'kotlin-platform-jvm'
|
||||
|
||||
dependencies {
|
||||
expectedBy project(":lib")
|
||||
compile 'com.google.guava:guava:20.0'
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package foo
|
||||
|
||||
actual class PlatformClass {
|
||||
actual val value: String = "JVM"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package foo
|
||||
|
||||
import com.google.common.collect.ImmutableSet
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val colors = ImmutableSet.of("red", "orange", "yellow")
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package foo
|
||||
|
||||
actual class PlatformTest {
|
||||
actual val value: PlatformClass = PlatformClass()
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
include ':lib', ':libJvm', ':libAndroid'
|
||||
+17
-2
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.plugin
|
||||
|
||||
import com.android.build.gradle.BaseExtension
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
@@ -114,12 +115,12 @@ open class KotlinPlatformImplementationPluginBase(platformName: String) : Kotlin
|
||||
|
||||
commonProject.sourceSets.all { commonSourceSet ->
|
||||
// todo: warn if not found
|
||||
addCommonSourceSetToPlatformSourceSet(commonSourceSet)
|
||||
addCommonSourceSetToPlatformSourceSet(commonSourceSet, platformProject)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun addCommonSourceSetToPlatformSourceSet(commonSourceSet: SourceSet) {
|
||||
protected open fun addCommonSourceSetToPlatformSourceSet(commonSourceSet: SourceSet, platformProject: Project) {
|
||||
val platformTask = platformKotlinTasksBySourceSetName[commonSourceSet.name]
|
||||
commonSourceSet.kotlin!!.srcDirs.forEach { platformTask?.source(it) }
|
||||
}
|
||||
@@ -147,6 +148,20 @@ open class KotlinPlatformImplementationPluginBase(platformName: String) : Kotlin
|
||||
}
|
||||
}
|
||||
|
||||
open class KotlinPlatformAndroidPlugin : KotlinPlatformImplementationPluginBase("android") {
|
||||
override fun apply(project: Project) {
|
||||
project.applyPlugin<KotlinAndroidPluginWrapper>()
|
||||
super.apply(project)
|
||||
}
|
||||
|
||||
override fun addCommonSourceSetToPlatformSourceSet(commonSourceSet: SourceSet, platformProject: Project) {
|
||||
val androidExtension = platformProject.extensions.getByName("android") as BaseExtension
|
||||
val androidSourceSet = androidExtension.sourceSets.findByName(commonSourceSet.name) ?: return
|
||||
val kotlinSourceSet = androidSourceSet.getConvention(KOTLIN_DSL_NAME) as? KotlinSourceSet ?: return
|
||||
kotlinSourceSet.kotlin.source(commonSourceSet.kotlin!!)
|
||||
}
|
||||
}
|
||||
|
||||
open class KotlinPlatformJvmPlugin : KotlinPlatformImplementationPluginBase("jvm") {
|
||||
override fun apply(project: Project) {
|
||||
project.applyPlugin<KotlinPluginWrapper>()
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
implementation-class=org.jetbrains.kotlin.gradle.plugin.KotlinPlatformAndroidPlugin
|
||||
+1
@@ -0,0 +1 @@
|
||||
implementation-class=org.jetbrains.kotlin.gradle.plugin.KotlinPlatformAndroidPlugin
|
||||
Reference in New Issue
Block a user