Join Kevin Ford for an in-depth discussion in this video Add crash reporting to your native Android app, part of Visual Studio App Center for Developers.
- [Instructor] And now we'll add VSAC analytics and crash reporting to a native Android application. Android Studio uses Gradle to pull the external dependencies. To add the dependencies to Gradle, we want to look at the build.gradle file for the app module. So we'll open up Gradle scripts and the build.gradle file that has module app next to it is the one we want so I'll open that up. And we're going to scroll down to the bottom where it has dependencies and this is where it's pulling in external dependencies. And the first thing I want to do is define a variable and we're going to call that appCenterSdkVersion and we're going to set that equal to 1.1.0 and this is going to make sure that all our dependencies that we're pulling in for app center are using the same version.
So let's pull in the first one so I'll go compile and space and it's com.microsoft.appcenter and then a colon and appcenter dash analytics and then a colon again dollar sign and then in curly braces we're going to use our appCenterSdkVersion.
And then I'm going to take that line and I'm going to put it in the clipboard and I'm going to copy it and paste it onto a new line and instead of analytics, what we're going to pull in this time is crashes for crash reporting. And I'm just going to make sure that Gradle file is saved by going file, save all, and you see a message at the top that the Gradle files have changed and there's an option to the right to sync now and this will pull in these two new external dependencies that I've added so I'm going to do that so I'll click sync now and we see at the bottom left that the Gradle build is finished.
Now we need to initialize our crash reporting analytics and we can do this directly in the main activity that's created by default. So we're going to go under app and java and our main project and look at the main activity. And then here I'm going to add some import statement so I'll open up the import section and the first one is import com.microsoft.appcenter and AppCenter, then put a semicolon and also an import for com.microsoft.appcenter and once again analytics and analytics.
Finally, import com.microsoft.appcenter.crashes and crashes. In the initialization call, we're going to put in our onCreate method. So we'll do that right after the setContentView so we'll add a couple new lines and we'll go AppCenter and start and we'll pass it our application object so it's getApplication and colon and then we're going to use our app secret or known as the API key so I'll just put in a quote quote for now then a comma and enlist the services that we want to start so we're going to start analytics.class and also we're going to do crashes.class.
So for that app secret, we can grab that directly out of the portal in VSAC. So we're going to go over to the Visual Studio App Center portal and open up our native Android application and under the getting started section, we can scroll down and grab the app secret right here. Now it's also interesting to notice they give you a cheat sheet for how to add all this code in here as well. So if you forget how to set this up, you can always go to the getting started area and see the code directly here and paste it directly into your application.
So we're going to go back to Android Studio. And in Android Studio where we have that quote quote for the app secret, we're going to paste it in. And I'm just going to make sure this file is saved by going to file and save all.
- Adding applications to the VSAC
- Using custom build scripts
- Creating iOS and Android builds
- Creating UI tests
- Automating tests
- Distributing apps
- Examining crash logs and analytics
- Adding push notifications
- Using CodePush for deployments