DAN MILLER: My name is Dan Miller.
I work for Unity Technologies as an XR evangelist.
So I mostly focus on AR and VR.
But I've done a lot of mobile game development in the past
and built a lot of Android applications.
And what I want to do today is talk a little bit
about some best practices for Unity development
inside the Android ecosystem.
So there's going to be some fairly kind
of basic or easy wins, as well as talking about things
you can do, and how to understand and start
some of the debugging process, as well as some newer
features and things that are maybe still
a little bit in early access.
And if you are publishing your game in the near coming months,
you'll see some of these things starting
to come out, and just some strategies that you can take
advantage of as a developer.
So before I get started, I want to ask
how many people have heard of Unity,
or are aware of the Unity editor or engine.
All right, lots of hands there.
So if you're not aware, Unity is a piece of software
or a tool for writing interactive applications.
And we've done a lot of work to make
it very easy to develop and create your games
and publish them to stores, like the Google Play Store.
There's actually integrated settings
in the publish settings so you can
set up a lot of your things, build out your APK,
and push it up right away.
All right.
And so what I want to do first is just
go through what I call some easy wins.
Some basic techniques to consider
when publishing and developing your application
within the Unity editor.
Next, I'm going to talk about ADB, the Android Debug Bridge,
how you can set that up, and how you can utilize
that to get some information about what's actually happening
with your application running on Android back to your PC.
And after that, I'm just going to talk a little bit
about reducing the APK size on your application
so that you can make it easier for users
to get a hold of your app, try it right away,
and not have to wait for a long download time
or downloading it over something like Wi-Fi.
All right, so let's start with some easy wins.
The first thing I want to talk about is just texture atlasing.
And what this is is it's really common in 2D development
where you pack all of your sprites
together in a single texture.
What this allows you to do is reduce draw calls.
And you can then kind of split it up
to use different little sprite sheets
for each individual sprite, but have them all packed here
on a certain texture.
And while this works really well for 2D,
it's also pretty common to do it for 3D as well.
You can see there's two little bug creatures here.
One's more of a dragonfly, and one's a ladybug.
But they're actually using the same texture here
and just referencing different parts of it.
So when you're creating things like 3D assets,
you can consider laying out the UVs on a shared UV sheet here,
and then reference the same texture to, again,
just reduce draw calls, and optimize your application.
Now, the other thing to consider is
how you're compressing your textures,
and what sort of shaders you're using to render your 3D models.
And again, this is more on the 3D side,
but does apply a little bit to 2D.
So one thing to keep in mind is right now,
inside the Unity editor, the standard shader
is PBR, or Physically-Based Rendering.
And this is meant to reflect the lighting conditions
and features in the real world.
We have reflective surfaces that are
able to reflect the environment around them,
similar to what we have that exist in the real world.
Things like different lighting settings and stuff like that.
Now, depending on what sort of application you're making,
or what sort of stylistic choice you're making with your models,
it's not always really appropriate to have these PBR
materials and have all these different options for what
you need.
You can see here that these two bugs are a little bit more
stylized or cartoon-like, so it doesn't necessarily
make sense to have them fully going
through the processes that's required to render them based
on physically-based properties.
So what I've done here is I actually
have two different materials that are backed-- one
by the standard shader, and one by a much lighter shader here.
And you can see the settings here.
And even without fully understanding
what's happening at the shader level,
you can easily see the contrast between the differences
of the instructions or the maps that are associated with this.
And you'll see here on one side we have just a simple texture
assignment.
And on the other, while we have that texture assignment,
we also have all these different settings.
But I haven't actually adjusted them all at all.
And if I go back there, you can almost
barely see a difference between how
the lighting and the rendering is set up here.
So something to really keep in mind, depending
if you're using 3D models and the actual stylistic approach
that you want to your assets, is just
considering using a more lightweight shader
or a mobile-optimized shader.
So within Unity in the material settings,
you can actually drop down, choose the shader that's
backed for that material.
And there is a specific mobile one as well.
So really consider this when setting up your 3D models.
And the last thing-- and this is something that's kind of unique
to the Android platform--
is, within the Unity editor, in the application namespace
and API, we actually have an is genuine check.
And what you can do here is, in your code,
you can go and check if the APK is genuine.
And what it means to be genuine is
if it is directly downloaded from the Google Play Store
and has not been altered.
Now, we all know that APK can be fairly easily distributed.
And this is really helpful for testing or letting
your buddy try out your game before it's released.
And what you can do in your app is
that you can use this is genuine check
to potentially restrict some features or things like that.
So you could restrict access to the in-app store
that's in your thing.
You could also restrict access to maybe certain levels
or something if the is genuine check is not passed.
Now, something to keep in mind is that this
is a fairly expensive call.
So if you are using it, consider using it at a single point
before you kind of show different features
or applications.
And don't try to call this every frame, as that
will get pretty expensive.
All right, and now I just want to dive a little bit
into debugging.
And this is kind of a process that I go through when
developing any apps on Android.
It is a little bit more rudimentary
but kind of helps you get a base start
to understand what's going on and how to integrate this.
And so for this, I use ADB.
So ADB is the Android Debug Bridge.
And what it is is it's basically a robust command line
tool that allows you to link in directly
to your Android device.
You can do this through USB by just plugging it
into your device, opening up the ADB console,
and then there's a lot of associated commands,
as well as flags that you can use to get information back.
Now, one thing to keep in mind is that ADB gives you
a lot of information back.
And if you're not using any filtering,
it'll be hard to even really read or understand what's
happening, as information just continually flies through
in the console itself.
So what can you do for this?
Well, you can actually set a specific Unity flag.
But again, I just want to kind of highlight here
that, as a developer, when you're connecting
your device via ADB or via your computer,
you can do it the USB.
And if you're using a more modern phone,
one thing to keep in mind is that you will need to unlock
and look at your phone and actually allow
those USB debugging.
And that's an option in the developer settings.
So if you guys are developing for Android,
hopefully your Android device is already in developer mode.
And there's a little checkbox there
for allowing USB debugging.
And then from here, you can connect it to your computer,
and then start hooking up ADB and getting some information
back.
It is also available via Wi-Fi.
And you can do this via the connected editor
in the console window within Unity.
So as I mentioned, there's actually a flag or a callback
here.
And you can do a -s Unity.
And that will give you specific callbacks
from your app running in Unity.
So here I just have a small, little debug
log that every time I change the orientation from portrait
to landscape, it just outputs a debug message
within my console in the app.
And as I'm running this on my phone, and as it's connected,
you can actually see these callbacks through ADB.
Now, it'll also output things like errors or null reference
exceptions, which, if you've developed a lot of applications
in Unity, you know you always get those a lot
where certain things aren't hooked up,
or certain things aren't initialized before you're
trying to call them.
And you can get that information back via ADB.
So you can start tracing and understanding
where those issues are coming from.
All right, and now what I want to do
is talk a little bit about reducing the size of your APK.
So within Unity, and just really when
building any sort of application,
especially in the mobile ecosystem,
you know that how fast your user can actually
play and experience your game is crucial in getting
them to be retained and continue to play it.
And so part of this is a strategy for delivering
a small APK, or a small application,
that they can get started with right away,
they can download not over Wi-Fi,
and they can really just start experiencing.
So for this, there's a couple different strategies
both built into Unity and the Google Play Store.
And I want to talk about how you, as a developer,
can start taking advantage of those.
All right, so the first one is splitting the APK
by target architecture.
Now, this is a little bit of a newer function.
So it's available in the latest version of Unity in 2018.2.
So that's the latest stable release, available now.
And what it allows you to do is it
allows you to check which APK target architectures
you specifically want when you build out your app.
Now, the Play Store actually allows
you to upload different versions of the APK
for all these target architectures.
And then, depending on what device
you're on and what target architecture it has,
it will actually download these separate APKs.
Previously, inside Unity, when you would package up an APK,
you would target certain architectures,
and it would all kind of be combined
into a single APK, which ended up bloating
your size a little bit.
So this is just an easy win where you can separate things
out, and it'll output different APKs depending
on which checkboxes you hit.
This is also a step towards compliance
with things like the new Android P,
as well as just from requirements
as you start to build out your apps.
The other thing that's supported is
something called APK expansion files, or OBB.
And what this is is this is a way
to build a base unit of your game--
think of something like the main menu and the first couple
levels--
and then actually split it up into what
we call expansion files, which are
downloaded alongside your game.
And again, this is a way for your users
to download your application right away,
and then start feeding in the necessary data to then
experience later levels.
If someone downloads your app right now,
they might just want to play the first couple levels
and not have to wait for the entire thing to download,
or the entire size of your APK.
So how do you take advantage of this within Unity?
Well, there's a small checkbox there to build out
these OBB within the publish settings under player settings.
Once you build this out, it will actually, again,
kind of separate your APK.
And through the Google Play Store,
you can upload these alongside of it.
Now, because Android is more of an open ecosystem,
you do have to be careful about users deleting these OBB files.
And you can't really restrict them
from cleaning up their phone, deleting some things
to try to clear up maybe space for another app
or something like that.
So it is required that, if you do this,
you actually provide a way for the user to re-download
these files within your app.
So how do you do this?
Well, Google provides some documentation
on how to actually integrate it on their side of things
for native applications.
And on the Unity side, if you guys just
all want to take a picture of this exact function
and call back.
And I was just kidding on that.
There's actually an asset store package
here that we've written that allows you to easily go
and integrate that extra download that's
required if you do split up your application using these OBB
files.
So again, this is a setting built into Unity
to split up your app in order to have
the main part of the game, something
like the main menu and the first couple levels,
and then expansion files that complete
the rest of your application.
And the real goal here is to try to get
under that 100-megabyte limit so that your users are not
required to download your app via Wi-Fi.
And so this, you can see, is just the Google Play OBB,
and it's free on the Unity asset store, which
just has this little code snippet here,
as well as some sample scenes and examples that
allows you to then put a button into your app, which
is a requirement for the Play Store when using that.
All right.
And now I want to talk a bit about Google Play Instant.
So this was mentioned in a lot of previous talks,
and it's something that I think is really exciting
and kind of what's possible in coming in the future.
So Google Play Instant is a way for users
to try out your game even quicker
it's a smaller, bite-sized experience that
may be something like a single level,
or really a taste of what your full application and game can
be.
And how do you start to integrate this,
or how do you build this within Unity?
Well, Google's actually made a plug-in.
It's still in beta.
But the cool thing you can see here
is that it's very actively being worked on.
I think this release--
says here that it was really something like four days ago.
That was actually four days ago.
So eight days ago, this plug-in was updated and released.
And it's really being actively developed.
And it is kind of a special part of the store
right now, where you can give your users access to it.
Now to integrate this and use this within Unity,
there is a lot of additional steps and setups
that you need to go through fairly carefully.
But Google has done a really good job
of providing a menu here.
And it actually walks you through the required steps.
You drop down the Google Play Instant.
You can actually build to the Instant architecture,
and then run that on your device.
And it gives you this small, little sample of your app
and packages it all up for you.
So this is directly integrated into Unity.
So you can start taking advantage of it now
and build these instant play apps.
And that's pretty much it for my talk, so thanks a lot.