Install Layer

Layer is distributed as a source code package or compiled bundle, and can be easily integrated into a new app or an existing codebase with standard tooling.

The Android SDK is built and designed to be used with Android Studio. The SDK is available as an AAR or JAR file hosted on Github, and can be added to your project by referencing the AAR remotely with Maven, or by importing the JAR locally.

Note

Google has deprecated Android tooling for Eclipse, and as a result we no longer provide support for Eclipse-based workflows.

Option 1: Maven + AAR

Navigate to your build.grade file at the app level (not project level) and include the following:

repositories {
    maven { url "https://raw.githubusercontent.com/layerhq/releases-android/master/releases/" }
}

dependencies {
    compile 'com.layer.sdk:layer-sdk:0.20.3'
    compile 'com.google.android.gms:play-services-gcm:7.5.0'
    compile 'org.slf4j:slf4j-nop:1.5.8'
}

Option 2: Local JAR

  1. Download the latest Layer SDK JAR from Github
  2. Drag the JAR file into the /libs directory of your Android Studio application
  3. Navigate to the JAR file in the Android Studio navigator, right-click and select “Add As A Library…”
  4. Navigate to your build.gradle file and ensure that you include the following:
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services-gcm:7.5.0'
    compile 'org.slf4j:slf4j-nop:1.5.8'
}

Example AndroidManifest.xml

The Layer Android SDK requires some permissions and references from your app’s AndroidManifest.xml file. These permissions allow the SDK to monitor network state and receive Google Cloud Messaging messages. Below is an example with a com.myapp.package package; replace with your own package when merging with your own manifest.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.myapp.package">

    <!-- Standard permissions -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>

    <!-- Signature-only permissions -->
    <permission android:name="com.myapp.package.permission.LAYER_PUSH"
       android:protectionLevel="signature"/>
    <uses-permission android:name="com.myapp.package.permission.LAYER_PUSH"/>
    <permission android:name="com.myapp.package.permission.C2D_MESSAGE"
       android:protectionLevel="signature"/>
    <uses-permission android:name="com.myapp.package.permission.C2D_MESSAGE"/>

    <!-- LayerClient.sendLogs() permissions -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_LOGS"/>

    <application>
       <!-- Your custom "com.layer.sdk.PUSH" notification Receiver -->
       <receiver android:name=".LayerPushReceiver">
          <intent-filter>
             <action android:name="com.layer.sdk.PUSH"/>
             <category android:name="com.myapp.package"/>
          </intent-filter>
       </receiver>

       <!-- Layer's GCM Receiver and Service -->
       <receiver android:name="com.layer.sdk.services.GcmBroadcastReceiver"
          android:permission="com.google.android.c2dm.permission.SEND">
          <intent-filter android:priority="950">
             <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
             <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
             <category android:name="com.myapp.package"/>
          </intent-filter>
       </receiver>
       <service android:name="com.layer.sdk.services.GcmIntentService"/>
    </application>
</manifest>

ProGuard support

If your project uses ProGuard, you may have to add the following settings to the ProGuard configuration file to ensure Layer builds correctly:

# Layer SDK
-keep class com.layer.** {*; }
-dontwarn com.layer.**

Verifying installation

To verify that everything is working, connect the client, then build and run your app.

Getting Started Connecting