Fast Integration with Smart Residence App SDK for Android

Last Updated on : 2023-05-31 03:29:42download

Before you begin

  • Before you start, make sure that you have performed the steps in Preparation.
  • If you have not installed Android Studio, visit the Android Studio official website to download Android Studio.
  • If you need to run the demo, please use the latest version of Android Studio (Android Studio Arctic Fox | 2020.3.1 Patch 3) Build #AI-203.7717.56.2031.7784292, built on October 1, 2021 Runtime version: 11.0.10+0-b96-7249189 aarch64), and upgrade Gradle version to 7.0 or higher. The demo is also developed with Jetpack Compose, please refer to the official documentation to configure the relevant development environment.

Integrate with the SDK

Step 1: Create an Android project

Create a project in Android Studio.

Step 2: Configure build.gradle

Add dependencies to the build.gradle file of the Android project.

android {
    defaultConfig {
        ndk {
            abiFilters "armeabi-v7a", "arm64-v8a"
    android.packagingOptions {
        // Deduplicates the dependencies of ``.
        pickFirst 'lib/arm64-v8a/'
        pickFirst 'lib/armeabi-v7a/'
        pickFirst 'lib/x86/'
        pickFirst 'lib/x86_64/'
dependencies {
    implementation ''
    implementation ''
    api ''


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

repositories {
    maven {url ""}

Step 3: Configure the security image, AppKey, and AppSecret

  1. Log in to the Tuya IoT Development Platform, go to the SDK Development page, and then click the SDK to be managed.

  2. On the page that appears, click the Get Key tab and click Download in the App Security Image for Android field.

    Fast Integration with Smart Residence App SDK for Android
  3. Rename the security image as t_s.bmp and put the image in the assets folder of your project.

    Fast Integration with Smart Residence App SDK for Android
  4. Return to the Android project, configure appkey and appSecret in AndroidManifest.xml, and then set permissions for the app.

    android:value="AppKey" />
    android:value="AppSecret" />

Step 4: 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.tuya.**{*;}
-dontwarn com.tuya.**

Step 5: Initialize the SDK

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

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

Configure appKey and appSecret in AndroidManifest.xml, or run the initialization code.

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

Step 6: 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 the SDK, you can get the security image, AppKey, and AppSecret. Make sure the security image, AppKey, and AppSecret are consistent with those used on the Tuya IoT Development Platform. Any mismatch will cause the SDK development to be failed. For more information, see Step 3: Configure the security image, AppKey, and AppSecret.

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

Demo app description

The demo app supports the following functions:

  • Site management
  • Access control
  • Personal information display

Demo app:

Fast Integration with Smart Residence App SDK for Android

更多详情,请参考 Github项目。

Run the sample

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

  2. Make sure that you have completed Step 3: Configure the security image, AppKey, and AppSecret.

  3. Click Run to run the demo app.

Troubleshooting the error message: Permission Verification Failed

  • Problem: When the system runs the demo app, an error message is returned in the following response:

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

    • Check whether your security image, AppKey, and AppSecret are correctly configured.
    • Check whether the security image is placed in the correct directory and whether the file name is t_s.bmp.