Fast Integration

Last Updated on : 2024-09-03 06:53:01download

This topic describes how to quickly integrate the Smart Industry App SDK for Android into your development environment, such as Android Studio. It also sheds light on the initialization method and how to enable the debugging mode with a few simple steps. This allows you to run the demo app and get started with your smart industry app development.

Prerequisites

Integrate with the SDK

Step 1: Create an Android project

Create a project in Android Studio.

Step 2: Configure build.gradle

Add dependencies downloaded in the preparation steps to the file build.gradle of the Android project.

android {
   defaultConfig {
      ndk {
         abiFilters "armeabi-v7a", "arm64-v8a"
      }
   }
   packagingOptions {
      pickFirst 'lib/*/libc++_shared.so' // An Android Archive (AAR) file contains an Android library. If the .so file exists in multiple AAR files, select the first AAR file.
   }
}

dependencies {
   implementation fileTree(dir: 'libs', include: ['*.aar'])
    implementation 'com.alibaba:fastjson:1.2.32'
    // The latest stable version of Smart Industry App SDK for Android.
    implementation 'com.thingclips.smart:IndustryLinkSDK:2.3.0-indy'
    implementation 'com.squareup.moshi:moshi:1.15.1'
}

Add the Tuya Maven repository URL to the build.gradle file in the root directory.

repositories {
   google()
   mavenCentral()
   // Tuya Maven repository address.
   maven { url "https://maven-other.tuya.com/repository/maven-commercial-releases/" }
}

Step 3: Integrate with security component

  1. Go to the Get SDK tab, select one or more required SDKs, and then download the App SDK for iOS or Android.

    Fast Integration
  2. Extract the downloaded package, put security-algorithm.aar in the libs directory of the project, and then make sure dependencies in build.gradle of your project include implementation fileTree(include: ['*.aar'], dir: 'libs').

    Fast Integration
  3. The domain.txt file extracted in step 2 will be used for initializing the SDK later.

    If you adopt or update the Custom Domain Name service later, you need to rebuild the SDK on the Get SDK page and repeat the steps mentioned above.

Step 4: Set cloud project certificate signature and get Client ID and Client Secret

  1. In the Developer Platform, find the cloud project associated with the SDK you created.

    Fast Integration
  2. Edit the SHA-1 for Tuya Smart App SDK (Android), as shown above.

    1. Generate an SHA-1 hash. For more information, see Android documentation and How to Get SHA-1 and SHA-256 Keys.
    2. Enter your SHA-1 hash in the SHA1 field.
  3. Copy the Client ID and Client Secret for later use when initializing the SDK.

Step 5: Set certificate signature and get AppKey and AppSecret

  1. In the Developer Platform, open the target SDK.

    Fast Integration
  2. Configure the app certificate.

    1. Generate an SHA-256 hash value. For more information, see Android documentation and How to Get SHA-1 and SHA-256 Keys.
    2. Enter the SHA-256 key in the certificate.
  3. Copy the AppKey and AppSecret for later use when initializing the SDK.

Step 6: Obfuscate the code

Configure obfuscation in proguard-rules.pro.

#fastJson
-keep class com.alibaba.fastjson.**{*;}
-dontwarn com.alibaba.fastjson.**

#mqtt
-keep class com.thingclips.smart.mqttclient.mqttv3.** { *; }
-dontwarn com.thingclips.smart.mqttclient.mqttv3.**

#OkHttp3
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**

-keep class okio.** { *; }
-dontwarn okio.**

-keep class com.thingclips.**{*;}
-dontwarn com.thingclips.**

# Matter SDK
-keep class chip.** { *; }
-dontwarn chip.**

Step 7: Initialize the SDK

Initialize the SDK in the main thread of the Application. Make sure that all processes are initialized. Example:

public class BaseApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        // Initialization.
        new IndustryLinkSDK.Builder(this)
                // The Client ID and Client Secret obtained in step 4.
                .initialize("clientId","clientSecret")
        // The domain obtained in step 3. Specify your domain.
                .setHost("domain")
                // The AppKey and AppSecret obtained in step 5.
                .setDeviceSDKKey("AppKey")
                .setDeviceSDKSecret("AppSecret")
                .setDebugMode(true)
                .build();
    }
}
  • In debug mode, you can enable SDK logging to facilitate troubleshooting.
  • We recommend that you disable logging in release mode.

Run the demo app

In the following example, a demo app is used to describe the process of app development with the Smart Industry App SDK. Before the development of your app, we recommend that you run the demo app.

Feature overview

The demo app provides basic features such as registration, login, device pairing, and asset management. Smart Industry App SDK forms the backbone of the Tuya SaaS Development Framework. For more information, see the GitHub project tuya-android-iot-app-sdk-sample.

The demo app supports the following features:

  • User management: log in to and log out of the app

  • Asset management: query and select assets

  • Device pairing: Wi-Fi access point (AP) mode, Wi-Fi Easy Connect (EZ) mode, wired mode, Zigbee sub-device pairing, QR code mode, and QR code scanning to pair NB-IoT devices

  • Device management: query and unbind devices

    Fast Integration

Run the demo

  1. According to the signature file of your project, configure signingConfigs in the build.gradle file of the project. The storeFile file indicates the location where the xxx.jks file is stored.

    Fast Integration
  2. Choose app > build.gradle and change the value of applicationId to your app package name.

    Fast Integration
  3. You have completed Step 3: Integrate with security component, Step 4: Set cloud project certificate signature and get Client ID and Client Secret, and Step 5: Set certificate signature and get AppKey and AppSecret.

  4. Run the demo.