Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase messaging frame #509

Merged
merged 4 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:
run: ./gradlew :firebase-firestore:publish
- name: Publish Firebase Functions
run: ./gradlew :firebase-functions:publish
- name: Publish Firebase Messaging
run: ./gradlew :firebase-messaging:publish
- name: Publish Firebase Storage
run: ./gradlew :firebase-storage:publish
- name: Publish Firebase Installations
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The following libraries are available for the various Firebase products.
| [Realtime Database](https://firebase.google.com/docs/database) | [`dev.gitlive:firebase-database:1.12.0`](https://search.maven.org/artifact/dev.gitlive/firebase-database/1.12.0/pom) | [![70%](https://img.shields.io/badge/-70%25-orange?style=flat-square)](/firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/database.kt) |
| [Cloud Firestore](https://firebase.google.com/docs/firestore) | [`dev.gitlive:firebase-firestore:1.12.0`](https://search.maven.org/artifact/dev.gitlive/firebase-firestore/1.12.0/pom) | [![60%](https://img.shields.io/badge/-60%25-orange?style=flat-square)](/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt) |
| [Cloud Functions](https://firebase.google.com/docs/functions) | [`dev.gitlive:firebase-functions:1.12.0`](https://search.maven.org/artifact/dev.gitlive/firebase-functions/1.12.0/pom) | [![80%](https://img.shields.io/badge/-80%25-green?style=flat-square)](/firebase-functions/src/commonMain/kotlin/dev/gitlive/firebase/functions/functions.kt) |
| [Cloud Messaging](https://firebase.google.com/docs/cloud-messaging) | [`dev.gitlive:firebase-messaging:1.12.0`](https://search.maven.org/artifact/dev.gitlive/firebase-messaging/1.12.0/pom) | ![0%](https://img.shields.io/badge/-0%25-lightgrey?style=flat-square) |
| [Cloud Messaging](https://firebase.google.com/docs/cloud-messaging) | [`dev.gitlive:firebase-messaging:1.12.0`](https://search.maven.org/artifact/dev.gitlive/firebase-messaging/1.12.0/pom) | [![1%](https://img.shields.io/badge/-0%25-lightgrey?style=flat-square)](/firebase-messaging/src/commonMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt) |
| [Cloud Storage](https://firebase.google.com/docs/storage) | [`dev.gitlive:firebase-storage:1.12.0`](https://search.maven.org/artifact/dev.gitlive/firebase-storage/1.12.0/pom) | [![40%](https://img.shields.io/badge/-40%25-orange?style=flat-square)](/firebase-storage/src/commonMain/kotlin/dev/gitlive/firebase/storage/storage.kt) |
| [Installations](https://firebase.google.com/docs/projects/manage-installations) | [`dev.gitlive:firebase-installations:1.12.0`](https://search.maven.org/artifact/dev.gitlive/firebase-installations/1.12.0/pom) | [![90%](https://img.shields.io/badge/-90%25-green?style=flat-square)](/firebase-installations/src/commonMain/kotlin/dev/gitlive/firebase/installations/installations.kt) |
| [Remote Config](https://firebase.google.com/docs/remote-config) | [`dev.gitlive:firebase-config:1.12.0`](https://search.maven.org/artifact/dev.gitlive/firebase-config/1.12.0/pom) | [![20%](https://img.shields.io/badge/-20%25-orange?style=flat-square)](/firebase-config/src/commonMain/kotlin/dev/gitlive/firebase/remoteconfig/FirebaseRemoteConfig.kt) |
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ tasks {
"firebase-database:updateVersion", "firebase-database:updateDependencyVersion",
"firebase-firestore:updateVersion", "firebase-firestore:updateDependencyVersion",
"firebase-functions:updateVersion", "firebase-functions:updateDependencyVersion",
"firebase-messaging:updateVersion", "firebase-messaging:updateDependencyVersion",
"firebase-installations:updateVersion", "firebase-installations:updateDependencyVersion",
"firebase-perf:updateVersion", "firebase-perf:updateDependencyVersion",
"firebase-storage:updateVersion", "firebase-storage:updateDependencyVersion"
Expand Down
174 changes: 174 additions & 0 deletions firebase-messaging/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree

/*
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
*/

version = project.property("firebase-messaging.version") as String

plugins {
id("com.android.library")
kotlin("multiplatform")
kotlin("native.cocoapods")
}

android {
val minSdkVersion: Int by project
val compileSdkVersion: Int by project

compileSdk = compileSdkVersion
namespace = "dev.gitlive.firebase.messaging"

defaultConfig {
minSdk = minSdkVersion
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

testOptions {
unitTests.apply {
isIncludeAndroidResources = true
}
}
packaging {
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 {
abortOnError = false
}
}

val supportIosTarget = project.property("skipIosTarget") != "true"

kotlin {

targets.configureEach {
compilations.configureEach {
kotlinOptions.freeCompilerArgs += "-Xexpect-actual-classes"
}
}

@Suppress("OPT_IN_USAGE")
androidTarget {
instrumentedTestVariant.sourceSetTree.set(KotlinSourceSetTree.test)
unitTestVariant.sourceSetTree.set(KotlinSourceSetTree.test)
publishAllLibraryVariants()
compilations.configureEach {
kotlinOptions {
jvmTarget = "11"
}
}
}

if (supportIosTarget) {
iosArm64()
iosX64()
iosSimulatorArm64()
cocoapods {
ios.deploymentTarget = "12.0"
framework {
baseName = "FirebaseMessaging"
}
noPodspec()
pod("FirebaseMessaging") {
version = "10.25.0"
}
}
}

js(IR) {
useCommonJs()
nodejs {
testTask(
Action {
useKarma {
useChromeHeadless()
}
}
)
}
browser {
testTask(
Action {
useKarma {
useChromeHeadless()
}
}
)
}
}

jvm {
compilations.getByName("main") {
kotlinOptions {
jvmTarget = "17"
}
}
compilations.getByName("test") {
kotlinOptions {
jvmTarget = "17"
}
}
}

sourceSets {
all {
languageSettings.apply {
val apiVersion: String by project
val languageVersion: String by project
this.apiVersion = apiVersion
this.languageVersion = languageVersion
progressiveMode = true
optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
if (name.lowercase().contains("ios")) {
optIn("kotlinx.cinterop.ExperimentalForeignApi")
optIn("kotlinx.cinterop.BetaInteropApi")
}
}
}

getByName("commonMain") {
dependencies {
api(project(":firebase-app"))
implementation(project(":firebase-common"))
}
}

getByName("commonTest") {
dependencies {
implementation(project(":test-utils"))
}
}

getByName("androidMain") {
dependencies {
api("com.google.firebase:firebase-messaging")
}
}
}
}

if (project.property("firebase-messaging.skipIosTests") == "true") {
tasks.forEach {
if (it.name.contains("ios", true) && it.name.contains("test", true)) { it.enabled = false }
}
}

if (project.property("firebase-messaging.skipJsTests") == "true") {
tasks.forEach {
if (it.name.contains("js", 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)
}
39 changes: 39 additions & 0 deletions firebase-messaging/firebase_messaging.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Pod::Spec.new do |spec|
spec.name = 'firebase_messaging'
spec.version = '1.8.1'
spec.homepage = ''
spec.source = { :http=> ''}
spec.authors = ''
spec.license = ''
spec.summary = ''
spec.vendored_frameworks = 'build/cocoapods/framework/firebase_messaging.framework'
spec.libraries = 'c++'



spec.pod_target_xcconfig = {
'KOTLIN_PROJECT_PATH' => ':firebase-messaging',
'PRODUCT_MODULE_NAME' => 'firebase_messaging',
}

spec.script_phases = [
{
:name => 'Build firebase_messaging',
:execution_position => :before_compile,
:shell_path => '/bin/sh',
:script => <<-SCRIPT
if [ "YES" = "$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED" ]; then
echo "Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \"YES\""
exit 0
fi
set -ev
REPO_ROOT="$PODS_TARGET_SRCROOT"
"$REPO_ROOT/../gradlew" -p "$REPO_ROOT" $KOTLIN_PROJECT_PATH:syncFramework \
-Pkotlin.native.cocoapods.platform=$PLATFORM_NAME \
-Pkotlin.native.cocoapods.archs="$ARCHS" \
-Pkotlin.native.cocoapods.configuration="$CONFIGURATION"
SCRIPT
}
]

end
31 changes: 31 additions & 0 deletions firebase-messaging/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@gitlive/firebase-messaging",
"version": "1.12.0",
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
"main": "firebase-messaging.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.12.0",
"firebase": "9.19.1",
"kotlin": "1.8.20",
"kotlinx-coroutines-core": "1.6.4"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.gitlive.firebase.messaging

import androidx.test.platform.app.InstrumentationRegistry
import dev.gitlive.firebase.Firebase
import dev.gitlive.firebase.FirebaseOptions
import dev.gitlive.firebase.apps
import dev.gitlive.firebase.initialize
import kotlin.test.BeforeTest

class AndroidInstrumentedFirebaseMessagingTest : FirebaseMessagingTest() {

private val context = InstrumentationRegistry.getInstrumentation().context

@BeforeTest
fun initializeFirebase() {
Firebase.apps(context).firstOrNull() ?: Firebase.initialize(
context,
FirebaseOptions(
applicationId = "1:846484016111:ios:dd1f6688bad7af768c841a",
apiKey = "AIzaSyCK87dcMFhzCz_kJVs2cT2AVlqOTLuyWV0",
databaseUrl = "https://fir-kotlin-sdk.firebaseio.com",
storageBucket = "fir-kotlin-sdk.appspot.com",
projectId = "fir-kotlin-sdk",
gcmSenderId = "846484016111"
)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@file:JvmName("android")
package dev.gitlive.firebase.messaging

import dev.gitlive.firebase.Firebase

actual val Firebase.messaging: FirebaseMessaging
get() = FirebaseMessaging(com.google.firebase.messaging.FirebaseMessaging.getInstance())

actual class FirebaseMessaging(val android: com.google.firebase.messaging.FirebaseMessaging) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.gitlive.firebase.messaging

import dev.gitlive.firebase.Firebase
import dev.gitlive.firebase.FirebaseApp

/** Returns the [FirebaseMessaging] instance of the default [FirebaseApp]. */
expect val Firebase.messaging: FirebaseMessaging

expect class FirebaseMessaging
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.gitlive.firebase.messaging

import dev.gitlive.firebase.Firebase
import kotlin.test.Test
import kotlin.test.assertNotNull

abstract class FirebaseMessagingTest {

@Test
fun initialization() {
assertNotNull(Firebase.messaging)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.gitlive.firebase.messaging

import cocoapods.FirebaseMessaging.FIRMessaging
import dev.gitlive.firebase.Firebase

actual val Firebase.messaging: FirebaseMessaging
get() = FirebaseMessaging(FIRMessaging.messaging())

actual class FirebaseMessaging(val ios: FIRMessaging) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package dev.gitlive.firebase.messaging

class IOSFirebaseMessagingTest : FirebaseMessagingTest()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.gitlive.firebase.messaging.externals

import dev.gitlive.firebase.externals.FirebaseApp

external fun getMessaging(
app: FirebaseApp? = definedExternally,
): Messaging

external interface Messaging
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dev.gitlive.firebase.messaging

import dev.gitlive.firebase.Firebase
import dev.gitlive.firebase.messaging.externals.Messaging
import dev.gitlive.firebase.messaging.externals.getMessaging

actual val Firebase.messaging: FirebaseMessaging
get() = FirebaseMessaging(getMessaging())

actual class FirebaseMessaging(val js: Messaging) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@file:JvmName("android")
package dev.gitlive.firebase.messaging

import dev.gitlive.firebase.Firebase

actual val Firebase.messaging: FirebaseMessaging
get() = TODO("Not yet implemented")

actual class FirebaseMessaging
Loading
Loading