Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resources DSL #523

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/dsl.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ By default, SGP disables androidTests in projects. These can be enabled via the

This is important for opting in tests to [AndroidTest APK Aggregation](/utilities/#androidtest-apk-aggregation).

### Resources

By default, we disable _Android_ resources (different from _Java_ resources) and libraries have to opt-in to using them.

This can be enabled via the `resources()` feature, which will enable the relevant `BuildFeature` in the Android plugin and also takes a required `prefix` parameter that is used as the required `resourcePrefix` for that library's resources to avoid naming conflicts.

## Android Application Features

### Permission AllowList
Expand Down
15 changes: 15 additions & 0 deletions slack-plugin/src/main/kotlin/slack/gradle/SlackExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package slack.gradle

import com.android.build.api.dsl.CommonExtension
import com.android.build.gradle.LibraryExtension
import com.squareup.anvil.plugin.AnvilExtension
import dev.zacsweers.moshix.ir.gradle.MoshiPluginExtension
import javax.inject.Inject
Expand Down Expand Up @@ -813,6 +814,20 @@ public abstract class AndroidFeaturesHandler @Inject constructor() {
androidExtension!!.testOptions.unitTests.isIncludeAndroidResources = true
robolectric.setDisallowChanges(true)
}

/**
* **LIBRARIES ONLY**
*
* Enables android resources in this library and enforces use of the given [prefix] for all
* resources.
*/
public fun resources(prefix: String) {
val libraryExtension =
androidExtension as? LibraryExtension
?: error("slack.android.features.resources() is only applicable in libraries!")
libraryExtension.resourcePrefix = prefix
libraryExtension.buildFeatures { androidResources = true }
}
}

@SlackExtensionMarker
Expand Down
Loading