Last active
April 24, 2020 12:31
-
-
Save kalaiselvan369/9efe62c1b34f70dabee96c3e0b4e00a2 to your computer and use it in GitHub Desktop.
Build gradle for MPP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
id 'org.jetbrains.kotlin.multiplatform' | |
} | |
apply plugin: 'com.android.library' | |
apply plugin: 'kotlin-android-extensions' | |
apply plugin: 'maven-publish' | |
// Because the components are created only during the afterEvaluate phase, you must | |
// configure your publications using the afterEvaluate() lifecycle method. | |
afterEvaluate { | |
publishing { | |
publications { | |
// Creates a Maven publication called "release". | |
release(MavenPublication) { | |
// Applies the component for the release build variant. | |
from components.release | |
// You can then customize attributes of the publication as shown below. | |
groupId = 'com.example.android.mars' | |
artifactId = 'shared' | |
version = '0.0.1' | |
} | |
// Creates a Maven publication called “debug”. | |
debug(MavenPublication) { | |
// Applies the component for the debug build variant. | |
from components.debug | |
groupId = 'com.example.android.mars' | |
artifactId = 'shared-debug' | |
version = '0.0.1' | |
} | |
} | |
} | |
} | |
android { | |
compileSdkVersion 29 | |
defaultConfig { | |
minSdkVersion 21 | |
targetSdkVersion 29 | |
versionCode 1 | |
versionName "1.0" | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | |
} | |
} | |
kotlin { | |
targets { | |
android("android") | |
// This is for iPhone emulator | |
// Switch here to iosArm64 (or iosArm32) to build library for iPhone device | |
// Select iOS target for real device or emulator. | |
final def iOSIsRealDevice = System.getenv('SDK_NAME')?.startsWith("iphoneos") | |
final def iOSTarget = iOSIsRealDevice ? presets.iosArm64 : presets.iosX64 | |
// iOS target. | |
fromPreset(iOSTarget, 'ios') { | |
binaries { framework('shared') } | |
} | |
} | |
sourceSets { | |
commonMain { | |
dependencies { | |
implementation kotlin('stdlib-common') | |
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.1.1" | |
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.20.0" | |
implementation "io.ktor:ktor-client-core:1.0.0" | |
} | |
} | |
commonTest { | |
dependencies { | |
implementation kotlin('test-common') | |
implementation kotlin('test-annotations-common') | |
} | |
} | |
androidMain { | |
dependencies { | |
implementation kotlin('stdlib') | |
} | |
} | |
androidTest { | |
dependencies { | |
implementation kotlin('test') | |
implementation kotlin('test-junit') | |
} | |
} | |
iosMain { | |
} | |
iosTest { | |
} | |
} | |
} | |
// This task attaches native framework built from ios module to Xcode project | |
// (see iosApp directory). Don't run this task directly, | |
// Xcode runs this task itself during its build process. | |
// Before opening the project from iosApp directory in Xcode, | |
// make sure all Gradle infrastructure exists (gradle.wrapper, gradlew). | |
// Task to generate iOS framework for xcode projects. | |
task packForXCode(type: Sync) { | |
final File frameworkDir = new File(buildDir, "xcode-frameworks") | |
final String mode = project.findProperty("XCODE_CONFIGURATION")?.toUpperCase() ?: 'DEBUG' | |
final def framework = kotlin.targets.ios.binaries.getFramework("shared", mode) | |
inputs.property "mode", mode | |
dependsOn framework.linkTask | |
from { framework.outputFile.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) | |
} | |
} | |
} | |
// Run packForXCode when building. | |
tasks.build.dependsOn packForXCode | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment