Skip to content

Commit

Permalink
Upgrade to Kotlin 2.0.0, add Compose compiler (#121)
Browse files Browse the repository at this point in the history
* feature: Migrate to kotlin 2.0.0 & Compose compiler

* Sync podspec

* Fix build errors

* Fix building iOS sample app

* Add `pod install`

* Add `./gradlew :sample:composeApp:generateDummyFramework`

---------

Co-authored-by: Raph <[email protected]>
Co-authored-by: Alex Shepeliev <[email protected]>
  • Loading branch information
3 people authored Jul 9, 2024
1 parent c7bf42f commit 0ae6d01
Show file tree
Hide file tree
Showing 15 changed files with 196 additions and 73 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build-sample-app-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ jobs:

- name: Build sample app
run: |
cd sample/iosApp
xcodebuild -configuration Debug -scheme iosApp -sdk iphonesimulator -arch arm64
./gradlew :sample:composeApp:generateDummyFramework
cd sample/iosApp
pod install
xcodebuild -workspace iosApp.xcworkspace -configuration Debug -scheme iosApp -sdk iphonesimulator -arch arm64
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ captures
xcuserdata
.externalNativeBuild
.cxx
.kotlin/
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
kotlin = "1.9.23"
kotlin = "2.0.0"
kotlin-coroutines = "1.8.0"
androidx-activity-compose = "1.9.0"
androidx-appcompat = "1.6.1"
Expand All @@ -26,7 +26,7 @@ targetSdk = "34"
agp = "8.2.2"
ktlint = "10.3.0"
nexus = "1.3.0"
compose-plugin = "1.6.2"
compose-plugin = "1.6.11"

[libraries]
webrtc-sdk = { module = "io.github.webrtc-sdk:android", version.ref = "webrtc-android-sdk" }
Expand Down Expand Up @@ -60,3 +60,4 @@ agp-plugin = { module = "com.android.tools.build:gradle", version.ref = "agp" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
nexus = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexus" }
jetbrains-compose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
1 change: 1 addition & 0 deletions sample/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ xcuserdata
!*.xcodeproj/project.xcworkspace/
!*.xcworkspace/contents.xcworkspacedata
**/xcshareddata/WorkspaceSettings.xcsettings
Pods/
12 changes: 12 additions & 0 deletions sample/composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType


plugins {
kotlin("multiplatform")
id("com.android.application")
kotlin("native.cocoapods")

alias(libs.plugins.jetbrains.compose)
alias(libs.plugins.compose.compiler)
}

kotlin {
Expand All @@ -24,6 +27,15 @@ kotlin {
moduleName = "WebRTC"
packageName = "WebRTC"
}

podfile = project.file("../iosApp/Podfile")

framework {
baseName = "ComposeApp"
}

xcodeConfigurationToNativeBuildType["CUSTOM_DEBUG"] = NativeBuildType.DEBUG
xcodeConfigurationToNativeBuildType["CUSTOM_RELEASE"] = NativeBuildType.RELEASE
}

androidTarget {
Expand Down
16 changes: 10 additions & 6 deletions sample/composeApp/composeApp.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,29 @@ Pod::Spec.new do |spec|
spec.authors = ''
spec.license = ''
spec.summary = 'Compose app'
spec.vendored_frameworks = 'build/cocoapods/framework/composeApp.framework'
spec.vendored_frameworks = 'build/cocoapods/framework/ComposeApp.framework'
spec.libraries = 'c++'
spec.ios.deployment_target = '13.0'
spec.ios.deployment_target = '13.0'
spec.dependency 'WebRTC-SDK', '125.6422.02'

if !Dir.exist?('build/cocoapods/framework/composeApp.framework') || Dir.empty?('build/cocoapods/framework/composeApp.framework')
if !Dir.exist?('build/cocoapods/framework/ComposeApp.framework') || Dir.empty?('build/cocoapods/framework/ComposeApp.framework')
raise "
Kotlin framework 'composeApp' doesn't exist yet, so a proper Xcode project can't be generated.
Kotlin framework 'ComposeApp' doesn't exist yet, so a proper Xcode project can't be generated.
'pod install' should be executed after running ':generateDummyFramework' Gradle task:
./gradlew :sample:composeApp:generateDummyFramework
Alternatively, proper pod installation is performed during Gradle sync in the IDE (if Podfile location is set)"
end

spec.xcconfig = {
'ENABLE_USER_SCRIPT_SANDBOXING' => 'NO',
}

spec.pod_target_xcconfig = {
'KOTLIN_PROJECT_PATH' => ':sample:composeApp',
'PRODUCT_MODULE_NAME' => 'composeApp',
'PRODUCT_MODULE_NAME' => 'ComposeApp',
}

spec.script_phases = [
Expand All @@ -46,5 +50,5 @@ Pod::Spec.new do |spec|
SCRIPT
}
]
spec.resources = ['build/compose/ios/composeApp/compose-resources']
spec.resources = ['build/compose/cocoapods/compose-resources']
end
47 changes: 26 additions & 21 deletions sample/composeApp/src/commonMain/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ fun App() {
MaterialTheme {
val scope = rememberCoroutineScope()
val (localStream, setLocalStream) = remember { mutableStateOf<MediaStream?>(null) }
val (remoteVideoTrack, setRemoteVideoTrack) = remember { mutableStateOf<VideoStreamTrack?>(null) }
val (remoteAudioTrack, setRemoteAudioTrack) = remember { mutableStateOf<AudioStreamTrack?>(null) }
val (remoteVideoTrack, setRemoteVideoTrack) = remember {
mutableStateOf<VideoStreamTrack?>(
null
)
}
val (remoteAudioTrack, setRemoteAudioTrack) = remember {
mutableStateOf<AudioStreamTrack?>(
null
)
}
val (peerConnections, setPeerConnections) = remember {
mutableStateOf<Pair<PeerConnection, PeerConnection>?>(null)
}
Expand Down Expand Up @@ -69,27 +77,24 @@ fun App() {
setLocalStream(stream)
}
})
} else {
StopButton(
onClick = {
hangup(peerConnections)
localStream.release()
setLocalStream(null)
setPeerConnections(null)
setRemoteVideoTrack(null)
setRemoteAudioTrack(null)
}
)

return@MaterialTheme
SwitchCameraButton(
onClick = {
scope.launch { localStream.videoTracks.firstOrNull()?.switchCamera() }
}
)
}

StopButton(
onClick = {
hangup(peerConnections)
localStream.release()
setLocalStream(null)
setPeerConnections(null)
setRemoteVideoTrack(null)
setRemoteAudioTrack(null)
}
)

SwitchCameraButton(
onClick = {
scope.launch { localStream.videoTracks.firstOrNull()?.switchCamera() }
}
)

if (peerConnections == null) {
CallButton(
onClick = { setPeerConnections(Pair(PeerConnection(), PeerConnection())) },
Expand Down
10 changes: 10 additions & 0 deletions sample/iosApp/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Uncomment the next line to define a global platform for your project
platform :ios, '13.0'

target 'iosApp' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!

# Pods for iosApp
pod 'composeApp', :path => '../composeApp'
end
23 changes: 23 additions & 0 deletions sample/iosApp/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
PODS:
- composeApp (1.0):
- WebRTC-SDK (= 125.6422.02)
- WebRTC-SDK (125.6422.02)

DEPENDENCIES:
- composeApp (from `../composeApp`)

SPEC REPOS:
trunk:
- WebRTC-SDK

EXTERNAL SOURCES:
composeApp:
:path: "../composeApp"

SPEC CHECKSUMS:
composeApp: b5af1c46ec9d310a2934e8ca55a13d300d59368c
WebRTC-SDK: 5319b8964f453c5ea6030d93c345082c4f40aa1c

PODFILE CHECKSUM: 93cb910915abe7895a05e1dca8ba57520db8947f

COCOAPODS: 1.15.2
Loading

0 comments on commit 0ae6d01

Please sign in to comment.