So now we need to build and install the application.
Remember, there are two parts,
the phone application and the wearable application.
Before, I mentioned that the wearable application
needs to be embedded into the phone application.
While this is required for distribution through Google Play.
it's actually possible to build and deploy them separately for testing.
So let's walk through how to build and deploy our new application for testing.
And then we can discuss the embedding later.
You'll notice here there are two Gradle projects, Mobile and Wear.
We can build and install each of these separately.
So make sure you connect up your phone now.
And ensure that the Android Debug Bridge is working properly.
Now select the mobile project, and click the green Play button.
This tells Gradle to run the Assemble Debug task.
Which compiles your code and makes an APK out of it.
Android Studio then installs it to your device or emulator.
We may need to select a device to install it to.
So select that, in this case, my Nexus 5.
And click okay to continue.
After waiting a minute or two.
You'll see the phone side of your application running on the phone.
This is exactly the same as what you would have done previously
when you learned Android programming.
Now to get to the important part,
building the wearable side of the application.
We now need to get your wearable paired up over ADB just like your phone.
Most Android Wear devices would come with a cradle, like one of these.
That allows you to connect to USB cable.
So we make sure we've got those connected up.
Also, you'll need to enable developer mode and usb debugging.
So you need to go to Settings, About, and tap on the Build number seven times.
Then you go to developer mode and enable USB Debugging.
Your wearable will ask you if you want to approve the permission request.
Once this is done, your wearable will be able to use ADB.
If you're a Windows user, I've provided a link in the instructor notes.
To some documentation that shows how to set up ADB for Android Wearable Devices.
If you have a wearable device that does not have a USB cradle.
You can also set up ADB over Bluetooth.
The instructor notes will have a link that has more information about what you
need to do that as well.
Now that we have the wearable device set up with ADB.
We need to build the Wearable project.
Let's select the Wearable Gradle project and click the green Play button.
This tells Gradle to run the assemblydebug task,
similar as before, but this time for the Wearable side instead.
Once it finishes building, Android Studio will prompt you for
which device to install the APK to.
Since there are now two devices connected by ADB.
It's very important that you pick the wearable device.
If you pick the wrong one, the app will not execute properly.
So we select the wearable, then we click okay.
Now you'll see the wearable activity appear on the wearable devices.
So that's how you can easily test and
debug phone and wearable apps from within Android Studio.
When you're ready to push the APK to your users via Google Play.
You'll need to do these steps a little differently.
You need to boot a release mode APK.
Which is different than a debug APK because it is signed with your
development keys to prove you built the APK.
You can start this process by using the build menu and
selecting generate signed APK.
Which uses the gradle assemble release task internally.
And this is how we go start that process.
Build, generate signed APK.
And then you can follow through by selecting the mobile project.
And at this point now, you need to provide all your key details.
And then continue through with the rest of the process.
I'm not going to go through that process right now though.
So let's just hit cancel to get back to where we were.
If you go to the mobile build.gradle file, like shown here.
You can see there's a property called wearApp at the bottom.
That references the ware gradle project.
This task tells gradle to embed the wearable APK into the phone APK.
You should note that this only happens in release mode.
When we did the testing earlier in debug mode.
There was no app embedding.
So it's important that you test your final APK in release mode
by installing it to a phone.
And checking that it syncs over to the wearable correctly.
If you make a mistake with any of the wearable packaging steps,
it'll fail to install in the wearable.
By the way, if you're trying to debug packaging installation problems.
You can use adb logcat and search for
the process WearablePkgInstaller on the phone and wearable side.
Which will tell you what the problem is.
Oh and one more thing.
I mention build.gradle files, but did not go into much detail on them.
For many cases you won't need to edit these very often.
But if you want to learn more.
We have a whole class on Gradle that teaches you everything you need to know.
About dealing with dependencies and Multiple Build Flavors.
For a link check the instructor notes.