Nowadays making a web view app is the fastest way to convert a web into an Android Mobile Application. But we view application contains a lot of deficiency to run the website’s functions as a Mobile Application.
For Example-
- Push Notifications
- Web Bluetooth
- Web USB
- Many others
But We have another best option to deploy a Website into Mobile Application which is TWA/PWA – Trusted Web Activity. So in this article, we are going to teach you how you can easily Build a TWA / PWA application for all types of websites and Foodomaa – Multi-restaurant Food Ordering, Restaurant Management, and Delivery Application.
Step 1: Set up a TWA
Create a new TWA project in Android Studio
-
- Open Android Studio and click on Start a new Android Studio project.
- Choose Add No Activity
- Configure your project:
- Name: name of your application
- Package Name: an identifier for Android Applications on the Play Store must be unique, I suggest using the URL of your PWA in reverse order (eg. com.codeyon.com)
- Save location: where your project will exist on your machine
- Language: you will not write any Java code (leave a default Java)
- Minimum API Level: API 19 (required by the support library)
- do not select any checkboxes (no Instant Apps nor AndroidX)
Add TWA Support Library
- Add Jitpack configuration – build.gradle (Project: Codeyon) – this is the Project level build.gradle. This allows us to add a dependency in the second file.
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
...
}
}
- Add required dependency – this is the Module level build.gradle
// build.gradle (Module: app)
dependencies {
...
implementation 'com.github.GoogleChrome:custom-tabs-client:a0f7418972'
...
}
- Enable Java 8 – TWA library uses Java 8 features we also need to enable Java 8. To do that we need to add compileOptions as below:
// build.gradle (Module: app)
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
...
}
- Add manifestPlaceholders – variables that will be used in the next step when configuring our TWA
// build.gradle (Module: app)
android {
...
defaultConfig {
...
manifestPlaceholders = [
hostName: "yourdomain.com",
defaultUrl: "https://yourdomain.com",
launcherName: "Your app name"
]
...
}
...
}
Add TWA Activity
When required dependency and variables are there, we can continue and set our TWA up. We do that by editing Android App Manifest.
When creating a project we selected Add No Activity option, because of that our manifest is empty and contains only the application tag.
<!-- manifests/AndroidManifest.xml -->
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="yourpack.name.here">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="${launcherName}"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="android.support.customtabs.trusted.LauncherActivity"
android:label="${launcherName}">
<meta-data
android:name="android.support.customtabs.trusted.DEFAULT_URL"
android:value="${defaultUrl}"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:scheme="https"
android:host="${hostName}"/>
</intent-filter>
</activity>
</application>
</manifest>
Step 2: Verify relationship between the website and the app
Establish application to website relationship
// build.gradle (Module: app)
android {
...
defaultConfig {
...
manifestPlaceholders = [
...
assetStatements: '[{ "relation": ["delegate_permission/common.handle_all_urls"], ' +
'"target": {"namespace": "web", "site": "https://yourdomain.com"}}]'
...
]
...
}
...
}
<!-- manifests/AndroidManifest.xml -->
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="${packageId}">
<application>
...
<meta-data
android:name="asset_statements"
android:value="${assetStatements}" />
...
</application>
</manifest>
Establish website to application relationship
- hosting site domain – our PWA url (eg. https://yourdomain.com/)
- app package name – our TWA package name (eg. yourpack.name.here)
- app package fingerprint (SHA256) – unique SHA256 that is generated based on Google Play Store keystore
- In the Android Studio go to: Build → Generate Signed Bundle or APK → APK
- Use existing keystore (if you already have one) or Create new…
- Fill the form (remember the credentials as those are the credentials that the application will be signed with, they confirm your ownership of the application)
- Select type of bundle (release as we want a production bundle) and signature versions
After creating our keystore we can use it to generate required app package fingerprint (SHA256). This file is extremely important as it works as a proof that you are the owner of the application.

[{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "yourpack.name.here",
"sha256_cert_fingerprints": ["8A:F4:....:29:28"]
}
}]

Step 3: Get the required assets
- Icons with following dimensions: (48 x 48, 72 x 72, 96 x 96, 144 x 144, 192 x 192) or adaptive icon
- Google Play Store logo – image – 512 x 512 32-bit PNG (with alpha)
- Google Play Store banner – image – 1024 x 500 JPG or 24-bit PNG (no alpha)
- Few screenshots from the application for phone and tablet
Step 4: Publish to Google Play Store
Let’s go to the last step and finally push our app to the store.
Using the APK generated before (you can find it in your AndroidStudioProjects folder (eg. AndroidStudioProjects/Wordguru/app/release/app-release.apk) we need to go to the Google Play console where we can publish our application. I will not describe the process of publishing an application in the store as the wizard makes it pretty straight forward and we are guided step by step during the process.
After the release it may take a few hours for the application to be reviewed and approved, only then it will finally appear in the store’s applications list.
Summary
That’s it! We just pushed our PWA to the Google Play Store. The process is not as intuitive as we would like it to be, but still, with a bit of effort it is doable, and believe me, it gives that great feeling at the end when you see your app being available at Google Play Store.
It is worth pointing out that this feature is in the very early phase and I would consider it experimental for some time. I would not recommend going with the production release of your application for now. It works only for users with Chrome 72 and above (everything below will be able to install the app, but the app itself will crash instantly, not the best user experience I guess). Also, the official release of custom-tabs-client does not support TWA yet (that is why we used raw Github link instead of official library release).

Comments are closed.