[Wear OS General] bernarbernuli:
How to port Unity games to Wear OS

Hi, I thought it would be interesting to give visibility and revive an old tutorial, expanded with my own experience following it. The guide consists in converting games to Wear OS from games originally intended for Android Smartphones. These games must have been originally created in Unity, and therefore, you must have the game project in Android, read the section "Preliminary clarification for Non-Unity Developers".

Original sources of the guide:​

​

Unity3d to Android Wear!

Ok so finally i have been successful in porting a Unity3d project to a Moto 360! Step 1: Export the Unity project as a Google Android Proj...

aa-games.blogspot.com

​

and​

​

Unity To Android Wear

“The world of mobile devices is expanding…” Want to see a game created with this process? Check out ‘Combat Wear’ on google play. Like or comment on this and let me kn…

nicholasgorman.wordpress.com

​

I. What is Unity and what is it for?

Unity (formerly called Unity 3D) is a software that has everything you need to develop video games and also on various platforms (Windows, Videogames, Android, iOS and more). Unity has been used in countless Android games, in fact more than half of those hosted on the Play Store have been developed in Unity. Many developers prefer it over other similar engines because of its great potential, a few examples: Crossy Road, Hitman Sniper, ShadowGun: DeadZone, Alto's Adventure, Hearthstone, Mobius Final Fantasy, Reigns, Monument Valley 2, Ravensword: Shadowlands, Hexagonium, Pokémon Go. This link explains in more detail how to install Unity and first steps with the Software.​

​

Although Unity is not compatible with Wear OS it can be ported from android to Wear OS, this process is relatively simple thanks to the fact that Android devices and Wear OS watches use the same file type (.APK). Basically it would be to export your Unity game project to Android Studio, and from Android Studio create an APK file that would already be compatible with Wear OS.​

II. Preliminary clarification for Non-Unity developers

Although in the explanation of the original sources of the tutorial (which I put above) does not make it too clear, the guide is really aimed at game creators who have developed a game from the Unity engine for Android, and want to port your game to Wear OS. You would think that it would be enough to decompile any Android APK with tools like ApkTool to get the Unity project, i.e. the source code, but that I think is not enough.​

​

From my knowledge (almost null about Android and Wear OS app development) I think there is no tool (apkTool for example, decompiles only partially) or a generic guide that serves to completely decompile all APKs, probably each game or APK must follow a custom method to decompile it and that only experienced developers can do it. Without going into legal constraints, what do you think? Do you know of an effective method to decompile an Android APK so that Unity can interpret it as a project?​

​

However, if you want to try the guide you can do a search on Google or specialized Unity forums, you will probably find Android game projects in Unity available for download.​

​

III. The Guide. How to port an Android game to Wear OS?

Prerequisites.​

Download Unity from here (choose Unity Installer from the latest 2017 version for your operating system), start the installation and select among the components to install Android package. Once installed, register and choose personal license.

Download and install Java JDK tools from here. Unity requires JDK version 8 (1.8) (paid or via emule). You can also install OpenJDK as an alternative, which works as well.

Download and install Android Studio 3.0.1 from here. It is not the latest version, in fact it is a 2017 version, but as the guide was made with Android Studio 3 and the current Android Studio interface is very different I recommend this version.

​

Steps in Unity (Previous preparation for compilation).​

​

1. Run Unity, open your Android game project. If you don't know what the project refers to or you don't have a project read the section "Preliminary clarification for NON Unity developers".​

​

2. In the Unity editor go to Edit > Preferences > External Tools and set the location of the SDK and JDK tools installed on your computer. (Figure 1)​

​

3. Go to File > Build Settings > Android > Switch platform to select Android in the build configuration platform, then in "Build System" select "Gradle" and activate "Export Project" option, don't click "export" button yet. (Figure 2)​

​

4. Go to Edit > Project Settings > Player, and set a company name and product name. Then click on "Other settings" drop-down menu and under "Identification" type package identifier in "com.companyname.productname" (taking into account the ones you typed before the company and product name), then set "Minimun API Level" to "API level 19" (minimum to run Android Wear 1.0). (Figure 3)​

​

5. Go back to "Build Settings" from step 3 and click "Export", Android Studio package will be created.​

​

​

​

​

Steps in Android Studio​

​

6. Now open Android Studio software and create a new blank project. Put the app name and company name which should match the name you set earlier in Unity (com.companyname.appname) and click "Next". (Figure 4)​

​

7. In this window the target devices are set, select "Phone and Tablet" and in Minimum SDK select "API 19" and also select "Wear" and in Minimum SDK (for Wear) select "API 20", finally click on "Next". (Figure 5)​

