Jump to content
  • Advertisement
  • entries
    44
  • comments
    19
  • views
    2412

Day 35 of 100 Days of VR: How to Run Google Cardboard on an Android Device in Unity

Josh Chang

724 views

Yesterday we looked at how we can work with VR and went through the basic demo and understood how everything worked.

Today, we’re going to look at how we can install our game directly into the phone.

To do everything today, we need to have:

  1. A phone that supports Android Level 19 (Kit Kat)
  2. A USB to Micro-USB (or Type-C for newer devices) cable
  3. (Optional) Google Cardboard

Today we’re going to:

  1. Install the Android SDK so we can build and run our app
  2. Install a USB driver for our computer to detect our phone
  3. Set up our phone to be in developer mode
  4. Build and Run the demo app into our phone

With all that being said, let’s get started! Today we’ll be following Unity’s Android SDK setup guide

Step 1: Install the Necessary Android Software

Since we’re building our VR app for Android applications, we need the required software to compile, build, and run our app on our phone.

  1. Download and install the latest Java SDK to run Android Studio
  2. Download and Install Android Studio
  3. You might have to restart your computer first for your computer to recognize the new Java SDK that you installed.

When we’re done downloading and installing Android Studio (which will take a LONG time), we want to open the SDK Manager.

opening-up-sdk.png

In our new project, we can find our SDK Manager under Configure.

Now we’ll get this:

launch-sdk-manager-1024x711.png

Under SDK Platform, select the platform we want to support, in this, case it’s Android 4.4 for Cardboard and Android 7.0 for DayDream, however, I believe if you install the newest version that’ll work for both.

Under SDK Tools, install:

  • Android SDK Platform-Tools
  • Android SDK Tools
  • Google USB Driver if you have a Nexus device

With all of this, we should now have everything we need to be able to build our game into our Android device.

Step 2: Install a USB Driver to Detect our Phone

The next part (and probably the part I hate the most) is installing a USB driver that allows our computer to detect our phone.

  1. Go to Google’s documentation on where to find the appropriate OEM USB driver for your phone and install it.

With any luck, your computer should be able to successfully recognize your phone when you plug it into your computer.

If not, then I refer you to Google this problem as there are too many possibilities of what could have gone wrong.

Step 3: Change Your Phone to Developer Mode

Now our computer can connect to our mobile device, the final thing we need to do is have our phone be in developer mode so Unity (or Android) can create the app and install it on our phone.

The instructions to enable Developer Mode varies depending on what your phone is. A quick Google search should give you what you need to enable it.

However, the most common approach these days is to:

  1. Go to Settings > About phone > Build Number
  2. Click build number 7 times to enable Developer Mode

Now under Settings, you should find Developer options.

  1. Go into Settings > Developer options and turn on USB Debugging

Hopefully, with this step completed, we can finally move on to our configurations in Unity!

Step 4: Configuring Unity to Build and Run our Android App

Now that our phone is ready, it’s time to finally build our game into Unity.

  1. Make sure that your phone is connected to your computer
  2. In Unity go to File > Build & Run to create an APK file (our app) that will install it on our computer

That’s it. Now in the perfect world, that’s it, we’re done. Enjoy our VR game!

Unfortunately, there are always problems that we would encounter:

  1. Your API is at the wrong level.
  2. You’re missing a Bundle Identifier
  3. Failed to compile resources with the following parameters: major version 52 is newer than 51, the highest major version supported by this compiler.

The 1st and 2nd problem can be resolved easily.

The first problem is because we need to make sure that we create a minimum version of Android devices that have the software we need to run our VR application.

  1. In Player Settings under Other Settings… in Minimum API Level select API Level 19 for Google Cardboard support and API Level 24 for Google Daydream. If you choose API Level 24, just make sure that your phone can run Daydream!

For the second problem, every Android app has a unique identifier that Google uses to identify the app. The error that we’re getting is that Unity is telling us that we’re using the default one and we should change it.

  1. In Player Settings under Other Settings… in Package Name change the string to be something else. Just make sure you follow the convention of <companyname>.<appname>. In our case, it doesn’t matter what it is, we can put anything we want.

Now for the third and final problem. This one more interesting. Most likely your error is something like this:

Failed to compile resources with the following parameters:

-bootclasspath "C:/Users/JoshDesktop/AppData/Local/Android/android-sdk\platforms\android-24\android.jar" -d "C:\Users\JoshDesktop\git\Cardboard\Temp\StagingArea\bin\classes" -source 1.6 -target 1.6 -encoding UTF-8 "com\google\android\exoplayer\R.java" "com\google\gvr\exoplayersupport\R.java" "com\google\gvr\keyboardsupport\R.java" "com\google\gvr\permissionsupport\R.java" "com\google\vr\cardboard\R.java" "com\google\vr\keyboard\R.java" "com\Josh\Chang\R.java" "com\unity3d\unitygvr\R.java"

warning: C:\Users\JoshDesktop\AppData\Local\Android\android-sdk\platforms\android-24\android.jar(java/lang/Object.class): major version 52 is newer than 51, the highest major version supported by this compiler.

