diff --git a/tutorials/mpp-iOS-Android/SharedCode/build.gradle b/tutorials/mpp-iOS-Android/SharedCode/build.gradle deleted file mode 100644 index a47ac149ff..0000000000 --- a/tutorials/mpp-iOS-Android/SharedCode/build.gradle +++ /dev/null @@ -1,50 +0,0 @@ -apply plugin: 'kotlin-multiplatform' - - -kotlin { - targets { - final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \ - ? presets.iosArm64 : presets.iosX64 - - fromPreset(iOSTarget, 'iOS') { - compilations.main.outputKinds('FRAMEWORK') - } - - fromPreset(presets.jvm, 'android') - } - - sourceSets { - commonMain.dependencies { - api 'org.jetbrains.kotlin:kotlin-stdlib-common' - } - - androidMain.dependencies { - api 'org.jetbrains.kotlin:kotlin-stdlib' - } - } -} - -// workaround for https://youtrack.jetbrains.com/issue/KT-27170 -configurations { - compileClasspath -} - -task packForXCode(type: Sync) { - final File frameworkDir = new File(buildDir, "xcode-frameworks") - final String mode = project.findProperty("XCODE_CONFIGURATION")?.toUpperCase() ?: 'DEBUG' - - inputs.property "mode", mode - dependsOn kotlin.targets.iOS.compilations.main.linkTaskName("FRAMEWORK", mode) - - from { kotlin.targets.iOS.compilations.main.getBinary("FRAMEWORK", mode).parentFile } - into frameworkDir - - doLast { - new File(frameworkDir, 'gradlew').with { - text = "#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$@\n" - setExecutable(true) - } - } -} - -tasks.build.dependsOn packForXCode diff --git a/tutorials/mpp-iOS-Android/SharedCode/build.gradle.kts b/tutorials/mpp-iOS-Android/SharedCode/build.gradle.kts new file mode 100644 index 0000000000..9ccc1823a9 --- /dev/null +++ b/tutorials/mpp-iOS-Android/SharedCode/build.gradle.kts @@ -0,0 +1,69 @@ +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget + +plugins { + kotlin("multiplatform") +} + +kotlin { + targets { + val iosTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget + + if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true) { + iosTarget = ::iosArm64 // Real device + } else { + iosTarget = ::iosX64 // iOS emulator + } + + iosTarget("iOS") { + binaries { + framework("SharedCode") + } + } + + jvm("android") + } + + sourceSets { + val commonMain by getting { + dependencies { + api("org.jetbrains.kotlin:kotlin-stdlib-common") + } + } + val androidMain by getting { + dependencies { + api("org.jetbrains.kotlin:kotlin-stdlib") + } + } + } +} + +// workaround for https://youtrack.jetbrains.com/issue/KT-27170 +configurations.create("compileClasspath") + +tasks.register("packForXCode") { + val frameworkDir = File(buildDir, "xcode-frameworks") + + val property = project.findProperty("XCODE_CONFIGURATION") as String? + val mode = property?.toUpperCase() ?: "DEBUG" + + val target = kotlin.targets.getByName("iOS") as KotlinNativeTarget + val framework = target.binaries.getFramework("SharedCode", mode) + + inputs.property("mode", mode) + dependsOn(framework.linkTask) + + from(framework.outputFile.parentFile) + into(frameworkDir) + + doLast { + val file = File(frameworkDir, "gradlew") + file.writeText(""" + #!/bin/bash + export 'JAVA_HOME=${System.getProperty("java.home")}' + cd '${rootProject.rootDir}' + ./gradlew $@ + """.trimIndent()) + file.setExecutable(true) + } +} +tasks.getByName("build").dependsOn("packForXCode") diff --git a/tutorials/mpp-iOS-Android/app/build.gradle b/tutorials/mpp-iOS-Android/app/build.gradle deleted file mode 100644 index 4a110acd0f..0000000000 --- a/tutorials/mpp-iOS-Android/app/build.gradle +++ /dev/null @@ -1,35 +0,0 @@ -apply plugin: 'com.android.application' - -apply plugin: 'kotlin-android' - -apply plugin: 'kotlin-android-extensions' - -android { - compileSdkVersion 28 - defaultConfig { - applicationId "com.jetbrains.jonnyzzz.myapplication" - minSdkVersion 15 - targetSdkVersion 28 - versionCode 1 - versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } -} - -dependencies { - implementation project(':SharedCode') - - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'com.android.support:appcompat-v7:28.0.0' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' -} diff --git a/tutorials/mpp-iOS-Android/app/build.gradle.kts b/tutorials/mpp-iOS-Android/app/build.gradle.kts new file mode 100644 index 0000000000..db85cb2144 --- /dev/null +++ b/tutorials/mpp-iOS-Android/app/build.gradle.kts @@ -0,0 +1,34 @@ +plugins { + id("com.android.application") + id("kotlin-android") + id("kotlin-android-extensions") +} + +android { + compileSdkVersion(27) + defaultConfig { + applicationId = "com.zuehlke.nativepopcorn" + minSdkVersion(15) + targetSdkVersion(27) + versionCode = 1 + versionName = "1.0" + testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + getByName("release") { + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } +} + +dependencies { + implementation(fileTree(mapOf("dir" to "libs", "include" to "*.jar"))) + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlin}") + implementation("com.android.support:appcompat-v7:27.1.1") + implementation("com.android.support.constraint:constraint-layout:1.1.3") + implementation(project(":SharedCode")) + testImplementation("junit:junit:4.12") + androidTestImplementation("com.android.support.test:runner:1.0.2") + androidTestImplementation("com.android.support.test.espresso:espresso-core:3.0.2") +} diff --git a/tutorials/mpp-iOS-Android/build.gradle b/tutorials/mpp-iOS-Android/build.gradle.kts similarity index 53% rename from tutorials/mpp-iOS-Android/build.gradle rename to tutorials/mpp-iOS-Android/build.gradle.kts index 7901e7eb9d..f6b111d3e5 100644 --- a/tutorials/mpp-iOS-Android/build.gradle +++ b/tutorials/mpp-iOS-Android/build.gradle.kts @@ -1,16 +1,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.0-rc-190' repositories { google() jcenter() - maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } + } dependencies { - classpath 'com.android.tools.build:gradle:3.2.0' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - + classpath("com.android.tools.build:gradle:3.3.2") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}") // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } @@ -20,10 +18,10 @@ allprojects { repositories { google() jcenter() - maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } + } } -task clean(type: Delete) { - delete rootProject.buildDir +tasks.register("clean") { + delete(rootProject.buildDir) } diff --git a/tutorials/mpp-iOS-Android/buildSrc/build.gradle.kts b/tutorials/mpp-iOS-Android/buildSrc/build.gradle.kts new file mode 100644 index 0000000000..2d9272e47e --- /dev/null +++ b/tutorials/mpp-iOS-Android/buildSrc/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + `kotlin-dsl` +} + +repositories { + // The org.jetbrains.kotlin.jvm plugin requires a repository + // where to download the Kotlin compiler dependencies from. + jcenter() +} diff --git a/tutorials/mpp-iOS-Android/buildSrc/src/main/kotlin/Versions.kt b/tutorials/mpp-iOS-Android/buildSrc/src/main/kotlin/Versions.kt new file mode 100644 index 0000000000..ce0f1acd58 --- /dev/null +++ b/tutorials/mpp-iOS-Android/buildSrc/src/main/kotlin/Versions.kt @@ -0,0 +1,3 @@ +object Versions { + const val kotlin = "1.3.30" +} diff --git a/tutorials/mpp-iOS-Android/settings.gradle b/tutorials/mpp-iOS-Android/settings.gradle deleted file mode 100644 index 720e6cbfaf..0000000000 --- a/tutorials/mpp-iOS-Android/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -include ':app' -include ':SharedCode' diff --git a/tutorials/mpp-iOS-Android/settings.gradle.kts b/tutorials/mpp-iOS-Android/settings.gradle.kts new file mode 100644 index 0000000000..83c1675de9 --- /dev/null +++ b/tutorials/mpp-iOS-Android/settings.gradle.kts @@ -0,0 +1,2 @@ +include(":app") +include(":SharedCode") \ No newline at end of file