Installation and Setup

Installation

Gradle Installation

The simplest way to use the Android Buy SDK in your project is to add the following dependency to your build.gradle file:

compile 'com.shopify.mobilebuysdk:buy:2.1.0'

If you have issues with conflicts between the versions of Play Services Libraries in you project and the SDK you may need to exclude the transitive dependency and include your required version:

compile ('com.shopify.mobilebuysdk:buy:2.1.0') {
    exclude group: 'com.google.android.gms', module: 'play-services-wallet'
}
compile 'com.google.android.gms:play-services-wallet:<Your Version>'

Manual Addition of Library

If you would prefer to download the .aar file and add it to your project manually, follow these steps:

  1. Download the latest release.
  2. Unzip the Mobile Buy SDK in a known location.
  3. In Android Studio, from the menu select (File | New | New Module | Import .JAR or .AAR package).
  4. Browse to the location where you unzipped the SDK, and select the aar file to import it. A new module will be created.
  5. From the Android Studio menu select (File | Project Structure).
  6. Select your app module, and select the dependencies tab and use the + button to add a new Module dependency on the Mobile Buy SDK module.

Initialize the SDK

Import the Buy packages

import com.shopify.buy.dataprovider.*;
import com.shopify.buy.model.*;

Initialize the client


new BuyClientBuilder()
    .shopDomain(SHOP_DOMAIN)
    .apiKey(API_KEY)
    .appId(APP_ID)
    .applicationName(APP_NAME)
    .customerToken(CUSTOMER_TOKEN)
    .callbackScheduler(CALLBACK_SCHEDULER)
    .interceptors(INTERCEPTORS)
    .productRequestPageSize(PRODUCT_PAGE_SIZE)
    .collectionRequestPageSize(COLLECTION_PAGE_SIZE)
    .productTagRequesPageSize(PRODUCT_TAG_PAGE_SIZE)
    .networkRequestRetryPolicy(RETRY_MAX_COUNT, RETRY_DELAY_MS, RETRY_BACKOFF_MULTIPLIER)
    .httpTimeout(CONNECTION_TIMEOUT_MS, READ_WRITE_TIMEOUT_MS)
    .build()

Where:

Parameter Description
SHOP_DOMAIN (mandatory) url of your store, ie. myshop.myshopify.com
API_KEY (mandatory) api key for your store
APP_ID (mandatory) application id for your shop
APP_NAME (mandatory) package name of your application
CUSTOMER_TOKEN (mandatory) existing customer token if required
CALLBACK_SCHEDULER (optional) Rx scheduler that will be used for all API callbacks. If no scheduler is provided, the Android main thread will be used by default
INTERCEPTORS (optional) custom OkHttp interceptors if required
PRODUCT_PAGE_SIZE (optional) page size used for API calls related to the product requests
COLLECTION_PAGE_SIZE (optional) page size used for API calls related to the collection requests
PRODUCT_TAG_PAGE_SIZE (optional) page size used for API calls related to the product tag requests
RETRY_MAX_COUNT, RETRY_DELAY_MS, RETRY_BACKOFF_MULTIPLIER (optional) request retry configuration parameters used to retry api requests on network errors (socket timeout, unknown host, etc.). Network retry is disabled by default
CONNECTION_TIMEOUT_MS, READ_WRITE_TIMEOUT_MS (optional) configuration parameters for OkHttp connections. The default connection timeout is 30 seconds, and the default 60 sec will be used as default values