Skip to content

Commit

Permalink
Configure demo app flavors in the build logic (#1230)
Browse files Browse the repository at this point in the history
* Update baseline profiles

* Configure demo app flavors in the build logic

* Move configureFlavors to the demo-app

---------

Co-authored-by: Aleksandar Apostolov <[email protected]>
  • Loading branch information
skydoves and aleksandar-apostolov authored Nov 21, 2024
1 parent ff79501 commit fb37338
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 41 deletions.
20 changes: 10 additions & 10 deletions benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
import io.getstream.video.android.Configuration
import io.getstream.video.configureFlavors

@Suppress("DSL_SCOPE_VIOLATION")
plugins {
Expand Down Expand Up @@ -62,16 +63,15 @@ android {
}
}

flavorDimensions += "environment"
productFlavors {
create("development") {
dimension = "environment"
proguardFiles("benchmark-rules.pro")
}
create("production") {
dimension = "environment"
proguardFiles("benchmark-rules.pro")
}
// Use the same flavor dimensions as the application to allow generating Baseline Profiles on prod,
// which is more close to what will be shipped to users (no fake data), but has ability to run the
// benchmarks on demo, so we benchmark on stable data.
configureFlavors(this) { flavor ->
buildConfigField(
"String",
"APP_FLAVOR_SUFFIX",
"\"${flavor.applicationIdSuffix ?: ""}\""
)
}

targetProjectPath = ":demo-app"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class BaselineProfileGenerator {
@Test
fun startup() =
baselineProfileRule.collect(
packageName = packageName,
packageName = PACKAGE_NAME,
stableIterations = 2,
maxIterations = 8,
includeInStartupProfile = true,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiObject2
import androidx.test.uiautomator.Until

/**
* Convenience parameter to use proper package name with regards to build type and build flavor.
*/
val PACKAGE_NAME = buildString {
append("io.getstream.video.android")
append(BuildConfig.APP_FLAVOR_SUFFIX)
}

internal fun UiDevice.waitForObject(selector: BySelector, timeout: Long = 5_000): UiObject2? {
if (wait(Until.hasObject(selector), timeout)) {
return findObject(selector)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import com.android.build.api.dsl.ApplicationExtension
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import io.getstream.video.configureAndroidCompose
import io.getstream.video.configureFlavors
import io.getstream.video.configureKotlinAndroid
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import com.android.build.api.dsl.ApplicationExtension
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import io.getstream.video.configureFlavors
import io.getstream.video.configureKotlinAndroid
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.getstream.video

import com.android.build.api.dsl.ApplicationExtension
import com.android.build.api.dsl.ApplicationProductFlavor
import com.android.build.api.dsl.CommonExtension
import com.android.build.api.dsl.ProductFlavor

@Suppress("EnumEntryName")
enum class FlavorDimension {
contentType
}

// The content for the app can either come from local static data which is useful for demo
// purposes, or from a production backend server which supplies up-to-date, real content.
// These two product flavors reflect this behaviour.
@Suppress("EnumEntryName")
enum class VideoDemoFlavor(val dimension: FlavorDimension, val applicationIdSuffix: String? = null) {
development(FlavorDimension.contentType, applicationIdSuffix = ".dogfooding"),
production(FlavorDimension.contentType)
}

fun configureFlavors(
commonExtension: CommonExtension<*, *, *, *, *, *>,
flavorConfigurationBlock: ProductFlavor.(flavor: VideoDemoFlavor) -> Unit = {}
) {
commonExtension.apply {
flavorDimensions += "environment"
productFlavors {
VideoDemoFlavor.values().forEach {
create(it.name) {
dimension = "environment"
flavorConfigurationBlock(this, it)
if (this@apply is ApplicationExtension && this is ApplicationProductFlavor) {
if (it.applicationIdSuffix != null) {
applicationIdSuffix = it.applicationIdSuffix
}
}
proguardFiles("benchmark-rules.pro")
}
}
}
}
}
25 changes: 14 additions & 11 deletions demo-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import com.android.build.api.variant.BuildConfigField
import com.android.build.api.variant.ResValue
import com.github.triplet.gradle.androidpublisher.ResolutionStrategy
import io.getstream.video.FlavorDimension
import io.getstream.video.VideoDemoFlavor
import io.getstream.video.android.Configuration
import io.getstream.video.configureFlavors
import java.io.FileInputStream
import java.util.*

Expand All @@ -45,6 +48,7 @@ android {
targetSdk = Configuration.targetSdk
versionCode = 1
versionName = Configuration.streamVideoCallGooglePlayVersion
missingDimensionStrategy(FlavorDimension.contentType.name, VideoDemoFlavor.development.name)
vectorDrawables {
useSupportLibrary = true
}
Expand Down Expand Up @@ -83,6 +87,8 @@ android {
}
}

configureFlavors(this)

buildTypes {
getByName("debug") {
versionNameSuffix = "-DEBUG"
Expand All @@ -94,6 +100,7 @@ android {
}
getByName("release") {
isMinifyEnabled = true
baselineProfile.automaticGenerationDuringBuild = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
Expand All @@ -110,17 +117,6 @@ android {
}
}

flavorDimensions += "environment"
productFlavors {
create("development") {
dimension = "environment"
applicationIdSuffix = ".dogfooding"
}
create("production") {
dimension = "environment"
}
}

buildFeatures {
resValues = true
buildConfig = true
Expand All @@ -136,6 +132,13 @@ android {

baselineProfile {
mergeIntoMain = true

// Don't build on every iteration of a full assemble.
// Instead enable generation directly for the release build variant.
automaticGenerationDuringBuild = false

// Make use of Dex Layout Optimizations via Startup Profiles
dexLayoutOptimization = true
}

playConfigs {
Expand Down

0 comments on commit fb37338

Please sign in to comment.