Install Shake

This page describes how to install the Shake SDK into your Android application via Gradle. Whether you are using Java or Kotlin, you can follow the steps below.

Add Maven repository to your top-level build.gradle file

build.gradle
allprojects {
repositories {
maven { url 'https://dl.bintray.com/shake/shake' }
}
}

Add Shake dependency to your app-level build.gradle file

build.gradle
dependencies {
implementation 'com.shakebugs.android:shake:'
}

Optional  If you use ProGuard optimizer, you have to add this rule
proguard-rules.pro
-keep public class com.shakebugs.shake.internal.data.** {
public protected private *;
}

Add Client ID and Secret to AndroidManifest.xml as metadata

Open your AndroidManifest.xml file. Paste this but replace your-api-client-id and your-api-client-secret with the actual values you have in your workspace settings.

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.shakebugs.APIClientID"
android:value="your-api-client-id" />
<meta-data
android:name="com.shakebugs.APIClientSecret"
android:value="your-api-client-secret" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>

Caveat for apps targeting SDK version 28 and lower

The Shake SDK targets the latest Android version(API 29) and as such has the attribute android:foregroundServiceType="mediaProjection" defined in the manifest that the screen recording feature requires. If your app targetSdkVersion is 28 or lower(defined in your projects build.gradle) you have to add the service definition to your manifest file manually otherwise the build won't pass. Open your AndroidManifest.xml file and paste this:

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.shakebugs.shake.internal.service.ScreenRecordingService"
tools:node="replace"/>
</application>/>
</manifest>

If you target Android API 28 and lower and don't add this service definition to your manifest you will get the following error:

AAPT: error: attribute android:foregroundServiceType not found.

Initialize Shake

App.kt
import android.app.Application
import com.shakebugs.shake.Shake
class App : Application() {
override fun onCreate() {
super.onCreate()
Shake.start(this)
}
}

Now build your project and see everything work! To build and run your app, select Run › Run in the menu bar. This first run will automatically add your app to your Shake Dashboard based on your app bundle ID.