diff --git a/README.md b/README.md index 7b39e2c..f3bb736 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,21 @@ sdk.dir=/your/path/to/android/sdk In this template there is only one subproject with name `lib`. You are always able to rename it, but remember that in this case you must rename it in `settings.gradle` file. +## JVM sources in Android target + +By default JVM code is not included in Android target. In case you wish to include JVM sources in Android build, use +next method in the end of your `build.gradle`: + +```groovy +enableIncludingJvmCodeInAndroidPart() +``` + +In case when you need to be sure that JVM sources are not included in Android part, use this snippet: + +```groovy +disableIncludingJvmCodeInAndroidPart() +``` + ## Types of projects ### `mppProjectWithSerialization` diff --git a/defaultAndroidSettings.gradle b/defaultAndroidSettings.gradle index 65b9e07..1b1a4f0 100644 --- a/defaultAndroidSettings.gradle +++ b/defaultAndroidSettings.gradle @@ -1,6 +1,31 @@ apply plugin: 'com.getkeepsafe.dexcount' android { + ext { + jvmKotlinFolderFile = { + String sep = File.separator + return new File("${project.projectDir}${sep}src${sep}jvmMain${sep}kotlin") + } + + enableIncludingJvmCodeInAndroidPart = { + File jvmKotlinFolder = jvmKotlinFolderFile() + if (jvmKotlinFolder.exists()) { + android.sourceSets.main.java.srcDirs += jvmKotlinFolder.path + } + } + + disableIncludingJvmCodeInAndroidPart = { + File jvmKotlinFolder = jvmKotlinFolderFile() + String[] oldDirs = android.sourceSets.main.java.srcDirs + android.sourceSets.main.java.srcDirs = [] + for (oldDir in oldDirs) { + if (oldDir != jvmKotlinFolder.path) { + android.sourceSets.main.java.srcDirs += oldDir + } + } + } + } + compileSdkVersion "$android_compileSdkVersion".toInteger() buildToolsVersion "$android_buildToolsVersion" diff --git a/gradle.properties b/gradle.properties index efb729c..899b6c8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,8 +6,8 @@ kotlin.incremental.js=true android.useAndroidX=true android.enableJetifier=true -kotlin_version=1.4.32 -kotlin_serialisation_core_version=1.1.0 +kotlin_version=1.5.0 +kotlin_serialisation_core_version=1.2.0 # github_release_plugin_version=2.2.12