diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index d5ea6e64513..c6e1f47e140 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -46,11 +46,9 @@ repositories {
     google()
 }
 
-fun isFossSourceSet(): Boolean {
-    return (Variants_gradle.Default.explicitBuildFlavor() ?: gradle.startParameter.taskRequests.toString())
-        .lowercase()
-        .contains("fdroid")
-}
+val nonFreeFlavors = setOf("prod", "internal", "staging", "beta", "dev")
+val fossFlavors = setOf("fdroid")
+val allFlavors = nonFreeFlavors + fossFlavors
 
 private fun getFlavorsSettings(): NormalizedFlavorSettings =
     try {
@@ -76,21 +74,17 @@ android {
     }
     android.buildFeatures.buildConfig = true
 
-    val fdroidBuild = isFossSourceSet()
-
     sourceSets {
-        // Add the "foss" sourceSets for the fdroid flavor
-        if (fdroidBuild) {
-            getByName("fdroid") {
-                java.srcDirs("src/foss/kotlin", "src/prod/kotlin")
-                res.srcDirs("src/prod/res")
-                println("Building with FOSS sourceSets")
-            }
-            // For all other flavors use the "nonfree" sourceSets
-        } else {
-            getByName("main") {
-                java.srcDirs("src/nonfree/kotlin")
-                println("Building with non-free sourceSets")
+        allFlavors.forEach { flavor ->
+            getByName(flavor) {
+                if (flavor in fossFlavors) {
+                    java.srcDirs("src/foss/kotlin", "src/prod/kotlin")
+                    res.srcDirs("src/prod/res")
+                    println("Adding FOSS sourceSets to '$flavor' flavor")
+                } else {
+                    java.srcDirs("src/nonfree/kotlin")
+                    println("Adding non-free sourceSets to '$flavor' flavor")
+                }
             }
         }
     }
@@ -193,15 +187,15 @@ dependencies {
     implementation(libs.resaca.hilt)
     implementation(libs.bundlizer.core)
 
-    var fdroidBuild = isFossSourceSet()
-
-    if (!fdroidBuild) {
-        // firebase
-        implementation(platform(libs.firebase.bom))
-        implementation(libs.firebase.fcm)
-        implementation(libs.googleGms.location)
-    } else {
-        println("Excluding FireBase for FDroid build")
+    allFlavors.forEach { flavor ->
+        if (flavor in nonFreeFlavors) {
+            println("Adding nonfree libraries to '$flavor' flavor")
+            add("${flavor}Implementation", platform(libs.firebase.bom))
+            add("${flavor}Implementation", libs.firebase.fcm)
+            add("${flavor}Implementation", libs.googleGms.location)
+        } else {
+            println("Skipping nonfree libraries for '$flavor' flavor")
+        }
     }
     implementation(libs.androidx.work)