Skip to content

Commit

Permalink
36 create firebase convention plugin (#155)
Browse files Browse the repository at this point in the history
* WIP: Migrating Firebase dependencies to convention plugin

* WIP: Migrating Firebase dependencies to convention plugin

* WIP: Migrating Firebase dependencies to convention plugin

* fixed firebase plugin issue

* lint checks

* Feat: Migrated Firebase dependencies to convention plugin

---------

Co-authored-by: Juma Allan <[email protected]>
  • Loading branch information
misshannah and jumaallan authored Aug 1, 2023
1 parent 8419987 commit 12eb6c6
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 11 deletions.
9 changes: 3 additions & 6 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("droidconke.android.hilt")
id("com.google.gms.google-services")
id("com.google.firebase.crashlytics")
id("com.google.firebase.firebase-perf")
id("droidconke.android.application.firebase")
id("org.jlleitschuh.gradle.ktlint")
id("io.gitlab.arturbosch.detekt")
}

android {
Expand Down Expand Up @@ -85,8 +85,5 @@ dependencies {

testImplementation(libs.bundles.test)

implementation(platform(libs.firebase.bom))
implementation(libs.bundles.firebase)

coreLibraryDesugaring(libs.desugar.jdk.libs)
}
10 changes: 10 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach
dependencies {
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.kotlin.gradlePlugin)
compileOnly(libs.firebase.crashlytics.gradlePlugin)
compileOnly(libs.firebase.performance.gradlePlugin)
compileOnly(libs.ksp.gradlePlugin)
}

Expand All @@ -39,5 +41,13 @@ gradlePlugin {
id = "droidconke.android.library.compose"
implementationClass = "AndroidLibraryComposeConventionPlugin"
}
register("androidFirebase") {
id = "droidconke.android.application.firebase"
implementationClass = "AndroidApplicationFirebaseConventionPlugin"
}
register("androidLibraryFirebase") {
id = "droidconke.android.library.firebase"
implementationClass = "AndroidLibraryFirebaseConventionPlugin"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import com.android.build.api.dsl.ApplicationExtension
import com.android254.libs
import com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies

class AndroidApplicationFirebaseConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.google.gms.google-services")
apply("com.google.firebase.firebase-perf")
apply("com.google.firebase.crashlytics")
}

dependencies {

val bom = libs.findLibrary("firebase-bom").get()
add("implementation", platform(bom))
"implementation"(libs.findLibrary("firebase.analytics").get())
"implementation"(libs.findLibrary("firebase.performance").get())
"implementation"(libs.findLibrary("firebase.crashlytics").get())
"implementation"(libs.findLibrary("firebase.common").get())
"implementation"(libs.findLibrary("firebase.remote.config").get())
}

extensions.configure<ApplicationExtension> {
buildTypes.configureEach {
// Disable the Crashlytics mapping file upload. This feature should only be
// enabled if a Firebase backend is available and configured in
// google-services.json.
configure<CrashlyticsExtension> {
mappingFileUploadEnabled = false
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import com.android.build.api.dsl.ApplicationExtension
import com.android254.libs
import com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies

class AndroidLibraryFirebaseConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
dependencies {

val bom = libs.findLibrary("firebase-bom").get()
add("implementation", platform(bom))
"implementation"(libs.findLibrary("firebase.common").get())
"implementation"(libs.findLibrary("firebase.remote.config").get())
}
}
}
}
3 changes: 1 addition & 2 deletions data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ plugins {
id("droidconke.android.library")
id("droidconke.android.room")
id("droidconke.android.hilt")
id("droidconke.android.library.firebase")
kotlin("plugin.serialization")
}

