Fast Integration

Last Updated on : 2024-03-26 08:57:12download

This topic describes how to integrate the Commercial Lighting App SDK for Android into your project.

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/*/'
        pickFirst 'lib/*/'
        pickFirst 'lib/*/'

 configurations.all {
        exclude group: "" ,module: 'thingsmart-modularCampAnno'

dependencies {
    implementation 'com.facebook.soloader:soloader:0.10.4'
    implementation ''
    implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.14.9'
    implementation ''

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

repositories {
   maven { url '' }
   maven { url "" }
   maven { url '' }
   maven { url '' }
   maven { url '' }
   maven { url '' }
   maven { url '' }

Step 3: Integrate with security component

  1. Go to SDK Development on the Tuya IoT Development Platform and open the target app. Go to the Get SDK tab, select one or more required SDKs or BizBundles, 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

Step 4: Configure AppKey, AppSecret, and certificate signature

  1. Go to SDK Development on the Tuya IoT Development Platform and open the target app.

  2. In the Get Key tab, find AppKey and AppSecret and specify them in the AndroidManifest.xml file.

    Fast Integration
        android:value="Appkey" />
        android:value="AppSecret" />
  3. 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.

Step 5: Obfuscate the code

Configure obfuscation in

-keep class**{*;}

-keep class** { *; }

-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.**

# Keep native methods
-keepclasseswithmembernames class * {
    native <methods>;
-keepclassmembers class * {
    native <methods>;

Step 6: Initialize the SDK

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


public class TuyaSmartApp extends Application {
    public void onCreate() {

Configure appKey and appSecret in AndroidManifest.xml, or set them during initialization.

ThingSdk.init(Application application, String appkey, String appSerect)

Step 7: Enable or disable logging

  • In debug mode, you can enable SDK logging to facilitate troubleshooting.

  • We recommend that you disable logging in release mode.


Run the demo app

After you integrate with the SDK, you can get the AppKey and AppSecret. Make sure the AppKey and AppSecret are consistent with those used on the Tuya IoT Development Platform. Any mismatch will cause the SDK not to work properly. See Step 4: Configure AppKey, AppSecret, and certificate signature for details.

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

Feature overview

The demo app supports the following features:

  • Project management
  • Area management
  • Group management
  • Account management
  • Device pairing
  • Device control
  • Outdoor project

Demo app:

Fast Integration

For more information, go to the GitHub repository.

Run the demo

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

    Fast Integration
  2. Make sure that you have completed Step 3: Integrate with security component and Step 4: Configure AppKey, AppSecret, and certificate signature.

  3. Run the code.

Error: Permission Verification Failed

  • Problem: The following error message is thrown when you run the demo.

        "success": false,
        "errorCode" : "SING_VALIDATE_FALED",
        "status" : "error",
        "errorMsg" : "Permission Verification Failed",
        "t" : 1583208740059
  • Solution:

    • Check whether the AppKey and AppSecret are correctly configured.