Skip to content

Instantly share code, notes, and snippets.

@NedaTop
Last active July 24, 2023 16:51
Show Gist options
  • Save NedaTop/68c6e708f5584061a3daf8a9e7321cfd to your computer and use it in GitHub Desktop.
Save NedaTop/68c6e708f5584061a3daf8a9e7321cfd to your computer and use it in GitHub Desktop.
Tiles to ProtoLayout migration

1. Dependency update

  • Replace implementation("androidx.wear.tiles:tiles-material:<version>") with implementation("androidx.wear.protolayout:protolayout-material:1.0.0-rc01")
  • Add implementation("androidx.wear.protolayout:protolayout-expression:1.0.0-rc01") and implementation("androidx.wear.protolayout:protolayout:1.0.0-rc01")
  • Update tiles:tiles dependency to use the latest version implementation("androidx.wear.tiles:tiles:1.2.0-rc01"), and it should stay for tiles only classes.

2. Code update

Use the script we provided to update your project's imports from Tiles to ProtoLayout. Script can be found here or copy the snippet below:

# Rename material packages
find . -type f -name "*.(java|kt)" -exec sed -i "s|androidx.wear.tiles.material|androidx.wear.protolayout.material|g" {} +

# Rename builder packages
find . -type f -name "*.(java|kt)" -exec sed -i "s|androidx.wear.tiles|androidx.wear.protolayout|g" {} +

# Re-rename real tiles classes
find . -type f -name "*.(java|kt)" -exec sed -i "s|androidx.wear.protolayout.EventBuilders|androidx.wear.tiles.EventBuilders|g" {} +
find . -type f -name "*.(java|kt)" -exec sed -i "s|androidx.wear.protolayout.RequestBuilders|androidx.wear.tiles.RequestBuilders|g" {} +
find . -type f -name "*.(java|kt)" -exec sed -i "s|androidx.wear.protolayout.TileBuilders|androidx.wear.tiles.TileBuilders|g" {} +
find . -type f -name "*.(java|kt)" -exec sed -i "s|androidx.wear.protolayout.TileService|androidx.wear.tiles.TileService|g" {} +

# Rename updated methods
# Note that etXXXX is intentional as there are both setter and getter.
find . -type f -name "*.(java|kt)" -exec sed -i "s|etTimeline|etTileTimeline|g" {} +
find . -type f -name "*.(java|kt)" -exec sed -i "s|onResourcesRequest|onTileResourcesRequest|g" {} +
find . -type f -name "*.(java|kt)" -exec sed -i "s|etDeviceParameters|etDeviceConfiguration|g" {} +
find . -type f -name "*.(java|kt)" -exec sed -i "s|etState|etCurrentState|g" {} +

Alternatively, follow the steps explained here for manual rename.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment