Android
Follow the instructions below to install and set up the Skillz SDK in your Android Studio project.
Add Required Maven Repositories
The Skillz Android SDK and its dependencies reside in the Skillz maven repository. In the module-level build.gradle
file (it can be found in the src folder where your game resides, not at the top level), you will need to add this maven repository so that it can later add the Skillz SDK to your project.
On Android Studio in the Android view on the Project panel, there are two build.gradle
files: one labeled Project and one labeled Module. Make sure the one labeled Module is selected like so:
Add the Skillz repository like so:
android {
repositories {
// The Google Maven repository must be listed first
google()
maven {
url 'http://nexus.skillz.com/content/groups/public/'
}
}
}
Google's Maven repository (re: google()
) must be listed first as Gradle won't look past the first Maven repository if it finds an older version of a dependency.
Adding the Skillz SDK Dependency
Next, add the Skillz library as a dependency. In this step, you must choose to add either the Stable build or the Beta build of the Skillz Android SDK. If you’re not sure which build is right for you, click here to find the release notes on each build. (For managed accounts, please reach out to your Skillz Account Manager for guidance on which build to integrate.)
To integrate the latest Stable build, add the following in the same build.gradle
file you edited earlier:
android {
// Extra code excluded for brevity
}
dependencies {
implementation 'com.skillz.sdk:skillz-sdk-android:26.0.20'
}
Version 26.0.20
is an example. The newest version of the SDK can be found in Skillz's Maven Repository. When upgrading to newer Skillz SDK releases in the future, you’ll need to update the specified version ("26.0.20" in the above example) within your project.
Ensure Android SDK version compatibility
In your build.gradle
file, you will need to ensure the Android SDK version compatibility. Skillz requires a minSdkVersion
of 23 or higher, and works best with a compiledSdkVersion
of 29 and targetSdkVersion
of 29. If you want to learn more about what's the difference between compiledSdkVersion and targetSdkVersion, you can check out the official Android developer documentation.
android {
compileSdkVersion 29
defaultConfig {
minSdkVersion 23
targetSdkVersion 29
ndk {
abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
}
Ensure minSdkVersion
is set to 23 or higher and that the targetSdkVersion is set to 29 within the android { defaultConfig { } }
block of your build.gradle
file.
Additionally, ensure that the compileSdkVersion
within the android block is set to 29.
You must also include the abiFilters
line in order to support both 32-bit and 64-bit devices.
Add multidex-keep.txt
The Skillz SDK needs a few classes to end up in your APK's main DEX file upon compilation. Modify build.gradle
to reference a file called multidex-keep.txt
inside the defaultConfig
subsection for the android
section.
android {
defaultConfig {
multiDexKeepProguard file('multidex-keep.txt')
}
}
Now, add a file called multidex-keep.txt
to your Android Studio project with the contents below:
# multidex-keep.txt
-keep class com.google.firebase.crashlytics.** { *; }
-keep class timber.log.** { *; }
-keep class com.facebook.FacebookSdk
-keep class com.path.android.jobqueue.JobManager
Enable AndroidX and R8
The Skillz SDK depends on the AndroidX Support Libraries instead of the original Android Support Libraries. Additionally, R8 has replaced Proguard as the standard tool for code shrinking, desugaring, and obfuscation.
In your project, add the lines below to the gradle.properties
file; create one if it does not exist. These will tell Android Studio to automatically migrate dependencies from any original Support Libraries to their AndroidX equivalents, and enable R8.
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true
Upgrade to Java 8
Since the SDK uses Java 8, you’ll also need to update to that version of Java to ensure compatibility.
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Add Proguard rules
Skillz is pre-obfuscated and requires Proguard rules to prevent it from being re-obfuscated and shrunken. Otherwise, this will cause crashes and other problems at runtime. In your build.gradle
, make sure minifyEnabled
and shrinkResources
are both set to false. Additionally, specify 'proguard-rules.pro'
as your Proguard file.
android {
buildTypes {
debug {
jniDebuggable true
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Next, add the snippet below in your Proguard file:
# The Skillz Android SDK is already obfuscated, prevent it
# from being obfuscated again if minifyEnabled true
-dontobfuscate
# Prevent the Skillz SDK from being minified if minifyEnabled true
-dontshrink
-keep class bitter.jnibridge.* { *; }
-keep class com.unity3d.player.* { *; }
-keep class org.fmod.* { *; }
-keep public class com.dylanvann.fastimage.* { *; }
-keep public class com.dylanvann.fastimage.** { *; }
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class retrofit.** {*;}
-keep class com.facebook.** {*;}
-keep class com.amazonaws.** {*;}
Custom Theming Warning
If your game takes advantage of our custom themed SDK feature, you will need to build an .ipa or .apk with the new SDK version, upload it to our developer console, and sync your game to Production. Prior to that, you may see artifacts within your custom theme.
Setting Skillz meta-data
Add the following lines in your Android Manifest’s <application>
block:
<application>
<!-- Make sure the Skillz <meta-data> tags are all direct children of the <application> tag, otherwise the game won't run properly! -->
<meta-data android:name="skillz_game_id" android:value="" />
<meta-data android:name="skillz_production" android:value="false" />
<meta-data android:name="skillz_game_activity" android:value="com.packagename.GameActivityName" />
<meta-data android:name="skillz_allow_exit" android:value="true" />
<meta-data android:name="skillz_exit_activity" android:value="com.packagename.MenuActiviyName" />
</application>
Now, edit each meta-data line to contain the correct information for your game.
<meta-data android:name="skillz_game_id" android:value="" />
Set the value to your Skillz Game ID from the Skillz Developer Console. You can obtain your Game ID by going to your developer console.
<meta-data android:name="skillz_production" android:value="false" />
Set this value to false
for testing in the Sandbox environment. When you are ready to move to Production and before uploading a binary in your developer console, set this value to true
.
<meta-data android:name="skillz_game_activity" android:value="" />
Set the value to the name of the activity Skillz should launch when a user enters a Skillz match. Skillz requires a fully-qualified path, example: “com.skillzgames.caverun.GameActivity”
.
<meta-data android:name="skillz_allow_exit" android:value="true" />
Set the value to false
if your game is Skillz-only and there is no main menu of your game. Set the value to true
to allow users to exit the Skillz interface back to the main menu of your game. If you set the value of skillz_allow_exit
to true
, you must also provide the skillz_exit_activity
for Skillz to return to. Otherwise, the screen will be blank.
<meta-data android:name="skillz_exit_activity" android:value="" />
Set the value to the name of the activity Skillz should launch when a user exits the Skillz menu UI. Skillz requires a fully-qualified path, example: "com.skillzgames.caverun.MainMenuActivity"
. This value is only used when skillz_allow_exit
is true
.
NOTE
You may need to add the following meta-data tag to support the larger aspect ratio of the new Android flagship phones:
<meta-data android:name="android.max_aspect" android:value="2.1" />
Change the main activity's launchMode to singleTop
Inside your AndroidManifest.xml
file, set your main activity’s launchMode to singleTop
.
Your main activity is the one with an intent filter with an action set as MAIN and category of LAUNCHER.
<activity
android:name=".YourMainActivity"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Game Activity should extend from SkillzActivity
The activity that you specified in the meta-data tag skillz_game_activity
will need to inherit from SkillzActivity.
Example:
public class GameActivity extends SkillzActivity {
}
Make sure your build.gradle
Syncs successfully, and that your project still compiles. If so, you're now ready to integrate the Skillz SDK.