Setting up a new app in Crashlytics without the IDE plugin
I like Crashlytics. I like the service they provide: their crash logs have saved my ass countless times. I also like that it's free.
However, there is one problem I've run into time and time again: getting new apps setup with it. They have a plugin... but you're probably not here because it worked.
For your reference (and mine), here's how you get Crashlytics setup with a new project. Just the code, no fluff.
-
Add the Crashlytics plugin to your build.gradle:
buildscript { repositories { // 1. Add the Crashlytics Maven repository maven { url 'http://download.crashlytics.com/maven' } } dependencies { // 2. Add the Crashlytics plugin to your dependencies classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+' } } apply plugin: 'com.android.application' // 3. Apply the Crashlytics plugin after the Android plugin apply plugin: 'crashlytics' repositories { // 4. Add the Maven repository maven { url 'http://download.crashlytics.com/maven' } } dependencies { // 5. Add the Crashlytics SDK to the Android project compile 'com.crashlytics.android:crashlytics:1.+' }
-
Make sure your app has INTERNET permissions in
AndroidManifest.xml
:<manifest> <uses-permission android:name="android.permission.INTERNET" /> <!-- ...The rest of your junk... --> </manifest>
What, did you think Crashlytics would work without internet access? :P
-
Add your API key as metadata inside the
<application>
tag inAndroidManifest.xml
:<application> <!-- ...All your activities, services, etc... --> <meta-data android:name="com.crashlytics.ApiKey" android:value="YOUR_KEY_GOES_HERE" /> </application>
To get your API key, go to this link, then click on the organization you want the app to be in:
Get your API key here:
-
Call
Crashlytics.start()
inApplication.onCreate()
:public void onCreate() { super.onCreate(); Crashlytics.start(this); }
-
(Optional) Add this line to your version control's ignore file (e.g., Git's
.gitignore
):com_crashlytics_export_strings.xml
Though not strictly necessary, doing this avoids committing unwanted files into your repository.
-
Launch your app. If all went well you should see it on your dashboard shortly.
Congratulations, you're now ready to use Crashlytics without ever having to install a plugin!
Thanks to @niftynei for both inspiring and proofreading this post.