-
Notifications
You must be signed in to change notification settings - Fork 0
Step 3: Android Setup
To build with Reader SDK, the following must be true:
- Your application minSdkVersion is API 19 (KitKat 4.4) or higher.
- Your application targetSdkVersion is API 26 (Oreo, 8.0) or lower.
- You are using the Android Gradle Plugin version 3.0.0 or greater. Reader SDK may work with 2.3.0 or greater, but stability is not guaranteed.
- Your application uses support library version 26.0.2 and Google Play Services version 12.0.1. Square cannot guarantee that the SDK will work with different versions of these libraries.
- You are not using Proguard for code optimization. Compressing the Reader SDK binary removes critical bytecode elements and results in runtime errors.
Make sure you retrieved Square credentials (The ones we created on the initial setup wiki page )
If you've worked on Android projects in the past, you probably know that there's a gradle.properties
file on ~/.gradle/gradle.properties
if you're on OSX (probably also on Linux) and C:\Users\username\.gradle\gradle.properties
if you're on Windows.
(There's also a gradle.properties
file in the root dir of your Android project, but I prefer adding credentials outside of the project. You can use that one as well).
You need to add the following entry to that gradle.properties
file:
SQUARE_REPO_USERNAME=WHATEVER_YOUR_SQUARE_USERNAME_IS
SQUARE_REPO_PASSWORD=WHATEVER_YOUR_SQUARE_PASSWORD_IS
where WHATEVER_YOUR_SQUARE_USERNAME_IS
and WHATEVER_YOUR_SQUARE_PASSWORD_IS
are the credentials you created in the Initial Setup step.
- Multidex:
Reader SDK and its dependencies contain more than 65k methods, so your build script must enable Multidex. If your minSdkVersion is less than 21, you also need to include the multidex dependency:
android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 26
multiDexEnabled true // <--
}
}
dependencies {
// Add this dependency if your minSdkVersion < 21
implementation 'com.android.support:multidex:1.0.3'
// ...
}
Configure the Multidex options:
android {
// ...
dexOptions {
// Ensures incremental builds remain fast
preDexLibraries true
// Required to build with Reader SDK
jumboMode true
// Required to build with Reader SDK
keepRuntimeAnnotatedClasses false
}
// ...
}
Find the MainApplication.java
file of your android project, and locate the onCreate
method:
It should look something like this:
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
ReaderSdk.initialize(this); // <-- ADD THIS
}
You'll probably need to include import com.squareup.sdk.reader.ReaderSdk;
to make things play well.
Also if you've added Multidex, make sure to also add the following method in that same file:
// We need to override this method because minSdkVersion < 21
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT_WATCH) {
// Required if minSdkVersion < 21
// only for KITKAT_WATCH and newer versions
MultiDex.install(this);
}
}
That should get you going, but if you need more info click here