Unity Android
To make these instructions concrete, we have created a sample cross-app wallet called Rapidfire ID. To interact with it, you can find its SDK in the NPM package directory: @rapidfire/id.
You can check out the GitHub repository for Rapidfire Wallet to learn how to create your own wallet.
This guide will walk you through adding support for any cross-app wallet into a Unity app by integrating the Mobile Wallet Protocol.
On Android, we use Chrome Custom Tabs (if available) to seamlessly connect gamers to your Openfort wallet from within the game.
Setup#
Follow the setup guide.
Running instructions#
UNITY VERSIONS BELOW 2021.3
To check if Chrome Custom Tabs are available, older Unity versions may require a specific Gradle plugin version. For example, on Unity 2019.4, you must upgrade from 3.4.* to 3.4.3 (see Android's blog post):
- In Unity go to Build Settings -> Player Settings -> Android -> Publishing Settings -> Enable Custom Base Gradle Template under the Build section
- Open the newly generated Assets/Plugins/Android/baseProjectTemplate.grade file
- Update classpath
com.android.tools.build:gradle:3.4.0
to classpathcom.android.tools.build:gradle:3.4.3
- In Unity go to Build Settings -> Player Settings -> Android -> Publishing Settings -> Enable Custom Main Manifest and Custom Main Gradle Template under the Build section
- Open the newly generated
Assets/Plugins/Android/AndroidManifest.xml
file. Add the following code inside the<application>
element:
_10<activity_10 android:name="com.openfort.unity.RedirectActivity"_10 android:exported="true" >_10 <intent-filter android:autoVerify="true">_10 <action android:name="android.intent.action.VIEW" />_10 <category android:name="android.intent.category.DEFAULT" />_10 <category android:name="android.intent.category.BROWSABLE" />_10 <data android:scheme="mygame" android:host="mobile-wallet-protocol" />_10 </intent-filter>_10</activity>
Make sure that android:scheme
mygame is the same as Custom Scheme
(mygame:// in this case)
- Open the newly generated
Assets/Plugins/Android/mainTemplate.gradle
file. Add the following code insidedependencies
block:
_10implementation('androidx.browser:browser:1.5.0')
For this version of the Chrome Custom Tabs to work, the compileSdkVersion must be at least 33. This is usually the same value as the targetSdkVersion, which you can set in Build Settings -> Player Settings -> Android -> Other Settings -> Target API Level.
Proguard
If you enable Minify in your project settings, you will need to add a custom Proguard file to your project.
- In Unity go to Build Settings -> Player Settings -> Android -> Publishing Settings -> Enable Custom Proguard File under the Build section
- Open the newly generated Assets/Plugins/Android/proguard-user.txt file. Add the following code inside the
<application>
element
_10-dontwarn com.openfort.**_10-keep class com.openfort.** { *; }_10-keep interface com.openfort.** { *; }_10_10-dontwarn androidx.**_10-keep class androidx.** { *; }_10-keep interface androidx.** { *; }