Installation
Gradle Plugin
Add GitHub Package Registry
Create GitHub token
GitHub package registry requires authentication credentials. These must be created by following the guide here: https://github.com/settings/tokens/new
You will need to enable the following scope on the GitHub token creation form:
Add GitHub Package Registry to project Gradle
Add the GitHub package registry to the top level build.gradle
as so:
buildscript {
repositories {
maven {
url = "https://maven.pkg.github.com/attractions-io/maplayr-android"
credentials {
username "GitHub username here"
password "GitHub token with packages read access here"
}
}
}
}
An example can be found here: build.gradle
Use environment variables for credential storage
To avoid saving your GitHub credentials directly in your repo you can add them to your environment variables. They can then be accessed like so:Add the MapLayr plugin class path to Gradle
Add the MapLayr plugin class path to Gradle by adding the following dependency to the top level build.gradle
as so:
An example can be found here: build.gradle
Add MapLayr Plugin to Gradle
Add the MapLayr plugin to Gradle in the app module build.gradle
as so:
An example can be found here: app/build.gradle
Use MapLayr Plugin
In the app module build.gradle
configure the plugin.
API Key
The apiKey
is required for any usage of the SDK
An example can be found here: app/build.gradle
Bundle maps at build time
Maps can be downloaded at build time and bundled into the resulting aab
or apk
file, which makes the maps available for immediate use when the user opens the app even if they are offline.
Bundle a single map
To bundle a single map specify the desired map id using the mapId
key as so:
This map id can be retrieved in your code by using BuildConfig.MAPLAYR_MAP_0
.
Bundle multiple maps
Multiple maps can be specified by using the mapIds
key as so:
These map ids can be retrieved in your code by using BuildConfig.MAPLAYR_MAP_0
, BuildConfig.MAPLAYR_MAP_1
, ... , BuildConfig.MAPLAYR_MAP_N
.
Bundle named map(s)
Map id(s) can be provided alongside a friendly name by using the maps
key as so:
These map id(s) can be retrieved in your code by using the friendly name(s); BuildConfig.MAPLAYR_MAP_MY_FIRST_MAP
, BuildConfig.MAPLAYR_MAP_MY_SECOND_MAP
.
Build variants, build types & product flavors
Any of the methodologies above for specifying map ids to be bundled into the app at build time can be nested in the build variants, build types or product flavors namespace to make them specific to that build.
attractionsIo {
variants {
variant1 {
mapId = "{map_id}"
}
variant2 {
mapId = "{map_id}"
}
}
buildTypes {
buildType1 {
mapId = "{map_id}"
}
buildType2 {
mapId = "{map_id}"
}
}
productFlavors {
productFlavor1 {
mapId = "{map_id}"
}
productFlavor2 {
mapId = "{map_id}"
}
}
}
An example can be found here: app/build.gradle
Set cache time
The maps are cached for a default period of 24 hours but this can be modified. For example, a build system could have this set to 0
so that the latest map is downloaded for every build.
An example can be found here: app/build.gradle
MapLayr Implementation
Use the same GitHub token as created above #Create GitHub token
Add GitHub Package Registry to module Gradle
Add the GitHub package registry to the module level build.gradle
as so:
repositories {
maven {
url = "https://maven.pkg.github.com/attractions-io/maplayr-android"
credentials {
username "GitHub username here"
password "GitHub token with packages read access here"
}
}
}
An example can be found here: app/build.gradle
Add MapLayr implementation to Gradle module dependencies
An example can be found here: app/build.gradle