Pull to refresh

Code Push in Flutter

Level of difficultyEasy
Reading time7 min
Views1.3K

In the fast-paced world of mobile app development, the ability to quickly push updates to users is crucial. Enter Code Push - a game-changing technology that allows developers to update mobile apps instantly without going through the traditional app store review process. This article explores how to implement Code Push in Flutter applications using Shorebird, a powerful tool that brings this capability to the Flutter ecosystem.

Understanding Code Push

Code Push is a technique that allows developers to push updates directly to devices without requiring them to download a new version from an app store. This is particularly useful for:

  • Fixing critical bugs quickly

  • Updating content or minor features

  • A/B testing different versions of your app

  • Gradually rolling out new features

Traditionally, Code Push has been more commonly available for React Native applications. However, with tools like Shorebird, Flutter developers can now also take advantage of this technology.

Glossary

Application

An application is what is created by running flutter create [app_name] and corresponds to a listing in the App Store or Play Store.

Each application has a unique app_id that is assigned when you run shorebird init. You can find your application’s id in the shorebird.yaml file at the root of your project.

An application can have zero or more releases

Applications that use build flavors will have a unique app_id for each flavor.

Release

A release is a specific version of an application, identified by a version and build number (e.g. 1.0.0+1). Although code push works for apps distributed outside of the App Store and Play Store, a release most often corresponds with a specific version of your app that is published to the App Store or Play Store.

A release can have zero or more patches applied to it.

Releases are created by running shorebird release [platform], where platform is androidaar, or ios.

Patch

A patch is a change to a specific release, applied as an over-the-air update. For example, a patch could be a bug fix or a new feature. Multiple patches can be published for a given release, although only one patch can be active at a time. Patches are identified by their associated release version and a patch number, which is an auto-incrementing integer.

When your application starts, it checks for available patches and applies the latest one. This patch will be visible the next time your application launches.

Patches are created by running shorebird patch [platform], where platform is androidaar, or ios.

What Can Be Included in a Patch?

Shorebird patches can modify any Dart code in your application. This includes:

  1. App code: Your main application logic and UI components.

  2. Generated code: Any code that's automatically generated as part of your build process.

  3. Dependencies in pubspec.yaml: You can update or add new dependencies, as long as they don't include native code changes.

What Cannot Be Included in a Patch?

There are some limitations to what Shorebird patches can modify:

  1. Asset files: Currently, patches cannot update images, fonts, or other asset files. However, Shorebird has plans to support this in the future.

  2. Native code: Changes to Java/Kotlin code on Android or Objective-C/Swift code on iOS cannot be included in a patch.

  3. Flutter engine changes: You cannot use a patch to change the Flutter version of your app.

Compliance with AppStore Guidelines

A common concern when using Code Push solutions is whether they comply with the guidelines set by major app stores. Shorebird has been designed with these guidelines in mind, ensuring that your app remains compliant when using this tool.

GooglePlay Store Compliance

Shorebird complies with GooglePlay Store guidelines. The Play Store has two main restrictions related to update tools:

  1. Updates must use an interpreter or virtual machine. Shorebird uses the Dart Virtual Machine, which satisfies this requirement.

  2. Changes to the app must not be deceptive (e.g., changing the purpose of the app via update).

The Play Store guidelines state:

"An app distributed via Google Play may not modify, replace, or update itself using any method other than Google Play's update mechanism. Likewise, an app may not download executable code (such as dex, JAR, .so files) from a source other than Google Play. *This restriction does not apply to code that runs in a virtual machine or an interpreter* where either provides indirect access to Android APIs (such as JavaScript in a webview or browser). Apps or third-party code, like SDKs, with interpreted languages (JavaScript, Python, Lua, etc.) loaded at run time (for example, not packaged with the app) must not allow potential violations of Google Play policies."

Shorebird's use of the Dart VM ensures compliance with this guideline. It's important to note that when you clear the application cache, the patch is rolled back and the update needs to be repeated.

Apple AppStore Compliance

Shorebird also complies with Apple AppStore guidelines. The AppStore allows interpreted code to be downloaded to an application, provided that such code:

1. Does not change the primary purpose of the application

2. Does not create a store or storefront for other code or applications

3. Does not bypass signing, sandbox, or other security features of the OS

Shorebird uses a custom Dart interpreter to comply with the interpreter-only restriction for updates on iOS.

Responsible Use

While Shorebird is designed to be compliant, it's crucial to use it responsibly:

  • Be clear with your users about what you're providing with your application.

  • Do not violate user expectations with significant behavioral changes through updates.

  • Avoid using Shorebird (or any code push solution) to circumvent AppStore reviews for major changes.

