From 7949fcd7ed9644d6df430cf72dbb8bbc58a7a593 Mon Sep 17 00:00:00 2001 From: shabinder Date: Fri, 30 Apr 2021 01:44:51 +0530 Subject: [PATCH] IOS project WIP --- .../PlatformActions.kt | 4 + .../ActualIos.kt | 2 +- common/dependency-injection/build.gradle.kts | 7 +- .../dependency_injection.podspec | 6 +- .../com/shabinder/common/di/AndroidDir.kt | 5 +- .../com.shabinder.common.di/IOSActual.kt | 19 ----- .../kotlin/com.shabinder.common.di/IOSDir.kt | 17 +++- common/root/build.gradle.kts | 85 +++++++++++++++++++ common/root/root.podspec | 46 ++++++++++ desktop/src/jvmMain/kotlin/Main.kt | 10 +-- gradle.properties | 1 + 11 files changed, 165 insertions(+), 37 deletions(-) create mode 100644 common/data-models/src/iosMain/kotlin/com.shabinder.common.models/PlatformActions.kt create mode 100644 common/root/root.podspec diff --git a/common/data-models/src/iosMain/kotlin/com.shabinder.common.models/PlatformActions.kt b/common/data-models/src/iosMain/kotlin/com.shabinder.common.models/PlatformActions.kt new file mode 100644 index 00000000..02c6ce65 --- /dev/null +++ b/common/data-models/src/iosMain/kotlin/com.shabinder.common.models/PlatformActions.kt @@ -0,0 +1,4 @@ +package com.shabinder.common.models + +actual interface PlatformActions { +} \ No newline at end of file diff --git a/common/database/src/iosMain/kotlin/com.shabinder.common.database/ActualIos.kt b/common/database/src/iosMain/kotlin/com.shabinder.common.database/ActualIos.kt index ac9df1b8..793b7915 100644 --- a/common/database/src/iosMain/kotlin/com.shabinder.common.database/ActualIos.kt +++ b/common/database/src/iosMain/kotlin/com.shabinder.common.database/ActualIos.kt @@ -7,7 +7,7 @@ import org.koin.dsl.module import com.squareup.sqldelight.drivers.native.NativeSqliteDriver @Suppress("RedundantNullableReturnType") -actual fun databaseModule(): Module { +actual fun databaseModule() = module { single { val driver = NativeSqliteDriver(Database.Schema, "Database.db") SpotiFlyerDatabase(Database(driver)) diff --git a/common/dependency-injection/build.gradle.kts b/common/dependency-injection/build.gradle.kts index 12e848bb..5bb7dbc8 100644 --- a/common/dependency-injection/build.gradle.kts +++ b/common/dependency-injection/build.gradle.kts @@ -29,18 +29,19 @@ kotlin { cocoapods { // Configure fields required by CocoaPods. - summary = "SpotiFlyer Native Module" + summary = "SpotiFlyer-DI Native Module" homepage = "https://github.com/Shabinder/SpotiFlyer" authors = "Shabinder Singh" // You can change the name of the produced framework. // By default, it is the name of the Gradle project. - frameworkName = "SpotiFlyer" - ios.deploymentTarget = "13.5" + frameworkName = "SpotiFlyer-DI" + ios.deploymentTarget = "9.0" // Dependencies pod("TagLibIOS") { version = "~> 0.3" } + //podfile = project.file("spotiflyer-ios/Podfile") } sourceSets { diff --git a/common/dependency-injection/dependency_injection.podspec b/common/dependency-injection/dependency_injection.podspec index d0aca3ea..254930a8 100644 --- a/common/dependency-injection/dependency_injection.podspec +++ b/common/dependency-injection/dependency_injection.podspec @@ -5,14 +5,14 @@ Pod::Spec.new do |spec| spec.source = { :git => "Not Published", :tag => "Cocoapods/#{spec.name}/#{spec.version}" } spec.authors = 'Shabinder Singh' spec.license = '' - spec.summary = 'SpotiFlyer Native Module' + spec.summary = 'SpotiFlyer-DI Native Module' spec.static_framework = true - spec.vendored_frameworks = "build/cocoapods/framework/SpotiFlyer.framework" + spec.vendored_frameworks = "build/cocoapods/framework/SpotiFlyer-DI.framework" spec.libraries = "c++" spec.module_name = "#{spec.name}_umbrella" - spec.ios.deployment_target = '13.5' + spec.ios.deployment_target = '9.0' spec.dependency 'TagLibIOS', '~> 0.3' diff --git a/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidDir.kt b/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidDir.kt index 1e0299d9..3d032de0 100644 --- a/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidDir.kt +++ b/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidDir.kt @@ -27,7 +27,10 @@ import com.shabinder.common.database.SpotiFlyerDatabase import com.shabinder.common.models.TrackDetails import com.shabinder.common.models.methods import com.shabinder.database.Database -import kotlinx.coroutines.* +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import java.io.File import java.io.FileOutputStream import java.io.IOException diff --git a/common/dependency-injection/src/iosMain/kotlin/com.shabinder.common.di/IOSActual.kt b/common/dependency-injection/src/iosMain/kotlin/com.shabinder.common.di/IOSActual.kt index 3b108d83..c0d60d50 100644 --- a/common/dependency-injection/src/iosMain/kotlin/com.shabinder.common.di/IOSActual.kt +++ b/common/dependency-injection/src/iosMain/kotlin/com.shabinder.common.di/IOSActual.kt @@ -1,25 +1,6 @@ package com.shabinder.common.di -import com.shabinder.common.models.AllPlatforms import com.shabinder.common.models.TrackDetails -import kotlinx.coroutines.CoroutineDispatcher -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.runBlocking - -actual fun queryActiveTracks() {} - -actual fun openPlatform(packageID: String, platformLink: String) {} - -actual fun shareApp() {} - -actual fun giveDonation() {} - -actual val dispatcherIO: CoroutineDispatcher = Dispatchers.Default - -actual val isInternetAvailable: Boolean - get() = runBlocking { isInternetAccessible() } - -actual val currentPlatform: AllPlatforms = AllPlatforms.Native actual suspend fun downloadTracks( list: List, diff --git a/common/dependency-injection/src/iosMain/kotlin/com.shabinder.common.di/IOSDir.kt b/common/dependency-injection/src/iosMain/kotlin/com.shabinder.common.di/IOSDir.kt index f5b51de6..11ae4877 100644 --- a/common/dependency-injection/src/iosMain/kotlin/com.shabinder.common.di/IOSDir.kt +++ b/common/dependency-injection/src/iosMain/kotlin/com.shabinder.common.di/IOSDir.kt @@ -1,14 +1,25 @@ package com.shabinder.common.di import co.touchlab.kermit.Kermit +import cocoapods.TagLibIOS.TLAudio +import com.shabinder.common.database.SpotiFlyerDatabase import com.shabinder.common.models.TrackDetails import com.shabinder.database.Database import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch -import platform.Foundation.* +import platform.Foundation.NSCachesDirectory +import platform.Foundation.NSDirectoryEnumerationSkipsHiddenFiles +import platform.Foundation.NSFileManager +import platform.Foundation.NSMusicDirectory +import platform.Foundation.NSURL +import platform.Foundation.NSURLConnection +import platform.Foundation.NSURLRequest +import platform.Foundation.NSUserDomainMask +import platform.Foundation.URLByAppendingPathComponent +import platform.Foundation.sendSynchronousRequest +import platform.Foundation.writeToFile import platform.UIKit.UIImage import platform.UIKit.UIImageJPEGRepresentation -import cocoapods.TagLibIOS.TLAudio actual class Dir actual constructor( private val logger: Kermit, @@ -87,7 +98,7 @@ actual class Dir actual constructor( private suspend fun loadFreshImage(url: String):UIImage? { return try { - val nsURL = NSURL(url) + val nsURL = NSURL(string = url) val data = NSURLConnection.sendSynchronousRequest(NSURLRequest.requestWithURL(nsURL),null,null) if (data != null) { UIImage.imageWithData(data)?.also { diff --git a/common/root/build.gradle.kts b/common/root/build.gradle.kts index 08c8f86c..e2dad363 100644 --- a/common/root/build.gradle.kts +++ b/common/root/build.gradle.kts @@ -18,9 +18,69 @@ plugins { id("multiplatform-setup") id("android-setup") id("kotlin-parcelize") + //kotlin("native.cocoapods") } +// Required be cocoapods +version = "1.0" + kotlin { + + /*IOS Target Can be only built on Mac*/ + if(HostOS.isMac){ + val sdkName: String? = System.getenv("SDK_NAME") + val isiOSDevice = sdkName.orEmpty().startsWith("iphoneos") + if (isiOSDevice) { + iosArm64("ios"){ + binaries { + framework { + baseName = "SpotiFlyer" + linkerOpts.add("-lsqlite3") + export(project(":common:database")) + export(project(":common:main")) + export(project(":common:list")) + export(project(":common:dependency-injection")) + export(project(":common:data-models")) + export(Decompose.decompose) + export(MVIKotlin.mvikotlin) + } + } + } + } else { + iosX64("ios"){ + binaries { + framework { + baseName = "SpotiFlyer" + linkerOpts.add("-lsqlite3") + export(project(":common:database")) + export(project(":common:main")) + export(project(":common:list")) + export(project(":common:dependency-injection")) + export(project(":common:data-models")) + export(Decompose.decompose) + export(MVIKotlin.mvikotlin) + } + } + } + } + } + + /*cocoapods { + // Configure fields required by CocoaPods. + summary = "SpotiFlyer Native Module" + homepage = "https://github.com/Shabinder/SpotiFlyer" + authors = "Shabinder Singh" + // You can change the name of the produced framework. + // By default, it is the name of the Gradle project. + frameworkName = "SpotiFlyer" + ios.deploymentTarget = "11.0" + + *//*pod("dependency_injection"){ + version = "1.0" + source = path(rootProject.file("common/dependency-injection")) + }*//* + }*/ + sourceSets { commonMain { dependencies { @@ -36,4 +96,29 @@ kotlin { } } } + sourceSets { + named("iosMain") { + dependencies { + api(project(":common:dependency-injection")) + api(project(":common:data-models")) + api(project(":common:database")) + api(project(":common:list")) + api(project(":common:main")) + api(Decompose.decompose) + api(MVIKotlin.mvikotlin) + } + } + } +} + +val packForXcode by tasks.creating(Sync::class) { + group = "build" + val mode = System.getenv("CONFIGURATION") ?: "DEBUG" + val targetName = "ios" + val framework = kotlin.targets.getByName(targetName).binaries.getFramework(mode) + inputs.property("mode", mode) + dependsOn(framework.linkTask) + val targetDir = File(buildDir, "xcode-frameworks") + from(framework.outputDirectory) + into(targetDir) } diff --git a/common/root/root.podspec b/common/root/root.podspec new file mode 100644 index 00000000..b0e61668 --- /dev/null +++ b/common/root/root.podspec @@ -0,0 +1,46 @@ +Pod::Spec.new do |spec| + spec.name = 'root' + spec.version = '1.0' + spec.homepage = 'https://github.com/Shabinder/SpotiFlyer' + spec.source = { :git => "Not Published", :tag => "Cocoapods/#{spec.name}/#{spec.version}" } + spec.authors = 'Shabinder Singh' + spec.license = '' + spec.summary = 'SpotiFlyer Native Module' + + spec.static_framework = true + spec.vendored_frameworks = "build/cocoapods/framework/SpotiFlyer.framework" + spec.libraries = "c++" + spec.module_name = "#{spec.name}_umbrella" + + spec.ios.deployment_target = '11.0' + + + + spec.pod_target_xcconfig = { + 'KOTLIN_TARGET[sdk=iphonesimulator*]' => 'ios_x64', + 'KOTLIN_TARGET[sdk=iphoneos*]' => 'ios_arm', + 'KOTLIN_TARGET[sdk=watchsimulator*]' => 'watchos_x64', + 'KOTLIN_TARGET[sdk=watchos*]' => 'watchos_arm', + 'KOTLIN_TARGET[sdk=appletvsimulator*]' => 'tvos_x64', + 'KOTLIN_TARGET[sdk=appletvos*]' => 'tvos_arm64', + 'KOTLIN_TARGET[sdk=macosx*]' => 'macos_x64' + } + + spec.script_phases = [ + { + :name => 'Build root', + :execution_position => :before_compile, + :shell_path => '/bin/sh', + :script => <<-SCRIPT + set -ev + REPO_ROOT="$PODS_TARGET_SRCROOT" + "$REPO_ROOT/../../gradlew" -p "$REPO_ROOT" :common:root:syncFramework \ + -Pkotlin.native.cocoapods.target=$KOTLIN_TARGET \ + -Pkotlin.native.cocoapods.configuration=$CONFIGURATION \ + -Pkotlin.native.cocoapods.cflags="$OTHER_CFLAGS" \ + -Pkotlin.native.cocoapods.paths.headers="$HEADER_SEARCH_PATHS" \ + -Pkotlin.native.cocoapods.paths.frameworks="$FRAMEWORK_SEARCH_PATHS" + SCRIPT + } + ] +end \ No newline at end of file diff --git a/desktop/src/jvmMain/kotlin/Main.kt b/desktop/src/jvmMain/kotlin/Main.kt index 8715ccf9..a8e2dc64 100644 --- a/desktop/src/jvmMain/kotlin/Main.kt +++ b/desktop/src/jvmMain/kotlin/Main.kt @@ -42,8 +42,7 @@ import com.shabinder.common.uikit.colorOffWhite import com.shabinder.common.uikit.showToast import com.shabinder.database.Database import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking private val koin = initKoin(enableNetworkLogs = true).koin @@ -96,11 +95,8 @@ private fun spotiFlyerRoot(componentContext: ComponentContext): SpotiFlyerRoot = override val dispatcherIO = Dispatchers.IO override val isInternetAvailable: Boolean - get() { - var result = false - val job = GlobalScope.launch { result = isInternetAccessible() } - while (job.isActive) {/*TODO Better Way*/} - return result + get() = runBlocking { + isInternetAccessible() } override val currentPlatform = AllPlatforms.Jvm diff --git a/gradle.properties b/gradle.properties index 6a034150..8eb88350 100644 --- a/gradle.properties +++ b/gradle.properties @@ -41,4 +41,5 @@ kotlin.native.disableCompilerDaemon=true kotlin.mpp.stability.nowarn=true kotlin.mpp.enableGranularSourceSetsMetadata=true kotlin.native.enableDependencyPropagation=false +kotlin.native.cacheKind=none #org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8