-
-
Notifications
You must be signed in to change notification settings - Fork 166
Added firebase-installations #257
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/* | ||
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget | ||
import org.jetbrains.kotlin.konan.target.KonanTarget | ||
|
||
version = project.property("firebase-installations.version") as String | ||
|
||
plugins { | ||
id("com.android.library") | ||
kotlin("multiplatform") | ||
} | ||
|
||
android { | ||
compileSdk = property("targetSdkVersion") as Int | ||
defaultConfig { | ||
minSdk = property("minSdkVersion") as Int | ||
targetSdk = property("targetSdkVersion") as Int | ||
} | ||
sourceSets { | ||
getByName("main") { | ||
manifest.srcFile("src/androidMain/AndroidManifest.xml") | ||
} | ||
} | ||
testOptions { | ||
unitTests.apply { | ||
isIncludeAndroidResources = true | ||
} | ||
} | ||
packagingOptions { | ||
resources.pickFirsts.add("META-INF/kotlinx-serialization-core.kotlin_module") | ||
resources.pickFirsts.add("META-INF/AL2.0") | ||
resources.pickFirsts.add("META-INF/LGPL2.1") | ||
} | ||
lint { | ||
isAbortOnError = false | ||
} | ||
} | ||
|
||
val KonanTarget.archVariant: String | ||
get() = if (this is KonanTarget.IOS_X64 || this is KonanTarget.IOS_SIMULATOR_ARM64) { | ||
"ios-arm64_i386_x86_64-simulator" | ||
} else { | ||
"ios-arm64_armv7" | ||
} | ||
|
||
kotlin { | ||
|
||
android { | ||
publishAllLibraryVariants() | ||
} | ||
|
||
val supportIosTarget = project.property("skipIosTarget") != "true" | ||
if (supportIosTarget) { | ||
fun nativeTargetConfig(): KotlinNativeTarget.() -> Unit = { | ||
val nativeFrameworkPaths = listOf( | ||
rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/iOS") | ||
).plus( | ||
listOf( | ||
"FirebaseAnalytics", | ||
"FirebaseCore", | ||
"FirebaseCoreDiagnostics", | ||
"FirebaseInstallations", | ||
"GoogleAppMeasurement", | ||
"GoogleAppMeasurementIdentitySupport", | ||
"GoogleDataTransport", | ||
"GoogleUtilities", | ||
"nanopb", | ||
"PromisesObjC" | ||
).map { | ||
rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/${konanTarget.archVariant}") | ||
} | ||
) | ||
|
||
binaries { | ||
getTest("DEBUG").apply { | ||
linkerOpts(nativeFrameworkPaths.map { "-F$it" }) | ||
linkerOpts("-ObjC") | ||
} | ||
} | ||
|
||
compilations.getByName("main") { | ||
cinterops.create("FirebaseInstallations") { | ||
compilerOpts(nativeFrameworkPaths.map { "-F$it" }) | ||
extraOpts = listOf("-compiler-option", "-DNS_FORMAT_ARGUMENT(A)=", "-verbose") | ||
} | ||
} | ||
} | ||
|
||
ios(configure = nativeTargetConfig()) | ||
iosSimulatorArm64(configure = nativeTargetConfig()) | ||
} | ||
|
||
js { | ||
useCommonJs() | ||
nodejs { | ||
testTask { | ||
useMocha { | ||
timeout = "5s" | ||
} | ||
} | ||
} | ||
browser { | ||
testTask { | ||
useMocha { | ||
timeout = "5s" | ||
} | ||
} | ||
} | ||
} | ||
|
||
sourceSets { | ||
all { | ||
languageSettings.apply { | ||
apiVersion = "1.5" | ||
languageVersion = "1.5" | ||
progressiveMode = true | ||
// optIn("kotlinx.coroutines.ExperimentalCoroutinesApi") | ||
// optIn("kotlinx.serialization.InternalSerializationApi") | ||
} | ||
} | ||
|
||
val commonMain by getting { | ||
dependencies { | ||
api(project(":firebase-app")) | ||
implementation(project(":firebase-common")) | ||
} | ||
} | ||
|
||
val androidMain by getting { | ||
dependencies { | ||
api("com.google.firebase:firebase-installations") | ||
} | ||
} | ||
|
||
if (supportIosTarget) { | ||
val iosMain by getting | ||
val iosSimulatorArm64Main by getting | ||
iosSimulatorArm64Main.dependsOn(iosMain) | ||
|
||
val iosTest by sourceSets.getting | ||
val iosSimulatorArm64Test by sourceSets.getting | ||
iosSimulatorArm64Test.dependsOn(iosTest) | ||
} | ||
|
||
val jsMain by getting | ||
} | ||
} | ||
|
||
if (project.property("firebase-installations.skipIosTests") == "true") { | ||
tasks.forEach { | ||
if (it.name.contains("ios", true) && it.name.contains("test", true)) { it.enabled = false } | ||
} | ||
} | ||
|
||
signing { | ||
val signingKey: String? by project | ||
val signingPassword: String? by project | ||
useInMemoryPgpKeys(signingKey, signingPassword) | ||
sign(publishing.publications) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "@gitlive/firebase-installations", | ||
"version": "1.0.0", | ||
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects", | ||
"main": "firebase-installations.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/GitLiveApp/firebase-kotlin-sdk.git" | ||
}, | ||
"keywords": [ | ||
"kotlin", | ||
"multiplatform", | ||
"kotlin-js", | ||
"firebase" | ||
], | ||
"author": "dev.gitlive", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/GitLiveApp/firebase-kotlin-sdk/issues" | ||
}, | ||
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk", | ||
"dependencies": { | ||
"@gitlive/firebase-app": "1.4.3", | ||
"firebase": "9.4.1", | ||
"kotlin": "1.5.31", | ||
"kotlinx-coroutines-core": "1.5.2" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<manifest package="dev.gitlive.firebase.installations"/> |
23 changes: 23 additions & 0 deletions
23
...-installations/src/androidMain/kotlin/dev/gitlive/firebase/installations/installations.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package dev.gitlive.firebase.installations | ||
|
||
import dev.gitlive.firebase.Firebase | ||
import dev.gitlive.firebase.FirebaseApp | ||
import kotlinx.coroutines.tasks.await | ||
|
||
actual val Firebase.installations | ||
get() = FirebaseInstallations(com.google.firebase.installations.FirebaseInstallations.getInstance()) | ||
|
||
actual fun Firebase.installations(app: FirebaseApp) | ||
= FirebaseInstallations(com.google.firebase.installations.FirebaseInstallations.getInstance(app.android)) | ||
|
||
actual class FirebaseInstallations internal constructor(val android: com.google.firebase.installations.FirebaseInstallations) { | ||
|
||
actual suspend fun delete() = android.delete().await().let { } | ||
|
||
actual suspend fun getId(): String = android.id.await() | ||
|
||
actual suspend fun getToken(forceRefresh: Boolean): String = | ||
android.getToken(forceRefresh).await().token | ||
} | ||
|
||
actual typealias FirebaseInstallationsException = com.google.firebase.installations.FirebaseInstallationsException |
20 changes: 20 additions & 0 deletions
20
...e-installations/src/commonMain/kotlin/dev/gitlive/firebase/installations/installations.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package dev.gitlive.firebase.installations | ||
|
||
import dev.gitlive.firebase.Firebase | ||
import dev.gitlive.firebase.FirebaseApp | ||
import dev.gitlive.firebase.FirebaseException | ||
import kotlinx.serialization.DeserializationStrategy | ||
import kotlinx.serialization.SerializationStrategy | ||
|
||
expect val Firebase.installations: FirebaseInstallations | ||
|
||
expect fun Firebase.installations(app: FirebaseApp): FirebaseInstallations | ||
|
||
expect class FirebaseInstallations { | ||
suspend fun delete() | ||
suspend fun getId(): String | ||
suspend fun getToken(forceRefresh: Boolean): String | ||
} | ||
|
||
expect class FirebaseInstallationsException: FirebaseException | ||
|
53 changes: 53 additions & 0 deletions
53
...base-installations/src/iosMain/kotlin/dev/gitlive/firebase/installations/installations.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package dev.gitlive.firebase.installations | ||
|
||
import cocoapods.FirebaseInstallations.* | ||
import dev.gitlive.firebase.Firebase | ||
import dev.gitlive.firebase.FirebaseApp | ||
import dev.gitlive.firebase.FirebaseException | ||
import kotlinx.coroutines.CompletableDeferred | ||
import platform.Foundation.* | ||
|
||
actual val Firebase.installations | ||
get() = FirebaseInstallations(FIRInstallations.installations()) | ||
|
||
actual fun Firebase.installations(app: FirebaseApp) | ||
= FirebaseInstallations(FIRInstallations.installationsWithApp(app.ios)) | ||
|
||
actual class FirebaseInstallations internal constructor(val ios: FIRInstallations) { | ||
|
||
actual suspend fun delete() = ios.await { deleteWithCompletion(completion = it) } | ||
|
||
actual suspend fun getId(): String = ios.awaitResult { installationIDWithCompletion(completion = it) } | ||
|
||
actual suspend fun getToken(forceRefresh: Boolean): String { | ||
val result: FIRInstallationsAuthTokenResult = ios.awaitResult { authTokenForcingRefresh(forceRefresh = forceRefresh, completion = it) } | ||
|
||
return result.authToken | ||
} | ||
} | ||
|
||
actual class FirebaseInstallationsException(message: String): FirebaseException(message) | ||
|
||
suspend inline fun <T> T.await(function: T.(callback: (NSError?) -> Unit) -> Unit) { | ||
val job = CompletableDeferred<Unit>() | ||
function { error -> | ||
if(error == null) { | ||
job.complete(Unit) | ||
} else { | ||
job.completeExceptionally(FirebaseInstallationsException(error.toString())) | ||
} | ||
} | ||
job.await() | ||
} | ||
|
||
suspend inline fun <T, reified R> T.awaitResult(function: T.(callback: (R?, NSError?) -> Unit) -> Unit): R { | ||
val job = CompletableDeferred<R?>() | ||
function { result, error -> | ||
if(error == null) { | ||
job.complete(result) | ||
} else { | ||
job.completeExceptionally(FirebaseInstallationsException(error.toString())) | ||
} | ||
} | ||
return job.await() as R | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nbransby Actually there's a separate package for Android, so probably makes sense to leave it as separate module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nbransby Can you take a look? I have some more PRs in my pipeline :)