This document is deprecated, please go to Tuya Developer Documentation Center to view the latest version: Tuya Smart Doc - Android SDK

1. Integrate SDK

1.1.1. Create Project

Build your project in the Android Studio.

1.1.2. Configure the build.gradle

Add the following codes to the build.gradle file.

android {
    defaultConfig {
        ndk {
            abiFilters "armeabi-v7a", "arm64-v8a"
    packagingOptions {
        pickFirst 'lib/*/' // multi aar has such so, should pick first.
dependencies {
    implementation ''
    implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.14.9'

    // Tuya Home's current latest release version:
    implementation ''

repositories {


  • The Tuya Smart sdk solely supports the platform of armeabi-v7a architecture by default. Developer may refer to the GitHub if you need other platforms.
  • After version 3.11.0, the so libraries of armeabi-v7a, arm64-v8a, armeabi platforms have been integrated into sdk. Please remove the relevant so-banks of sdk manually placed in the local, and use the default provided by sdk.

1.1.3. Integrated security image

Click the download button to download the security image.

Rename the downloaded security image to "t_s.bmp" and move it to the assets/ folder in the project directory.

1.1.4. Set the AndroidManifest.xml

Set appkey and appSecret in the AndroidManifest.xml file, and configure corresponding permissions, etc.

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

1.1.5. Proguard Configuration

please add this proguard configuration to files.

-keep class**{*;}

-keep class** { *; }

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

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

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

1.2. Use the SDK function in codes

The TuyaHomeSdk is the outbound interface of the Smart Home, and the operations include network configuration, initiation, control, room, group and ZigBee.

1.2.1. Initiate SDK in the Application


It is used to initiate components of communication services, etc.


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


The appId and appSecret need to be configured in the AndroidManifest.xml file or the build environment or the codes.

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

1.2.2. Logout of the Tuya Smart Cloud connection

The following interface needs to be invoked to log out of the App.


1.2.3. Monitor the invalidity of registered session


Because of abnormality or long-time absence of operation for 45 or more days, the session will become invalid, and user has to log out of the App and log in again to obtain the session.


// Monitor the invalidity of session.
TuyaHomeSdk.setOnNeedLoginListener(INeedLoginListener needLoginListener);

needLoginListener.onNeedLogin(Context context);


public class TuyaSmartApp extends Application {

        public void onCreate() {
            // Register in the App.
                TuyaHomeSdk.setOnNeedLoginListener(new INeedLoginListener(){
                public void onNeedLogin(Context context) {


[info] Note

  • In case of this kind of callback, please go to the login page and require the user to log in again.

1.2.4. Debug mode

In the debug mode, you can enable the sdk log switch to view more log information and help you locate the problem quickly. It is recommended to turn off the log switch in release mode.


results matching ""

    No results matching ""