Share
Embed
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.
Transcript
46 slides
-
@bennegeek Mobi Rem Cruz Mobi Cristiano Madeira Mobi JB Lorenzo
UX Prod Hero Karen Banzon Mana ger Ayelen Chavez Mana ger Caio Moritz -
@bennegeek Mobi Rem Cruz Mobi Cristiano Madeira Mobi JB Lorenzo
UX Prod Hero Karen Banzon Mana ger Ayelen Chavez Mana ger Caio Moritz * 3 devs * 2 managers * 1 ux/prod * /w real work * ~1 month deadline -
@bennegeek Outline: - Why? - How? (to Setup* (updated)) -
How? (to link Flutter and Kotlin) - What? (pitfalls, considerations) -
@bennegeek android \-- app \-- build.gradle \-- build.gradle \-- settings.gradle
common a \-- build.gradle ios \-- Runner.xcodeproj lib -
@bennegeek android \-- app \-- build.gradle \-- build.gradle \-- settings.gradle
common a \-- build.gradle ios \-- Runner.xcodeproj lib -
@bennegeek // settings.gradle include ':app a ' def flutterProjectRoot =
rootProject.projectDir.parentFile.toPath() def plugins = new Properties() def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') if (pluginsFile.exists()) { pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } } include ':common' plugins.each { name, path -> def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() include ":$name" project(":$name").projectDir = pluginDirectory } project(":common").projectDir = new File(“../common”) enableFeaturePreview('GRADLE_METADATA') -
@bennegeek // settings.gradle include ':app a ' def flutterProjectRoot =
rootProject.projectDir.parentFile.toPath() def plugins = new Properties() def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') if (pluginsFile.exists()) { pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } } include ':common' plugins.each { name, path -> def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() include ":$name" project(":$name").projectDir = pluginDirectory } project(":common").projectDir = new File(“../common”) enableFeaturePreview('GRADLE_METADATA') -
@bennegeek // settings.gradle include ':app a ' def flutterProjectRoot =
rootProject.projectDir.parentFile.toPath() def plugins = new Properties() def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') if (pluginsFile.exists()) { pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } } include ':common' plugins.each { name, path -> def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() include ":$name" project(":$name").projectDir = pluginDirectory } project(":common").projectDir = new File(“../common”) enableFeaturePreview('GRADLE_METADATA') -
@bennegeek // settings.gradle include ':app a ' def flutterProjectRoot =
rootProject.projectDir.parentFile.toPath() def plugins = new Properties() def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') if (pluginsFile.exists()) { pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } } include ':common' plugins.each { name, path -> def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() include ":$name" project(":$name").projectDir = pluginDirectory } project(":common").projectDir = new File(“../common”) enableFeaturePreview('GRADLE_METADATA') -
@bennegeek // settings.gradle include ':app a ' def flutterProjectRoot =
rootProject.projectDir.parentFile.toPath() def plugins = new Properties() def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') if (pluginsFile.exists()) { pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } } include ':common' plugins.each { name, path -> def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() include ":$name" project(":$name").projectDir = pluginDirectory } project(":common").projectDir = new File(“../common”) enableFeaturePreview('GRADLE_METADATA') -
@bennegeek android \-- app \-- build.gradle \-- build.gradle \-- settings.gradle
common a \-- build.gradle ios \-- Runner.xcodeproj lib -
@bennegeek android \-- app \-- build.gradle \-- build.gradle \-- settings.gradle
common a \-- build.gradle ios \-- Runner.xcodeproj lib -
@bennegeek // build.gradle buildscript { ext.kotlin_version = '1.3.0' repositories {
google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.3.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } // ... -
@bennegeek // build.gradle buildscript { ext.kotlin_version = '1.3.0' repositories {
google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.3.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } // ... -
@bennegeek // build.gradle buildscript { ext.kotlin_version = '1.3.0' repositories {
google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.3.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } // ... -
@bennegeek android \-- app \-- build.gradle \-- build.gradle \-- settings.gradle
common a \-- build.gradle ios \-- Runner.xcodeproj lib -
@bennegeek android \-- app \-- build.gradle \-- build.gradle \-- settings.gradle
common a \-- build.gradle ios \-- Runner.xcodeproj lib -
@bennegeek android \-- app \-- build.gradle \-- build.gradle \-- settings.gradle
common a \-- build.gradle ios \-- Runner.xcodeproj lib -
@bennegeek android 1 \-- app \-- build.gradle \-- build.gradle \--
settings.gradle common \-- build.gradle ios \-- Runner.xcodeproj lib -
@bennegeek // common / build.gradle 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' ¹ } } } // … task packForXCode(type: Sync) { finala File frameworkDir =aa new File(buildDir, "xcode-frameworks")a finala String mode =a 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 =a "#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$@\n" setExecutable(true) } } } tasks.build.dependsOn packForXCode ¹ Dissecting Stdlib https://www.youtube.com/watch?v=Fzt_9I733Yg -
@bennegeek // common / a build.gradle 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' } } } // ... task packForXCode(type: Sync) { final a File frameworkDir = aa new File(buildDir, "xcode-frameworks") a final a String mode = a 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 = a "#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '$ {rootProject.rootDir}'\n./gradlew \$@\n" setExecutable(true) } } } tasks.build.dependsOn packForXCode -
@bennegeek android 1 \-- app \-- build.gradle 1 \-- build.gradle
1 \-- settings.gradle common \-- build.gradle ios \-- Runner.xcodeproj lib -
@bennegeek android 1 \-- app \-- build.gradle 1 \-- build.gradle
1 \-- settings.gradle common \-- build.gradle ios \-- Runner.xcodeproj lib -
@bennegeek # Runner.xcodeproj # Build Phase cd \”$SRCROOT/../common/build/xcode-frameworks\”\n ./gradlew :common:packForXCode
-PXCODE_CONFIGURATION=${CONFIGURATION} -
@bennegeek # Runner.xcodeproj # Build Phase cd \”$SRCROOT/../common/build/xcode-frameworks\”\n ./gradlew :common:packForXCode
-PXCODE_CONFIGURATION=${CONFIGURATION} -
@bennegeek Now we've setup - android/settings.gradle - android/build.gradle - ios/Runner.xcodeproj
- common/build.gradle - framework in iOS Kotlin/Native -
@bennegeek Android // MainActivity.kt import common.doSomethingWith GeneratedPluginRegistrant.registerWith(this) MethodChannel(flutterView, CHANNEL).setMethodCallHandler {
call, result -> when (call.method) { "methodName" -> doSomethingWith(result) } } -
@bennegeek iOS // AppDelegate.swift import YourFrameworkName // from Kotlin-Native //
... let channel = FlutterMethodChannel.init(name: "/channel", binaryMessenger: controller) channel.setMethodCallHandler({(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in // Process call.method and result }); GeneratedPluginRegistrant.register(with: self) -
@bennegeek * Serializing and Deserializing * Companion in Swift *
arm32 * No Bitcode * Hot reload * JVM libraries Pitfalls -
@bennegeek Takeaways * Flutter is awesome for fast prototypes *
You can replace Flutter with other cross platform UI frameworks while keeping your logic code in Kotlin/Native * Kotlin/Native are still in beta but is usable already though with some limitations * Kotlin/Native works well to reduce the amount of platform specific code * Some glue code needs to be written to pass around/ serialize objects * Don’t be afraid to try out new technologies (but …)