Skip to content

Commit

Permalink
fix ios build
Browse files Browse the repository at this point in the history
  • Loading branch information
luca992 committed Jun 12, 2024
1 parent 5c716ef commit 6dd1895
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 88 deletions.
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ kotlin.js.yarn=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
144 changes: 72 additions & 72 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ kotlin {
}
}

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


sourceSets {
Expand Down Expand Up @@ -220,66 +220,66 @@ multiplatformResources {
resourcesPackage = "io.michaelrocks.libphonenumber.sample"
}

// todo: Remove when resolved: https://github.com/icerockdev/moko-resources/issues/372
tasks.withType<KotlinNativeLink>()
.matching { linkTask -> linkTask.binary is AbstractExecutable }
.configureEach {
val task: KotlinNativeLink = this

doLast {
val binary: NativeBinary = task.binary
val outputDir: File = task.outputFile.get().parentFile
task.libraries
.filter { library -> library.extension == "klib" }
.filter(File::exists)
.forEach { inputFile ->
val klibKonan = KonanFile(inputFile.path)
val klib = KotlinLibraryLayoutImpl(
klib = klibKonan,
component = "default"
)
val layout = klib.extractingToTemp

// extracting bundles
layout
.resourcesDir
.absolutePath
.let(::File)
.listFiles(FileFilter { it.extension == "bundle" })
// copying bundles to app
?.forEach { bundleFile ->
logger.info("${bundleFile.absolutePath} copying to $outputDir")
bundleFile.copyRecursively(
target = File(outputDir, bundleFile.name),
overwrite = true
)
}
}
}
}

tasks.withType<AbstractNativeMacApplicationPackageAppDirTask> {
val task: AbstractNativeMacApplicationPackageAppDirTask = this

doLast {
val execFile: File = task.executable.get().asFile
val execDir: File = execFile.parentFile
val destDir: File = task.destinationDir.asFile.get()
val bundleID: String = task.bundleID.get()

val outputDir = File(destDir, "$bundleID.app/Contents/Resources")
outputDir.mkdirs()

execDir.listFiles().orEmpty()
.filter { it.extension == "bundle" }
.forEach { bundleFile ->
logger.info("${bundleFile.absolutePath} copying to $outputDir")
bundleFile.copyRecursively(
target = File(outputDir, bundleFile.name),
overwrite = true
)
}
}
}
//// todo: Remove when resolved: https://github.com/icerockdev/moko-resources/issues/372
//tasks.withType<KotlinNativeLink>()
// .matching { linkTask -> linkTask.binary is AbstractExecutable }
// .configureEach {
// val task: KotlinNativeLink = this
//
// doLast {
// val binary: NativeBinary = task.binary
// val outputDir: File = task.outputFile.get().parentFile
// task.libraries
// .filter { library -> library.extension == "klib" }
// .filter(File::exists)
// .forEach { inputFile ->
// val klibKonan = KonanFile(inputFile.path)
// val klib = KotlinLibraryLayoutImpl(
// klib = klibKonan,
// component = "default"
// )
// val layout = klib.extractingToTemp
//
// // extracting bundles
// layout
// .resourcesDir
// .absolutePath
// .let(::File)
// .listFiles(FileFilter { it.extension == "bundle" })
// // copying bundles to app
// ?.forEach { bundleFile ->
// logger.info("${bundleFile.absolutePath} copying to $outputDir")
// bundleFile.copyRecursively(
// target = File(outputDir, bundleFile.name),
// overwrite = true
// )
// }
// }
// }
// }
//
//tasks.withType<AbstractNativeMacApplicationPackageAppDirTask> {
// val task: AbstractNativeMacApplicationPackageAppDirTask = this
//
// doLast {
// val execFile: File = task.executable.get().asFile
// val execDir: File = execFile.parentFile
// val destDir: File = task.destinationDir.asFile.get()
// val bundleID: String = task.bundleID.get()
//
// val outputDir = File(destDir, "$bundleID.app/Contents/Resources")
// outputDir.mkdirs()
//
// execDir.listFiles().orEmpty()
// .filter { it.extension == "bundle" }
// .forEach { bundleFile ->
// logger.info("${bundleFile.absolutePath} copying to $outputDir")
// bundleFile.copyRecursively(
// target = File(outputDir, bundleFile.name),
// overwrite = true
// )
// }
// }
//}

apply(from = "$rootDir/gradle/pack-library-resources.gradle.kts")
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 = ''
spec.homepage = 'https://github.com/luca992/libphonenumber-kotlin'
spec.source = { :http=> ''}
spec.authors = ''
spec.license = ''
spec.summary = ''
spec.vendored_frameworks = 'build/cocoapods/framework/sample.framework'
spec.summary = 'Shared code for the sample'
spec.vendored_frameworks = 'build/cocoapods/framework/shared.framework'
spec.libraries = 'c++'
spec.ios.deployment_target = '14.1'



if !Dir.exist?('build/cocoapods/framework/sample.framework') || Dir.empty?('build/cocoapods/framework/sample.framework')
if !Dir.exist?('build/cocoapods/framework/shared.framework') || Dir.empty?('build/cocoapods/framework/shared.framework')
raise "
Kotlin framework 'sample' doesn't exist yet, so a proper Xcode project can't be generated.
Kotlin framework 'shared' 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' => 'sample',
'PRODUCT_MODULE_NAME' => 'shared',
}

spec.script_phases = [
Expand All @@ -50,5 +50,5 @@ Pod::Spec.new do |spec|
SCRIPT
}
]
spec.resources = ['build/compose/cocoapods/compose-resources']
spec.resources = ['src/commonMain/resources/**', 'src/iosMain/resources/**']
end
4 changes: 2 additions & 2 deletions sampleIosApp/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: "../sample"

SPEC CHECKSUMS:
sample: 36a5889d1393847f6f66fe1423cae26198af5f48
sample: a218637c7b6716e4ea8216201d423e252c5b5e9b

PODFILE CHECKSUM: 4522186d270471310130db42abc1984c8fbbfc8f

COCOAPODS: 1.12.1
COCOAPODS: 1.15.2
3 changes: 3 additions & 0 deletions sampleIosApp/Pods/Local Podspecs/sample.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions sampleIosApp/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions sampleIosApp/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

0 comments on commit 6dd1895

Please sign in to comment.