Why is this worth your time?
A Progressive web app is quite a new technology not many users know about yet. Publishing to a Play Store will make your app get a lot more installs. Publishing a PWA to the play store is really easy using Google’s Trusted Web Activities.
What is a Trusted Web Activity?
In Google’s words, Trusted Web Activities are a new way to integrate your web-app content such as your PWA with your Android app using a protocol based on Custom Tabs.
Native, Trusted Web Activity, WebView or just a PWA?
You might be confused as to what’s the best approach to creating a mobile App. As with almost anything, this largely depends on your use case. Here are some pros and cons of each of the approaches
- Native – This approach works best if you want your app to be very performant. But it also requires you to have a different codebase in a different language for each platform, multiplying cost and time requirements.
- Progressive Web App – This is the easiest one, especially when you use create-react-app or PWA builder. The only downside is that not many users know about PWAs yet since it is quite a new technology and your app will never get as big of a traction as it would get on a store.
- Trusted Web Activity – This requires the web app to be created by you, and you still have to meet the store guidelines. Requires just one codebase, but this doesn’t work on iOS.
- WebView – Using WebViews is really not worth it anymore – there’s many downsides to them compared to Trusted Web Activities. The only time it would make sense using it is when the content you want to display is not yours. But for that, you’d probably prefer using Chrome Custom Tabs.
Wrapping the PWA inside a Trusted Web Application
- After you’ve got your PWA built and want to wrap it inside a native app, you first need to clone this repository.
- After you’ve done this, open the folder you cloned the repository into with Android Studio.
- Next, open app/build.gradle file. This is how it should look like:
twaManifest, you need to update these three lines:
applicationId: change this to your application id.
hostname: change this to the url of your website. The website has to be HTTPS, but don’t put the
https://in the string.
name: change this to the name of your app
Everything else is optional and depends on your needs.
Now you can try to run your app inside an emulator or with a real device. After you run the app for the first time, it should work even when you’re offline.
Publishing to the Play Store
Now that we’ve done all of the above, we’re ready to publish our app to the Play Store.
- First, we need to build an apk, we do that by going into Android studio and going to Build > Generate signed Bundle / APK
- Generate a keystore if you haven’t already. You can generate it directly from android studio
- Now, we need to extract the SHA256 fingerprint from the keystore, we can do that with this command:
keytool -list -v -keystore path-to-keystore -alias twa -storepass your-password -keypass your-password
- Now we set up a Digital Asset Link, we can do that with this tool.
- Create a
.well-known/assetlinks.jsonfile and paste the output from the Digital Asset Link generator.
- Log in to your Google Play Console and create a new app
- Go to App releases > Production track > Create release and upload your apk.
There are four main ways you can make your app downloadable on Android. The best one is creating a PWA and then wrapping it with a Trusted Web Activity. This unfortunately doesn’t work on iOS at all, and iOS is not really PWA friendly when it comes to the homescreen. Right now, the best way to create an iOS app is using webviews or creating a native app.