Skip to main content
Version: 1.5.x

Integration

caution

This is standalone SDK. You don't need dependencies from platform-101xp-sdk. You should create the new build project.

Gradle

Please, add to gradle.properties file:

android.useAndroidX=true
android.enableJetifier=true

Copy google-services.json file to app folder.

For that file ask your manager.

Add to the project level build.gradle file:

buildscript {
repositories {
google()
jcenter()
jcenter { url "http://jcenter.bintray.com" }
maven { url 'https://maven.google.com/' }
maven { url 'https://maven.fabric.io/public' }
maven {url 'https://developer.huawei.com/repo/'}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.google.gms:google-services:4.3.3'
classpath 'io.fabric.tools:gradle:1.31.2'
classpath 'com.huawei.agconnect:agcp:1.3.2.301'
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
jcenter { url "http://jcenter.bintray.com" }
maven {url 'https://developer.huawei.com/repo/'}
}
}

Add to the application level build.gradle file:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.huawei.agconnect'

android {
compileSdkVersion ...
buildToolsVersion "..."
defaultConfig {
applicationId 'com.your_package.huawei'
minSdkVersion ...
targetSdkVersion ...
versionCode ...
versionName "..."
multiDexEnabled true
}

signingConfigs {
release {
keyAlias '...'
keyPassword '...'
storeFile file('.../your_key_release.keystore')
storePassword '...'
}
}


buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
minifyEnabled false
signingConfig signingConfigs.debug
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

repositories{
mavenCentral()
maven {url 'http://developer.huawei.com/repo/'}
maven {
url 'https://artifactory101xp.jfrog.io/artifactory101xp/p101xp-huawei-release/'
credentials {
username = "sdk-user"
password = "Dt!k(5JR&6"
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
...
implementation "androidx.multidex:multidex:2.0.1"

implementation "com.platform101xp:platform101xp-huawei-sdk:1.2.0"
}

Copy agconnect-services.json file to app folder.

Please, ask your manager for that file.

AndroidManifest

Please, add the next permissions:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="com.huawei.appmarket.service.commondata.permission.GET_COMMON_DATA" />

It is very important to set application class as: com.platform101xp.sdk_huawei.Platform101XPApplication

If you have your own class Application, please, extend your class from Platform101XPApplication.

<application
android:name="com.platform101xp.sdk_huawei.Platform101XPApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
</application>

Then, add the values for the next parameters.

Please, ask your manager for those values.

<meta-data android:name="com.platform101xp.sdk_huawei.client_id"
android:value="@string/client_id" />
<meta-data android:name="com.huawei.hms.version"
android:value="2.6.3.306" />
<meta-data android:name="com.huawei.hms.client.appid"
android:value="appid=$your_app_id" />
<meta-data android:name="com.huawei.hms.client.cpid"
android:value="cpid=$your_cp_id" />
<meta-data android:name="com.platform101xp.sdk_huawei.company_name"
android:value="@string/company_name" />

In your MainActivity, you need to create the SDK instance and set the initialize listener:

public class MainActivity extends Activity {
private Platform101XPHuaweiInitializeListener initializeListener;
private Platform101XPHuawei platformInstance;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

initializeListener = error -> {
if (error != null)
showMessage(error.getErrorMessage());
else
Log.d(Platform101XPHuawei.LOG_TAG, "Sdk is initialized");
};

platformInstance = new Platform101XPHuawei
.Builder(this)
.setInitializeListener(initializeListener)
.build();
}
}