Skip to content

Commit

Permalink
fix ios build and getting bundled resources
Browse files Browse the repository at this point in the history
  • Loading branch information
luca992 committed Dec 2, 2024
1 parent 4d05e0a commit 541240e
Show file tree
Hide file tree
Showing 37 changed files with 48 additions and 1,130 deletions.
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ ksp.incremental=false
org.jetbrains.compose.experimental.jscanvas.enabled=true
org.jetbrains.compose.experimental.macos.enabled=true
org.jetbrains.compose.experimental.uikit.enabled=true
compose.ios.resources.sync=false

# Publishing : Required
GROUP=io.github.luca992.libphonenumber-kotlin
Expand Down
7 changes: 6 additions & 1 deletion libphonenumber/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,9 @@ plugins.withId("com.vanniktech.maven.publish") {
}
}

apply(from = "$rootDir/gradle/pack-library-test-resources.gradle.kts")
//apply(from = "$rootDir/gradle/pack-library-test-resources.gradle.kts")

compose.resources {
publicResClass = true
generateResClass = always
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MultiFileModeResourceProvider(
}

override fun getFor(key: Any): String? {
println("MultiFileModeResourceProvider.getFor key: $key")
val keyAsString = key.toString()
require(ALPHANUMERIC.matchEntire(keyAsString) != null) { "Invalid key: $keyAsString" }
val path = phoneMetadataFileNamePrefix + keyAsString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SingleFileModeResourceProvider(
private val phoneMetadataFileName: String
) : PhoneMetadataResourceProvider {
override fun getFor(key: Any): String? {
println("SingleFileModeResourceProvider.getFor key: $key")
return Res.getUri("files/$phoneMetadataFileName")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
package io.michaelrocks.libphonenumber.kotlin.metadata.init

import co.touchlab.kermit.Logger
import io.github.luca992.libphonenumber_kotlin.libphonenumber.generated.resources.Res
import io.michaelrocks.libphonenumber.kotlin.MetadataLoader
import io.michaelrocks.libphonenumber.kotlin.io.InputStream
import io.michaelrocks.libphonenumber.kotlin.io.OkioInputStream
import okio.FileSystem
import okio.Path.Companion.toPath
import okio.buffer
import org.jetbrains.compose.resources.MissingResourceException
import platform.Foundation.*
import platform.Foundation.NSBundle
import platform.Foundation.NSFileManager

/**
* A [MetadataLoader] implementation that reads phone number metadata files as classpath
Expand All @@ -33,11 +35,10 @@ import platform.Foundation.*
class ComposeResourceMetadataLoader : MetadataLoader {
override fun loadMetadata(phoneMetadataResource: String): InputStream? {
return try {
val path = getPathOnDisk(phoneMetadataResource).toPath()
println("getPathOnDisk:$path")
OkioInputStream(FileSystem.SYSTEM.source(path).buffer())
val path = Res.getUri(phoneMetadataResource).removePrefix("file://")
OkioInputStream(FileSystem.SYSTEM.source(path.toPath()).buffer())
} catch (t: Throwable) {
logger.v("Failed to load metadata from $phoneMetadataResource.path", t)
logger.v("Failed to load metadata from $phoneMetadataResource", t)
null
}
}
Expand Down
40 changes: 15 additions & 25 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.compose.desktop.application.tasks.AbstractNativeMacApplicationPackageAppDirTask
import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractExecutable
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBinary
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl
import java.io.File
import java.io.FileFilter
import org.jetbrains.kotlin.konan.file.File as KonanFile

plugins {
alias(libs.plugins.org.jetbrains.kotlin.multiplatform)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.org.jetbrains.compose)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.com.android.application)
kotlin("native.cocoapods")
}

version = "1.0-SNAPSHOT"
Expand All @@ -33,23 +24,19 @@ kotlin {
macosTargets {
binaries.executable()
}
iosX64()
iosArm64()
iosSimulatorArm64()
applyDefaultHierarchyTemplate()

cocoapods {
summary = "Shared code for the sample"
homepage = "https://github.com/luca992/libphonenumber-kotlin"
ios.deploymentTarget = "14.1"
podfile = project.file("../sampleIosApp/Podfile")
framework {
fun iosTargets(config: KotlinNativeTarget.() -> Unit) {
iosX64(config)
iosArm64(config)
iosSimulatorArm64(config)
}
iosTargets {
binaries.framework {
baseName = "shared"
isStatic = true
}
extraSpecAttributes["resources"] = "['src/commonMain/resources/**', 'src/iosMain/resources/**']"
}

applyDefaultHierarchyTemplate()

sourceSets {
val commonMain by getting {
Expand All @@ -58,6 +45,7 @@ kotlin {
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.runtime)
implementation(compose.components.resources)
api(project(":libphonenumber"))
}
}
Expand Down Expand Up @@ -114,7 +102,7 @@ android {

defaultConfig {
minSdk = 24
targetSdk = 34
targetSdk = 35
}

compileOptions {
Expand All @@ -135,5 +123,7 @@ android {
}
}


apply(from = "$rootDir/gradle/pack-library-resources.gradle.kts")
compose.resources {
publicResClass = true
generateResClass = always
}
16 changes: 8 additions & 8 deletions sample/sample.podspec
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
Pod::Spec.new do |spec|
spec.name = 'sample'
spec.version = '1.0-SNAPSHOT'
spec.homepage = 'https://github.com/luca992/libphonenumber-kotlin'
spec.homepage = ''
spec.source = { :http=> ''}
spec.authors = ''
spec.license = ''
spec.summary = 'Shared code for the sample'
spec.vendored_frameworks = 'build/cocoapods/framework/shared.framework'
spec.summary = ''
spec.vendored_frameworks = 'build/cocoapods/framework/sample.framework'
spec.libraries = 'c++'
spec.ios.deployment_target = '14.1'


if !Dir.exist?('build/cocoapods/framework/shared.framework') || Dir.empty?('build/cocoapods/framework/shared.framework')

if !Dir.exist?('build/cocoapods/framework/sample.framework') || Dir.empty?('build/cocoapods/framework/sample.framework')
raise "
Kotlin framework 'shared' doesn't exist yet, so a proper Xcode project can't be generated.
Kotlin framework 'sample' 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:generateDummyFramework
Expand All @@ -28,7 +28,7 @@ Pod::Spec.new do |spec|

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

spec.script_phases = [
Expand All @@ -50,5 +50,5 @@ Pod::Spec.new do |spec|
SCRIPT
}
]
spec.resources = ['src/commonMain/resources/**', 'src/iosMain/resources/**']
end
5 changes: 0 additions & 5 deletions sampleIosApp/Podfile

This file was deleted.

16 changes: 0 additions & 16 deletions sampleIosApp/Podfile.lock

This file was deleted.

35 changes: 0 additions & 35 deletions sampleIosApp/Pods/Local Podspecs/sample.podspec.json

This file was deleted.

16 changes: 0 additions & 16 deletions sampleIosApp/Pods/Manifest.lock

This file was deleted.

Loading

0 comments on commit 541240e

Please sign in to comment.