diff --git a/.bazel/.test.bazelrc b/.bazel/.test.bazelrc index 1081a76c..6b73225f 100644 --- a/.bazel/.test.bazelrc +++ b/.bazel/.test.bazelrc @@ -2,5 +2,4 @@ test --build_tests_only test --test_verbose_timeout_warnings test --test_output=errors # Print test logs for failed tests -test --test_summary=terse # Print information only about unsuccessful tests that were run -test --ui_event_filters=-DEBUG \ No newline at end of file +test --test_summary=terse # Print information only about unsuccessful tests that were run \ No newline at end of file diff --git a/WORKSPACE b/WORKSPACE index 80f95136..2e8570dc 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -27,7 +27,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") git_repository( name = "grab_bazel_common", - commit = "7ce14f2063b19b1e700bb9fa51cc944626545450", + commit = "46e70d673d86c1aae4b317f05506601b19c2b4c9", remote = "https://github.com/grab/grab-bazel-common.git", ) diff --git a/build.gradle b/build.gradle index 90378d10..5883e5ed 100644 --- a/build.gradle +++ b/build.gradle @@ -98,7 +98,7 @@ grazel { rules { bazelCommon { gitRepository { - commit = "7ce14f2063b19b1e700bb9fa51cc944626545450" + commit = "46e70d673d86c1aae4b317f05506601b19c2b4c9" remote = "https://github.com/grab/grab-bazel-common.git" } toolchains { diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/bazel/rules/AndroidRules.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/bazel/rules/AndroidRules.kt index 470dc9f5..05de0359 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/bazel/rules/AndroidRules.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/bazel/rules/AndroidRules.kt @@ -140,6 +140,7 @@ internal fun StatementsBuilder.androidBinary( assetsDir: String? = null, buildConfigData: BuildConfigData, lintConfigs: LintConfigs? = null, + resConfigFilters: Set = emptySet(), ) { load("@$GRAB_BAZEL_COMMON//rules:defs.bzl", "android_binary") rule("android_binary") { @@ -168,6 +169,9 @@ internal fun StatementsBuilder.androidBinary( transform = Assignee::asString ) } + resConfigFilters.notEmpty { + "resource_configuration_filters" `=` resConfigFilters.quote + } resources?.let { "resources" `=` resources } deps.notEmpty { "deps" `=` array(deps.map(BazelDependency::toString).quote) diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidData.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidData.kt index a4020a9f..9fbc211c 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidData.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidData.kt @@ -80,6 +80,7 @@ internal data class AndroidBinaryData( override val tags: List = emptyList(), override val lintConfigs: LintConfigs, val manifestValues: Map = emptyMap(), + val resConfigs: Set = emptySet(), val multidex: Multidex = Multidex.Native, val dexShards: Int? = null, val incrementalDexing: Boolean = true, diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidExtractor.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidExtractor.kt index 8805f0f5..0df9c9c9 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidExtractor.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidExtractor.kt @@ -220,6 +220,11 @@ constructor( val lintConfigs = lintConfigs(extension.lintOptions, project) + val resourceConfiguration = matchedVariant.variant + .productFlavors + .flatMap { it.resourceConfigurations } + .toSortedSet() + return AndroidBinaryData( name = project.name, manifestValues = manifestValues, @@ -234,6 +239,7 @@ constructor( compose = project.hasCompose, databinding = project.hasDatabinding, lintConfigs = lintConfigs, + resConfigs = resourceConfiguration ) } } \ No newline at end of file diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidTarget.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidTarget.kt index d1e73a03..d0e6af90 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidTarget.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidTarget.kt @@ -103,6 +103,7 @@ internal data class AndroidBinaryTarget( val debugKey: String? = null, val dexShards: Int? = null, val manifestValues: Map = mapOf(), + val resConfigFilters: Set = emptySet(), val customPackage: String, val incrementalDexing: Boolean = false, ) : AndroidTarget { @@ -121,6 +122,7 @@ internal data class AndroidBinaryTarget( srcsGlob = srcs, manifest = manifest, manifestValues = manifestValues, + resConfigFilters = resConfigFilters, resources = buildResources(resDirs), resValuesData = resValuesData, deps = deps, diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/target/AndroidBinaryTargetBuilder.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/target/AndroidBinaryTargetBuilder.kt index faa089ca..44283a11 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/target/AndroidBinaryTargetBuilder.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/target/AndroidBinaryTargetBuilder.kt @@ -119,6 +119,7 @@ constructor( packageName = androidBinaryData.packageName, manifest = androidLibraryData.manifestFile, manifestValues = androidBinaryData.manifestValues, + resConfigFilters = androidBinaryData.resConfigs, resDirs = androidLibraryData.res, resValuesData = androidLibraryData.resValuesData, assetsGlob = androidLibraryData.assets, diff --git a/sample-android-flavor/src/main/res/layout/activity_flavor.xml b/sample-android-flavor/src/main/res/layout/activity_flavor.xml index 6c060346..265557cd 100644 --- a/sample-android-flavor/src/main/res/layout/activity_flavor.xml +++ b/sample-android-flavor/src/main/res/layout/activity_flavor.xml @@ -34,7 +34,8 @@ android:id="@+id/text" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_gravity="center" /> + android:layout_gravity="center" + android:lineHeight="12dp" /> + + \ No newline at end of file diff --git a/sample-android/BUILD.bazel b/sample-android/BUILD.bazel index 89cfb0a8..edb5531f 100644 --- a/sample-android/BUILD.bazel +++ b/sample-android/BUILD.bazel @@ -56,6 +56,19 @@ android_binary( "flavor": "free", }, }, + resource_configuration_filters = [ + "en", + "id", + "in", + "ja", + "km", + "ko", + "ms", + "my", + "th", + "vi", + "zh", + ], resources = { "src/main/res-debug": { }, @@ -147,6 +160,19 @@ android_binary( "flavor": "paid", }, }, + resource_configuration_filters = [ + "en", + "id", + "in", + "ja", + "km", + "ko", + "ms", + "my", + "th", + "vi", + "zh", + ], resources = { "src/main/res-debug": { }, @@ -238,6 +264,19 @@ android_binary( "flavor": "free", }, }, + resource_configuration_filters = [ + "en", + "id", + "in", + "ja", + "km", + "ko", + "ms", + "my", + "th", + "vi", + "zh", + ], resources = { "src/main/res-debug": { }, @@ -329,6 +368,19 @@ android_binary( "flavor": "paid", }, }, + resource_configuration_filters = [ + "en", + "id", + "in", + "ja", + "km", + "ko", + "ms", + "my", + "th", + "vi", + "zh", + ], resources = { "src/main/res-debug": { }, diff --git a/sample-android/build.gradle b/sample-android/build.gradle index 3e0253b3..41eb14fd 100644 --- a/sample-android/build.gradle +++ b/sample-android/build.gradle @@ -66,19 +66,24 @@ android { } flavorDimensions "service", "release" + def resConfigs = ["en", "id", "in", "km", "ms", "my", "th", "vi", "zh", "ko", "ja"] productFlavors { flavor1 { + resourceConfigurations += resConfigs dimension "service" } flavor2 { + resourceConfigurations += resConfigs dimension "service" } free { + resourceConfigurations += resConfigs dimension "release" applicationIdSuffix ".free" resValue("string", "flavor", "free") } paid { + resourceConfigurations += resConfigs dimension "release" applicationIdSuffix ".paid" resValue("string", "flavor", "paid") diff --git a/sample-android/lint_baseline.xml b/sample-android/lint_baseline.xml index 1042e85c..2f157238 100755 --- a/sample-android/lint_baseline.xml +++ b/sample-android/lint_baseline.xml @@ -1,5 +1,23 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -43,6 +160,17 @@ column="37"/> + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sample-android/src/free/res/values-id/strings.xml b/sample-android/src/free/res/values-id/strings.xml new file mode 100644 index 00000000..3e69e72b --- /dev/null +++ b/sample-android/src/free/res/values-id/strings.xml @@ -0,0 +1,19 @@ + + + + Overridable resource - From free + \ No newline at end of file diff --git a/sample-android/src/main/res/layout/activity_main.xml b/sample-android/src/main/res/layout/activity_main.xml index d957cb4a..02e8ce5a 100644 --- a/sample-android/src/main/res/layout/activity_main.xml +++ b/sample-android/src/main/res/layout/activity_main.xml @@ -25,6 +25,7 @@ android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:lineHeight="16dp" android:text="Hello World from Grazel!" app:layout_constraintBottom_toTopOf="@+id/button" app:layout_constraintEnd_toEndOf="parent" @@ -69,4 +70,9 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/composeButton" /> + + \ No newline at end of file