From 54176697575d4e1a76874c4d83864930c4edc10a Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Mon, 2 Dec 2024 05:38:10 -0500 Subject: [PATCH] fix android. cleanup. --- .gitignore | 4 +--- libphonenumber/build.gradle.kts | 18 ++---------------- .../metadata/source/AssetsMetadataLoader.kt | 11 ++++++++--- .../MultiFileModeResourceProvider.android.kt | 9 --------- .../libphonenumber/kotlin/MetadataLoader.kt | 2 +- 5 files changed, 12 insertions(+), 32 deletions(-) delete mode 100644 libphonenumber/src/androidMain/kotlin/io/michaelrocks/libphonenumber/kotlin/metadata/source/MultiFileModeResourceProvider.android.kt diff --git a/.gitignore b/.gitignore index 297dd851..b377fd5d 100644 --- a/.gitignore +++ b/.gitignore @@ -158,6 +158,4 @@ lint/tmp/ .DS_Store .kotlin -# moko-resources-generated -moko-resources-generated.js -pack-library-resources-generated.js + diff --git a/libphonenumber/build.gradle.kts b/libphonenumber/build.gradle.kts index 02b6fd69..0039971c 100644 --- a/libphonenumber/build.gradle.kts +++ b/libphonenumber/build.gradle.kts @@ -39,8 +39,7 @@ kotlin { } val commonTest by getting { dependencies { - // need to make a separate module to import the resources because moko resources doesn't commonTest - // resources yet: https://github.com/icerockdev/moko-resources/issues/193 + // todo: move test resources to commonTest implementation(project(":library-test-resources")) implementation(kotlin("test")) } @@ -89,6 +88,7 @@ kotlin { compose.resources { publicResClass = true + generateResClass = always } android { @@ -123,23 +123,9 @@ android { } } -// https://youtrack.jetbrains.com/issue/KT-46466 -val dependsOnTasks = mutableListOf() -tasks.withType().configureEach { - dependsOnTasks.add(this.name.replace("publish", "sign").replaceAfter("Publication", "")) - dependsOn(dependsOnTasks) -} - plugins.withId("com.vanniktech.maven.publish") { mavenPublishing { publishToMavenCentral(SonatypeHost.S01) signAllPublications() } -} - -//apply(from = "$rootDir/gradle/pack-library-test-resources.gradle.kts") - -compose.resources { - publicResClass = true - generateResClass = always } \ No newline at end of file diff --git a/libphonenumber/src/androidMain/kotlin/io/michaelrocks/libphonenumber/kotlin/metadata/source/AssetsMetadataLoader.kt b/libphonenumber/src/androidMain/kotlin/io/michaelrocks/libphonenumber/kotlin/metadata/source/AssetsMetadataLoader.kt index c45c3111..1e3160e6 100644 --- a/libphonenumber/src/androidMain/kotlin/io/michaelrocks/libphonenumber/kotlin/metadata/source/AssetsMetadataLoader.kt +++ b/libphonenumber/src/androidMain/kotlin/io/michaelrocks/libphonenumber/kotlin/metadata/source/AssetsMetadataLoader.kt @@ -16,16 +16,21 @@ package io.michaelrocks.libphonenumber.kotlin.metadata.source; import android.content.res.AssetManager -import dev.icerock.moko.resources.AssetResource +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.JavaInputStream +import kotlinx.coroutines.runBlocking import okio.IOException class AssetsMetadataLoader(private val assetManager: AssetManager) : MetadataLoader { - override fun loadMetadata(phoneMetadataResource: AssetResource): InputStream? { + override fun loadMetadata(phoneMetadataResource: String): InputStream? { return try { - assetManager.open(phoneMetadataResource.path) + val path = Res.getUri(phoneMetadataResource).removePrefix("file:///android_asset/") + println(path) + JavaInputStream(assetManager.open(path)) } catch (exception: IOException) { + exception.printStackTrace() null } as InputStream? } diff --git a/libphonenumber/src/androidMain/kotlin/io/michaelrocks/libphonenumber/kotlin/metadata/source/MultiFileModeResourceProvider.android.kt b/libphonenumber/src/androidMain/kotlin/io/michaelrocks/libphonenumber/kotlin/metadata/source/MultiFileModeResourceProvider.android.kt deleted file mode 100644 index ec43d2b9..00000000 --- a/libphonenumber/src/androidMain/kotlin/io/michaelrocks/libphonenumber/kotlin/metadata/source/MultiFileModeResourceProvider.android.kt +++ /dev/null @@ -1,9 +0,0 @@ -package io.michaelrocks.libphonenumber.kotlin.metadata.source - -import dev.icerock.moko.resources.AssetResource -import dev.icerock.moko.resources.ResourceContainer -import dev.icerock.moko.resources.getAssetByFilePath - -actual fun ResourceContainer.getAssetByFilePath( - filePath: String -): AssetResource? = getAssetByFilePath(filePath) \ No newline at end of file diff --git a/libphonenumber/src/commonMain/kotlin/io/michaelrocks/libphonenumber/kotlin/MetadataLoader.kt b/libphonenumber/src/commonMain/kotlin/io/michaelrocks/libphonenumber/kotlin/MetadataLoader.kt index 44b6cd41..371e9afb 100644 --- a/libphonenumber/src/commonMain/kotlin/io/michaelrocks/libphonenumber/kotlin/MetadataLoader.kt +++ b/libphonenumber/src/commonMain/kotlin/io/michaelrocks/libphonenumber/kotlin/MetadataLoader.kt @@ -31,7 +31,7 @@ interface MetadataLoader { * Returns an input stream corresponding to the metadata to load. This method may be called * concurrently so implementations must be thread-safe. * - * @param phoneMetadataResource the moko resources AssetResource to load + * @param phoneMetadataResourceUri the path relative to the composeResources directory * @return the input stream for the metadata file. The library will close this stream * after it is done. Return null in case the metadata file could not be found */