Skip to content

Commit 5d57b97

Browse files
committed
Simplify Startup Initializers
Since the project current modularization does not yet allow to split bindings and the rest of the code, moving the `Initializer`s registration to the `:app` module makes it easier to use. - It avoids duplicated registrations (it was both present in `:app` and `:core:network`) - It avoids removing registrations on other modules that would break during instrumented tests `EnsureInitializerMetadata` had to be suppressed because the Lint rule does not actually check where the initializer are registered, and always expects to see it on the same module, which is quite a simplistic assumption. https://googlesamples.github.io/android-custom-lint-rules/checks/EnsureInitializerMetadata.md.html I also remove the hardcoded `androidx.startup` string with the proper string reference `@string/androidx_startup`.
1 parent f84eab3 commit 5d57b97

File tree

10 files changed

+9
-140
lines changed

10 files changed

+9
-140
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@
5858
tools:node="merge">
5959
<meta-data
6060
android:name="com.android.developers.androidify.startup.FirebaseAppInitializer"
61-
android:value="androidx.startup" />
61+
android:value="@string/androidx_startup" />
6262
<meta-data
6363
android:name="com.android.developers.androidify.startup.FirebaseAppCheckInitializer"
64-
android:value="androidx.startup" />
64+
android:value="@string/androidx_startup" />
6565
<meta-data
6666
android:name="com.android.developers.androidify.startup.FirebaseRemoteConfigInitializer"
67-
android:value="androidx.startup" />
67+
android:value="@string/androidx_startup" />
6868
</provider>
6969
<activity
7070
android:name=".MainActivity"

core/network/src/main/AndroidManifest.xml

Lines changed: 0 additions & 35 deletions
This file was deleted.

core/network/src/main/java/com/android/developers/androidify/startup/FirebaseAppCheckInitializer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.android.developers.androidify.startup
1717

18+
import android.annotation.SuppressLint
1819
import android.content.Context
1920
import androidx.startup.Initializer
2021
import com.google.firebase.appcheck.FirebaseAppCheck
@@ -25,6 +26,7 @@ import com.google.firebase.ktx.Firebase
2526
/**
2627
* Initialize [FirebaseAppCheck] using the App Startup Library.
2728
*/
29+
@SuppressLint("EnsureInitializerMetadata") // Registered in :app module
2830
class FirebaseAppCheckInitializer : Initializer<FirebaseAppCheck> {
2931
override fun create(context: Context): FirebaseAppCheck {
3032
return Firebase.appCheck.apply {

core/network/src/main/java/com/android/developers/androidify/startup/FirebaseAppInitializer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.android.developers.androidify.startup
1717

18+
import android.annotation.SuppressLint
1819
import android.content.Context
1920
import androidx.startup.Initializer
2021
import com.google.firebase.Firebase
@@ -24,6 +25,7 @@ import com.google.firebase.initialize
2425
/**
2526
* Initialize [FirebaseApp] using the App Startup Library.
2627
*/
28+
@SuppressLint("EnsureInitializerMetadata") // Registered in :app module
2729
class FirebaseAppInitializer : Initializer<FirebaseApp> {
2830
override fun create(context: Context): FirebaseApp {
2931
return Firebase.initialize(context)!!

core/network/src/main/java/com/android/developers/androidify/startup/FirebaseRemoteConfigInitializer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.android.developers.androidify.startup
1717

18+
import android.annotation.SuppressLint
1819
import android.content.Context
1920
import android.util.Log
2021
import androidx.startup.Initializer
@@ -27,6 +28,7 @@ import com.google.firebase.remoteconfig.remoteConfigSettings
2728
/**
2829
* Initialize [FirebaseRemoteConfig] using the App Startup Library.
2930
*/
31+
@SuppressLint("EnsureInitializerMetadata") // Registered in :app module
3032
class FirebaseRemoteConfigInitializer : Initializer<FirebaseRemoteConfig> {
3133
override fun create(context: Context): FirebaseRemoteConfig {
3234
return Firebase.remoteConfig.apply {

core/network/src/main/res/xml/startup_initializers.xml

Lines changed: 0 additions & 22 deletions
This file was deleted.

feature/camera/src/androidTest/AndroidManifest.xml

Lines changed: 0 additions & 20 deletions
This file was deleted.

feature/creation/src/androidTest/AndroidManifest.xml

Lines changed: 0 additions & 20 deletions
This file was deleted.

feature/home/src/androidTest/AndroidManifest.xml

Lines changed: 0 additions & 20 deletions
This file was deleted.

feature/results/src/androidTest/AndroidManifest.xml

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)