​

8. Now the project design configuration is set, click "Empty Activity" for mobile devices and then click "Next", In the next window leave it as it is and click "Next" again. Click on "Blank Wear Activity" and then "Next", and finally "Finish". The compilation process will start and wait until it finishes.(Figure 6) (Figure 7)​

​

9. Now import the Unity build you created in step 5 in "File > New > Import Module" and click "Finish". Let Gradle finish synchronizing, you will probably need to download some Android Studio SDK tools. Finally the Unity project is imported into Android Studio.​

​

10. On the left side, open "Project" menu (Figure 8) (Figure 9). Now you must dissect the module you have imported from Unity and join its individual apps as follows:​

a. Delete MainActivity.java file from wear folder (wear > src > main > java > "com.companyname.productname" > MainActivity). (Figure 10)​

b. Copy/paste "unity-classes.jar" file (module > libs) into "Wear" platform (Wear > Libs). (Figure 11)​

c. Copy/paste assets folder, java folder and jniLibs folder (Module > src > main > assets and jniLibs) into "Wear" platform, under Wear > src > main. Leave the names as they are. (Figure 12)​

d. Next, copy/paste activity module (src > main > java > packageName > UnityPlayerActivity) into "Wear" platform (src > main > java > packageName). (Figure 13)​

​

11. UnityPlayerClass you just copy/paste should show some errors (red flags). To fix it go to Wear > Build.gradle and add the following in "dependencies" section. This will include all the files needed to run the game through Android Studio and create the build. (Figure 14)​

​

provided 'com.google.android.wearable:wearable:2.0.0'

compile files ('libs/unity-classes.jar')

​

12. After re-syncing the build, go to UnityPlayerActivity in "Wear > main > src > java > packagename > UnityPlayerActivity" and add the following to the top of the class below the rest of the imports (Figure 15):​

​

import com.unity3d.player.UnityPlayer;

​

13. This should fix all the problems, now go to "Wear" section and open "AndroidManifest.xml". You should set "Launcher activity" to "UnityPlayerActivity".​

​

​

​

​

​

Steps again in Unity​

​

14. Now in Unity, go to "Edit > Project Settings > Player", click on "Publishing Settings" dropdown menu and activate "Create a new keystore", type a password and confirm it, then click on "Browse keystore" and save the password. Then click on "Alias" button and select "Create a new key".​

​

15. In the next window at least Alias, Password and Organization must be filled in. Make up a relevant or funny name for the alias. You must enter the password you used before. Finally click on "Create key". Now you have a keystore, go back to "Settings Player" menu and assign alias key and set the password. This is a necessary step for Unity to allow to create the APK.​

​

16. Finally go to File > Build Settings and click "Build" to create an apk file. Send it to your watch and install the game.​

​

​

​

Considerations:​

In step 4, if you are creating a Wear OS 2.0 app you can change "Minimun API Level" later, from Android Studio. If you want to update the icon or anything else you can do it from Android Studio later. This just sets up the Android Manifest and gradle as your import.

In step 6, if you want to directly edit the company and app name you set up in Unity click "edit" button on the right side of the window.

After step 13 and before generating the apk you can test the operation of the game with the Wear OS emulator in Android Studio.

In step 14, make sure to save in a safe place the keystore, you will need it later when you generate a signed APK.

Once the game is compiled it could happen that the orientation goes haywire, and if the watch face is circular the image could be off the screen.

IV. Which Android games would be more "playable" on Wear OS?

It is true that playing with the watch is somewhat difficult, such a small screen greatly limits the movements however to be a fun experience should be a simple idea, casual games and include simple controls, games in which movements can be made with a simple touch or gesture by sliding a finger or several fingers across the screen, it would also be interesting to be controlled with the movements of the arm or wrist.​

V. Bonus. Compilation of all the games adapted to Wear OS

A reddit user compiled all the games for Wear OS that exist to date.​

​

https://www.reddit.com/r/WearOS/comments/qkjfqy
​

​

In several lists on the net they recommend these games among all those for Wear OS. Because of the obvious discomfort of playing on such a small screen, I personally don't play any of them on the watch, but here they are, for the knowledge of those who are interested.​

​

2048​

Infinity Loop​

PetQuest Virtual Pet​

Combat Wear ​

Hex - Anxiety Relief​

Wear Maze​

Snake for Wear​

General Knowledge Quiz​

Bubble Shootix​

Bugdroid Land​

Math it!​

Sookie Says ​

​