It is recommended that the compiler be upgraded.

warning: C:\Users\JoshDesktop\AppData\Local\Android\android-sdk\platforms\android-24\android.jar(java/lang/AutoCloseable.class): major version 52 is newer than 51, the highest major version supported by this compiler.

What all of this is saying is that our Java is out of date and we need to have at least Java SDK 8.52.

In my case, I previously had 8.51 installed and when I installed version 8.52, Unity didn’t pick up on the changes.

To fix this:

  1. Go to Edit > Preferences > External Tools under Android, select JDK and choose the path to your newest JDK file. For me, on my window machine, it was located at C:\Program Files\Java\jdk1.8.0_152

With all of this done, hopefully, you should be able to successfully build and run the GvrDemo on your phone + Google Cardboard if you have one.

Conclusion

Hopefully, this was a useful guide to getting your Android device set up to play the scene. Leave a comment if you run into problems and I’ll try to help and update this article with any new information.

On a different note, it’s truly amazing playing with VR on our own mobile device. Just playing the VR game from Unity was interesting, but words can’t describe how much more realistic and interesting it becomes until you strap your phone onto your face!

I think at this point, we have a good understanding of the basics and what is and isn’t possible with the Google Cardboard now.

Tomorrow we’re going to look and see how we can incorporate the VR SDK into our simple FPS game to see how our game fairs in VR!

Day 34 | 100 Days of VR | Day 36

Home

 



0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Advertisement
  • Blog Entries

  • Similar Content

    • By jb-dev
      This is how loading screens will look like. I still have no idea whenever or not I could show things like tips or anything alike...
    • By Tanzan
      Hello  all,
      I just finished my first Android game and published it on Google play...
      I know its not the next red dead redemption2 but it would be nice to have some comments/feedback on it if its worth it to go on with a release 2.0. or move on to the next game? (red dead redemption 3  )
      Anyway thx for your reading time and i hope on some nice reviews!
      https://play.google.com/store/apps/details?id=com.gamlex.android.games.typomania
      Regards,
       
      Tanzan
       
       
    • By chiisa
      Hello.
      My friend asked me to join a small game project of her which I think was not quite worth to make since it consist only three stages and two routes. Also, the game play types are different each stages so it may need big effort to code. The game is actually a visual novel with more game play than scenario, but both of them are too simple, I guess. The only interesting part is she is trying to show off traditional culture, but it feels a bit forced. However, she disagreed with me and was very sure that this project would work. She gave me this pitching presentation and she said it's okay if I post it for a feedback. So, how do you think?

    • By Dimitri Lozovoy
      The mobile editor for Voxyc, a voxel-focused open-source game engine in development, can now edit 3D scenes on Android. Right in the app, you can create voxel chunks and combine them with models and sprites. You can import files right from the menu and then assign textures, move and resize them with a few button presses. All imported objects can be animated with Lua scripts. The resulting scenes can be used in games created with Voxyc, but since the project is open-source, export to other formats and engines can be and are expected to be developed.
      The app is one of the first that allows level creation on the go. You can work wherever inspiration strikes. Any dull moment can now be used productively, which is important for small indie teams that lack resources or work after-hours or on weekends. Using your device's camera to make textures and inserting them right into the scene is also convenient. The app is aimed at people who work on games independently and, perhaps after having already spent hours at their desk job, do not wish to be tied down to a chair and monitor. I find that using the app on a tablet is most convenient.
      Although the engine and the editor have come a long way in the last year, at this time, I am the only developer on the project. The editor and the engine are still missing some essential features, and I am looking for developers with whom I can share code. The codebase is cross-platform C++ and target platforms are Android, iOS, Windows, Mac, OpenVR, GearVR, Daydream and others.
      Voxyc editor for Android on Google Play
      Engine source code on GitHub
      Gamedev project link

      View full story
    • By Dimitri Lozovoy
      The mobile editor for Voxyc, a voxel-focused open-source game engine in development, can now edit 3D scenes on Android. Right in the app, you can create voxel chunks and combine them with models and sprites. You can import files right from the menu and then assign textures, move and resize them with a few button presses. All imported objects can be animated with Lua scripts. The resulting scenes can be used in games created with Voxyc, but since the project is open-source, export to other formats and engines can be and are expected to be developed.
      The app is one of the first that allows level creation on the go. You can work wherever inspiration strikes. Any dull moment can now be used productively, which is important for small indie teams that lack resources or work after-hours or on weekends. Using your device's camera to make textures and inserting them right into the scene is also convenient. The app is aimed at people who work on games independently and, perhaps after having already spent hours at their desk job, do not wish to be tied down to a chair and monitor. I find that using the app on a tablet is most convenient.
      Although the engine and the editor have come a long way in the last year, at this time, I am the only developer on the project. The editor and the engine are still missing some essential features, and I am looking for developers with whom I can share code. The codebase is cross-platform C++ and target platforms are Android, iOS, Windows, Mac, OpenVR, GearVR, Daydream and others.
      Voxyc editor for Android on Google Play
      Engine source code on GitHub
      Gamedev project link
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!