diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4f2821da7..a13529ec8 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 diff --git a/README.md b/README.md index 44af9afdc..fe4265a14 100644 --- a/README.md +++ b/README.md @@ -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) | diff --git a/build.gradle.kts b/build.gradle.kts index 649fe04e7..507fb50f9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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" diff --git a/firebase-messaging/build.gradle.kts b/firebase-messaging/build.gradle.kts new file mode 100644 index 000000000..e3d7c263d --- /dev/null +++ b/firebase-messaging/build.gradle.kts @@ -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) +} diff --git a/firebase-messaging/firebase_messaging.podspec b/firebase-messaging/firebase_messaging.podspec new file mode 100644 index 000000000..a6535f70e --- /dev/null +++ b/firebase-messaging/firebase_messaging.podspec @@ -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 \ No newline at end of file diff --git a/firebase-messaging/package.json b/firebase-messaging/package.json new file mode 100644 index 000000000..f156d390c --- /dev/null +++ b/firebase-messaging/package.json @@ -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" + } +} diff --git a/firebase-messaging/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/messaging/messaging.kt b/firebase-messaging/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/messaging/messaging.kt new file mode 100644 index 000000000..059bf03d6 --- /dev/null +++ b/firebase-messaging/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/messaging/messaging.kt @@ -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" + ) + ) + } +} \ No newline at end of file diff --git a/firebase-messaging/src/androidMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt b/firebase-messaging/src/androidMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt new file mode 100644 index 000000000..17619585f --- /dev/null +++ b/firebase-messaging/src/androidMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt @@ -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) { + +} \ No newline at end of file diff --git a/firebase-messaging/src/commonMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt b/firebase-messaging/src/commonMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt new file mode 100644 index 000000000..ea8fa6e3d --- /dev/null +++ b/firebase-messaging/src/commonMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt @@ -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 diff --git a/firebase-messaging/src/commonTest/kotlin/dev/gitlive/firebase/messaging/messaging.kt b/firebase-messaging/src/commonTest/kotlin/dev/gitlive/firebase/messaging/messaging.kt new file mode 100644 index 000000000..e29682ee6 --- /dev/null +++ b/firebase-messaging/src/commonTest/kotlin/dev/gitlive/firebase/messaging/messaging.kt @@ -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) + } +} \ No newline at end of file diff --git a/firebase-messaging/src/iosMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt b/firebase-messaging/src/iosMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt new file mode 100644 index 000000000..2f1897c52 --- /dev/null +++ b/firebase-messaging/src/iosMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt @@ -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) { + +} \ No newline at end of file diff --git a/firebase-messaging/src/iosTest/kotlin/dev/gitlive/firebase/messaging/messaging.kt b/firebase-messaging/src/iosTest/kotlin/dev/gitlive/firebase/messaging/messaging.kt new file mode 100644 index 000000000..3501ed370 --- /dev/null +++ b/firebase-messaging/src/iosTest/kotlin/dev/gitlive/firebase/messaging/messaging.kt @@ -0,0 +1,3 @@ +package dev.gitlive.firebase.messaging + +class IOSFirebaseMessagingTest : FirebaseMessagingTest() \ No newline at end of file diff --git a/firebase-messaging/src/jsMain/kotlin/dev/gitlive/firebase/messaging/externals/messaging.kt b/firebase-messaging/src/jsMain/kotlin/dev/gitlive/firebase/messaging/externals/messaging.kt new file mode 100644 index 000000000..506c8ef8f --- /dev/null +++ b/firebase-messaging/src/jsMain/kotlin/dev/gitlive/firebase/messaging/externals/messaging.kt @@ -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 \ No newline at end of file diff --git a/firebase-messaging/src/jsMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt b/firebase-messaging/src/jsMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt new file mode 100644 index 000000000..dc809b68f --- /dev/null +++ b/firebase-messaging/src/jsMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt @@ -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) { + +} \ No newline at end of file diff --git a/firebase-messaging/src/jvmMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt b/firebase-messaging/src/jvmMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt new file mode 100644 index 000000000..6e13a52b2 --- /dev/null +++ b/firebase-messaging/src/jvmMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt @@ -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 \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 19068e9f3..fcc583fd6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,6 +30,7 @@ firebase-config.skipIosTests=false firebase-database.skipIosTests=false firebase-firestore.skipIosTests=false firebase-functions.skipIosTests=false +firebase-messaging.skipIosTests=false firebase-installations.skipIosTests=false firebase-perf.skipIosTests=false firebase-crashlytics.skipIosTests=false @@ -44,6 +45,7 @@ firebase-config.skipJsTests=false firebase-database.skipJsTests=false firebase-firestore.skipJsTests=false firebase-functions.skipJsTests=false +firebase-messaging.skipJsTests=false firebase-installations.skipJsTests=false firebase-perf.skipJsTests=false firebase-storage.skipJsTests=false @@ -57,6 +59,7 @@ firebase-config.version=1.12.0 firebase-database.version=1.12.0 firebase-firestore.version=1.12.0 firebase-functions.version=1.12.0 +firebase-messaging.version=1.12.0 firebase-installations.version=1.12.0 firebase-perf.version=1.12.0 firebase-crashlytics.version=1.12.0 diff --git a/settings.gradle.kts b/settings.gradle.kts index 68af478a5..dff3511a3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,6 +7,7 @@ include( "firebase-database", "firebase-firestore", "firebase-functions", + "firebase-messaging", "firebase-installations", "firebase-perf", "firebase-crashlytics",