Expand Down Expand Up @@ -53,8 +54,6 @@ dependencies {
implementation(libs.ktor.auth)
implementation(libs.ktor.logging)
implementation(libs.ktor.okhttp)
implementation(platform(libs.firebase.bom))
implementation(libs.bundles.firebase)

releaseImplementation(libs.chucker.release)
debugImplementation(libs.chucker.debug)
Expand Down
11 changes: 9 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ lifecycle = "2.5.1"
room = "2.5.0"
ktor = "2.2.2"
splash = "1.0.0"
firebaseCrashlyticsPlugin = "2.9.2"
firebasePerfPlugin = "1.4.2"
junit4 = "4.13.2"
agp = "7.4.1"
chucker = "3.5.2"
ksp = "1.8.20-1.0.11"
androidxComposeBom = "2023.06.01"
remote_config = "21.4.1"

[libraries]
android-appCompat = "androidx.appcompat:appcompat:1.6.1"
Expand Down Expand Up @@ -83,12 +86,14 @@ ktor-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref =
ktor-auth = { module = "io.ktor:ktor-client-auth", version.ref = "ktor" }
ktor-mock = { module = "io.ktor:ktor-client-mock", version.ref = "ktor" }
ktor-logging = { module = "io.ktor:ktor-client-logging", version.ref = "ktor" }
firebase-bom = "com.google.firebase:firebase-bom:31.2.2"
firebase-bom = "com.google.firebase:firebase-bom:32.2.0"
firebase-messaging = { module = "com.google.firebase:firebase-messaging-ktx" }
firebase-crashlytics = { module = "com.google.firebase:firebase-crashlytics-ktx" }
firebase-analytics = { module = "com.google.firebase:firebase-analytics-ktx" }
firebase-performance = { module = "com.google.firebase:firebase-perf-ktx" }
firebase-config = { module = "com.google.firebase:firebase-config-ktx" }
firebase-remote-config = { module = "com.google.firebase:firebase-config-ktx", version.ref = "remote_config" }
firebase-common = "com.google.firebase:firebase-common-ktx:20.3.3"
chucker-debug = { module = "com.github.chuckerteam.chucker:library", version.ref = "chucker" }
chucker-release = { module = "com.github.chuckerteam.chucker:library-no-op", version.ref = "chucker" }

Expand All @@ -99,6 +104,8 @@ test-junit-ktx = "androidx.test.ext:junit-ktx:1.1.5"
junit4 = { group = "junit", name = "junit", version.ref = "junit4" }

# Dependencies of the included build-logic
firebase-crashlytics-gradlePlugin = { group = "com.google.firebase", name = "firebase-crashlytics-gradle", version.ref = "firebaseCrashlyticsPlugin" }
firebase-performance-gradlePlugin = { group = "com.google.firebase", name = "perf-plugin", version.ref = "firebasePerfPlugin" }
android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "agp" }
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
ksp-gradlePlugin = { group = "com.google.devtools.ksp", name = "com.google.devtools.ksp.gradle.plugin", version.ref = "ksp" }
Expand All @@ -108,7 +115,7 @@ compose = ["coil-compose", "compose-activity", "compose-compiler", "compose-mate
lifecycle = ["lifecycle-livedataKtx", "lifecycle-runtimeKtx", "lifecycle-viewmodel-compose"]
room = ["room-ktx", "room-paging", "room-runtime"]
ktor = ["ktor-core", "ktor-android", "ktor-json", "ktor-content-negotiation"]
firebase = ["firebase-messaging", "firebase-crashlytics", "firebase-analytics", "firebase-performance", "firebase-config"]
firebase = ["firebase-messaging", "firebase-crashlytics", "firebase-analytics", "firebase-performance", "firebase-remote-config", "firebase-common"]
test = ["junit4", "test-junit-ktx"]

[plugins]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ fun FeedScreen(
feedViewModel: FeedViewModel = hiltViewModel()
) {
val bottomSheetState = rememberModalBottomSheetState(
skipPartiallyExpanded= true)
skipPartiallyExpanded = true
)
val scope = rememberCoroutineScope()
feedViewModel.fetchFeed()
val feedUIState = feedViewModel.viewState
Expand Down

0 comments on commit 12eb6c6

Please sign in to comment.