Skip to main content

Snabble Gradle Plugin also on Gradle Plugin Portal

The Snabble Gradle Plugin is for the simplest setup of the Snabble Android SDK. With this plugin you can reduce the SDK integration to 5 lines in your codebase. You can also download the manifest in your CI to bundle the latest metadata with your app so that your user it can use your app with all required meta data.

Usage

Add plugin

Using the plugins DSL:

plugins {
id 'com.android.application'
id 'io.snabble.setup' version '{latestVersion}' // add this line
}
Hint: Latest version is embedded in image

Using the plugin

The absolut minimum is to add those two lines to make the SDK already working:

snabble.production.appId = 'your-app-id'
snabble.production.secret = 'your-app-secret'

When you use to add the dependency:

dependencies {
// your other dependencies
implementation 'io.snabble.sdk:ui:{latestVersion}' // add this line
}
Hint: Latest version is embedded in image

To start the combined scanner you just need to start our activity:

startActivity(Intent(context, CombinedScannerActivity::class.java))

That's it. This is the absolut minimum integration.

However we recommend to use the normal DSL syntax to define your config like this:

snabble.production {
appId = 'your-app-id'
secret = 'your-app-secret'
prefetchMetaData = true
}

With the last line added the manifest will be downloaded for each release build. If you want to use it also in debug builds you need to execute the gradle task downloadSnabbleMetadata.
Caching is applied so the file won't be downloaded on each build (except clean builds).

When your app supports multiple stages in a single app (e.g. with a developer setting) then you can define multiple secrets in your build.gradle like this:

snabble {
production {
appId = 'your-app-id'
secret = 'your-production-secret'
prefetchMetaData = true
}
staging {
appId = 'your-app-id'
secret = 'your-staging-secret'
}
testing {
appId = 'your-app-id'
secret = 'your-testing-secret'
}
}

To change the environment to staging you need to update this variable:

Snabble.userPreferences.environment = Environment.STAGING

Then you also need to restart the app. We use in our app for that the ProcessPhoenix library like this:

ProcessPhoenix.triggerRebirth(context)

For a seamless integration check out sample apps there you can see how you integrate our SDK it with out sample Apps. There we show you how to customize our UI.

Available parameters

ParameterTypeDescription
appIdStringRequired parameter. The project identifier, which is used in the communication with the backend.
secretStringRequired parameter. The secret needed for Totp token generation.
endpointBaseUrlStringThe endpoint url of the Snabble backend. When omitted it will take the stage default
prefetchMetaDataBooleanHighly recommended to use for production. Download the metadata automatically.
bundledMetadataAssetPathStringRelative path from the assets folder which points to a bundled file which contains the metadata.
Do not use this with prefetchMetaData=true
This file gets initially used to initialize the sdk before network requests are made, or be able to use the sdk in the case of no network connection. Optional. If no file is specified every time the sdk is initialized we wait for a network response from the backend. It is HIGHLY recommended to provide bundled metadata to allow the SDK to function without having a network connection.
generateSearchIndexBooleanIf set to true, creates an full text index to support searching in the product database using findByName or searchByName. Note that this increases setup time of the ProductDatabase, and it may not be immediately available offline.
maxProductDatabaseAgeLongThe time that the database is allowed to be out of date. After the specified time in milliseconds the database only uses online requests for asynchronous requests. Successfully calling [ProductDatabase.update] resets the timer. The time is specified in milliseconds.
maxShoppingCartAgeLongThe time that the shopping cart is allowed to be alive after the last modification. The time is specified in milliseconds.
disableCertificatePinningBooleanIf set to true, disables certificate pinning. Not recommended for production!
vibrateToConfirmCartFilledBooleanVibrate while adding a product to the cart.
loadActiveShopsBooleanSet to true, to load shops that are marked as pre launch and are not part of the original metadata in the backend (for example for testing shops in production before a go-live).
checkInRadiusFloatThe radius in which the CheckInManager tries to check in a shop. In meters.
checkOutRadiusFloatThe radius in which the CheckInManager tries to stay in a shop, if already in it. If outside of this radius and the lastSeenThreshold, you will be checked out.
lastSeenThresholdLongThe time in milliseconds which we keep you checked in at a shop. The timer will be refreshed while you are still inside the shop and only begins to run if you are not inside the checkOutRadius anymore.
networkInterceptorStringThe FQN of the Network interceptor used for all calls made by the SDK.
manualProductDatabaseUpdatesBooleanSet to true if you want to control when the product database gets updated, otherwise the product database gets updated when checking in and if checked in when the app resumes.