How to integrate the SDK in your application
v3
Introducing the software documentation and the demo app!
The software documentation provides elaborated information on every class, function and member in the SDK. Please choose the relevant SDK version:
The demo app gives you a general idea on how you should implement the SDK in you app. To download, please follow those steps:
- Open the demo app repo.
- Download the content of the repo.
- Unzip the file and open the Android demo app.
Prerequisites
The following are required to install the SDK:
- Administrative access to the HUMAN Portal to:
- Retrieve the HUMAN application ID (AppID).
- Set the token expiration and validity.
- An active HUMAN Enforcer.
Permissions and dependencies
Add the following permissions to your AndroidManifest.xml file:
📘 Dependencies are added automatically
Dependencies don’t have to be added when adding the SDK via JFrog. However, they are still needed when you add the SDK manually.
🚧 Update your OkHttp library to v4
If your app is using OkHttp v3, there will be a conflict that could cause unexpected errors in runtime. Notice that you should update both `okhttp` and `logging-interceptor` libraries.
Adding HUMAN SDK to your project
You can add the SDK to your project with one of the following options:
JFrog
- Add the following repository to your
build.gradle
andsettings.gradle
:
- Add the following dependency to your
build.gradle
and set the HUMAN Android SDK version:
Manual
- Download the AAR file from https://perimeterx.jfrog.io/ui/repos/tree/General/px-Android-SDK or use the following command line:
- Put the
PerimeterX-release.aar
in the libs folder of your app. - Add the following dependency to your
build.gradle
:
- Add the following dependencies to your
build.gradle
file (please refer to the relevant SDK version):
🚧 Issue with R8
R8 is a tool that is used to shrink, secure, and optimize Android applications.
When using this tool it could sometimes cause an issue with ktor library which included in the SDK.
To prevent this issue, we recommend addting the following rule in your proguard file:
How to start the SDK
Starting the SDK should be the first thing that runs in your app. Therefore, you should start it in your Application
class:
- Import the SDK:
- Make your
Application
class to implement thePerimeterXDelegate
(optional).
- Create and configure the
PXPolicy
object, in theApplication
’sonCreate
function.
- It’s recommended to tell the SDK which domains it should intercept. Not setting domains will cause the SDK to intercept URL requests from ALL domains, including 3rd party libraries.
- Call the
PerimeterX/start(application:appId:delegate:policy:)
function, with your application, AppID and the policy, in theApplication
’sonCreate
function. This function should be called only once.
- Add the HUMAN’s interceptor (
PXInterceptor
) to yourHttpClient
’s application interceptors list at the end. This is required for the “Automatic Interception”.
OkHttp:
ktor:
What happens when you start the SDK
The PerimeterX/start(appId:delegate:policy:)
function set up the session for a given AppID. It’s essential to call this function as early as possible in your application and before any URL request to your server.
Adding custom parameters
You may add custom parameters for additional configuration.
Summary
After writing the code above, the SDK will:
- Intercept your URL requests.
- Add SDK’s HTTP headers to those URL requests.
- Handle block responses from the server by presenting a challenge to the user.
Next steps
Review the following topics:
- Integration verification and testing
- Manual integration
- Handle block responses from the server
- React Native support
- Hybrid App support
- Account Defender
- Multiple AppIDs support
- Migrating from earlier SDK versions