|
/* |
|
* Applying a plugin to a project allows the plugin to extend the project’s capabilities. It can do things such as: |
|
* Extend the Gradle model (e.g. add new DSL elements that can be configured) |
|
* Configure the project according to conventions (e.g. add new tasks or configure sensible defaults) |
|
* Apply specific configuration (e.g. add organizational repositories or enforce standards) |
|
*/ |
|
plugins { |
|
id("com.android.library") // To define a plugin we need to pass the group id and name |
|
kotlin("multiplatform") // Kotlin simply means we're using the `org.jetbrains.kotlin` group ID |
|
} |
|
|
|
/* |
|
* The kotlin extension, where we can define our targets and sourcesets for KMP |
|
* Docs: https://kotlinlang.org/docs/multiplatform-dsl-reference.html |
|
*/ |
|
kotlin { |
|
/* |
|
* Targets are what platforms or environments you want to build to |
|
* Docs: https://kotlinlang.org/docs/multiplatform-dsl-reference.html#targets |
|
*/ |
|
android() |
|
ios { |
|
binaries { // Configuring the binaries (https://kotlinlang.org/docs/multiplatform-dsl-reference.html#binaries) |
|
framework { // Configuring the Objective-C framework |
|
baseName = "shared" |
|
} |
|
} |
|
} |
|
|
|
/* |
|
* Source Sets are where we define dependencies for platform specific codebases |
|
* Includes their resources, dependencies, and language settings. |
|
* Docs: https://kotlinlang.org/docs/multiplatform-dsl-reference.html#source-sets |
|
*/ |
|
sourceSets { |
|
|
|
/* |
|
* One Method of defining a sourceset if it's source set is created outside of the build script |
|
* Docs: https://docs.gradle.org/current/userguide/kotlin_dsl.html#type-safe-accessors |
|
*/ |
|
commonMain { |
|
dependencies { |
|
} |
|
} |
|
/* |
|
* Another Method of defining a sourceset, a string based lookup |
|
*/ |
|
named("iosMain") { |
|
dependencies { |
|
/* |
|
* APIs are exported to consumers, that is to say found on their compile classpath. |
|
*/ |
|
api("androidx.appcompat:appcompat:1.6.1") |
|
/* |
|
* Implementations are only for this module, other modules implementing this module will not include this. |
|
*/ |
|
implementation(compose.preview) |
|
} |
|
} |
|
/* |
|
* Another Method of defining a sourceset, the preferred method. |
|
* Can be used to easily add as dependencies to other sourcesets |
|
*/ |
|
val androidMain by getting { |
|
dependencies { |
|
implementation(project(":other")) // Adding local module |
|
} |
|
} |
|
} |
|
} |
|
|
|
/** |
|
* The android block is where you configure all your Android-specific |
|
* build options. |
|
*/ |
|
android { |
|
/* |
|
* compileSdk specifies the Android API level Gradle should use to |
|
* compile your app. This means your app can use the API features included in |
|
* this API level and lower. |
|
*/ |
|
compileSdk = 33 |
|
|
|
/* |
|
* The defaultConfig block encapsulates default settings and entries for all |
|
* build variants and can override some attributes in main/AndroidManifest.xml |
|
* dynamically from the build system. You can configure product flavors to override |
|
* these values for different versions of your app. |
|
*/ |
|
defaultConfig { |
|
minSdk = 26 |
|
targetSdk = 33 |
|
} |
|
|
|
/* |
|
* Where you can define what versions of the JDK you want to use |
|
* Gradle Plugin Requires a minimum version of java, so can be defined here |
|
*/ |
|
compileOptions { |
|
/* |
|
* The Version we're using for building, |
|
* if you only have a certain type or want certain benefits of newer Java Versions |
|
*/ |
|
sourceCompatibility = JavaVersion.VERSION_11 |
|
/* |
|
* The version we're using for generating |
|
* by default equals a current Gradle's JDK version |
|
* Docs: https://kotlinlang.org/docs/gradle-configure-project.html#gradle-java-toolchains-support |
|
*/ |
|
targetCompatibility = JavaVersion.VERSION_11 |
|
} |
|
|
|
sourceSets { |
|
named("androidMain") { |
|
manifest.srcFile("src/androidMain/AndroidManifest.xml") |
|
res.srcDirs("src/androidMain/res") |
|
} |
|
} |
|
} |