Deliberately abusing Shorebird to violate AppStore guidelines is against Shorebird's Terms of Service and can result in account termination. By the way, Shorebird works fine with side-loading and mobile device management (MDM) on Android. Shorebird says that no one tried iOS Developer Enterprise program, but they expect it to work just as well.

Shorebird Dashboard

When using Shorebird for Code Push in your Flutter applications, you'll have access to a comprehensive account dashboard. This interface provides crucial information and controls for managing your Code Push deployments. Let's explore what you can find on it

Main page with list of your apps
Main page with list of your apps
Account page with your current plan and usage statistics
Account page with your current plan and usage statistics
Upgrade plan
Upgrade plan

Monthly Patch Installs

Monthly cost

50,000

$20.00

300,000

$100.00

1,000,000

$300.00

2,500,000

$700.00

5,000,000

$1,250.00

10,000,000

$2,000.00

Conclusion

The arrival of Shorebird's Code Push solution marks a significant milestone in the Flutter ecosystem. For years, Flutter developers have eagerly awaited a technology like this, often envying their React Native counterparts who have long enjoyed the benefits of over-the-air updates. Shorebird finally brings this capability to the Flutter world, potentially revolutionizing how we approach app updates and maintenance.

It's important to note some key aspects of Shorebird's implementation:

  1. Dart SDK Fork: Shorebird has forked the Dart SDK repository to implement their Code Push functionality. This fork allows them to teach Dart how to run modified (patched) code in an interpreter while still running all unmodified code on the CPU. This approach is crucial for enabling the Code Push feature while maintaining performance for unmodified parts of the app.

    Current Private Status: As of now, Shorebird's Dart SDK fork is private. However, the Shorebird team has stated their intention to make it public in the future. They also plan to work on upstreaming many of their changes as their team grows and the product matures.

    Future Transparency: The planned move towards making their fork public and contributing changes upstream demonstrates Shorebird's commitment to transparency and collaboration with the broader Dart and Flutter community. This approach may alleviate some concerns about using a closed-source modification of the Dart SDK.

While the current private status of the fork might be a consideration for some development teams, especially those with strict open-source requirements, Shorebird's roadmap towards greater openness is a positive sign. It suggests that as the technology matures, developers will have more insight into and potentially influence over the underlying mechanisms of Code Push in Flutter.

  1. Pricing Considerations: While Shorebird offers a free "Hobby" plan, which is excellent for small projects and individual developers, larger teams and enterprises should carefully evaluate the pricing structure. As your app grows and the number of patch installs increases, costs can accumulate. It's essential to factor these potential expenses into your project budget and weigh them against the benefits of rapid updates and improved user experience.

  2. Update Limitations: It's crucial to remember that Shorebird's Code Push functionality is limited to Dart code changes only. While this covers a significant portion of Flutter app development, it doesn't extend to native code or asset updates. Teams working on apps with frequent native code changes or asset updates will still need to rely on traditional app store update processes for those components.

  3. Compliance and Best Practices: As discussed earlier, while Shorebird complies with app store guidelines, it's vital to use this technology responsibly. Ensure that your use of Code Push aligns with the terms of service of both Shorebird and the app stores you're publishing to.

Despite these considerations, the introduction of Shorebird represents a significant step forward for the Flutter community. It offers a powerful tool for rapid iteration, bug fixes, and feature rollouts, potentially leading to improved app quality and user satisfaction. As with any new technology, it's important to thoroughly evaluate its fit for your specific project needs and development practices.

The Flutter ecosystem continues to evolve, and tools like Shorebird demonstrate the community's commitment to addressing developer needs. While it may not be suitable for every project, Code Push with Shorebird opens up new possibilities for Flutter developers, bringing us closer to the dynamic update capabilities that have been standard in web development for years.

As you consider incorporating Shorebird into your Flutter development workflow, weigh the benefits of rapid updates against the potential limitations and costs. Used judiciously, Code Push can be a game-changer for your app development process, allowing you to respond more quickly to user feedback and market demands.

Useful Resources

For those looking to dive deeper into Shorebird and its Code Push capabilities for Flutter, I recommend the following resources:

  1. Official Shorebird YouTube Channel: https://www.youtube.com/@shorebird Here you'll find regular updates, tutorials, and demonstrations from the Shorebird team.

  2. Video on Recent Updates: https://youtu.be/HVRRUY0f0ko This video provides an excellent overview of the latest changes in Shorebird's Code Push product. It's particularly useful for those who want to see how Shorebird's tools work and how updates are performed in practice.

  3. Official Shorebird Documentation: https://docs.shorebird.dev/ Here you'll find detailed guides, API documentation, and best practices for using Shorebird in your Flutter projects.

Tags:
Hubs:
Total votes 2: ↑2 and ↓0+4
Comments0

Articles