Last Updated on : 2023-05-31 03:29:42download
Create a project in Android Studio.
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 `libc++_shared.so`.
pickFirst 'lib/arm64-v8a/libc++_shared.so'
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
pickFirst 'lib/x86/libc++_shared.so'
pickFirst 'lib/x86_64/libc++_shared.so'
}
}
dependencies {
implementation 'com.alibaba:fastjson:1.1.67.android'
implementation 'com.tuya.smart:smartResidenceSDK:1.2.0'
api 'com.tuya.smart:tuyasmart:3.34.5'
}
Add the Tuya IoT Maven repository URL to the build.gradle file in the root directory.``
repositories {
maven {url "https://maven-other.tuya.com/repository/maven-releases/"}
}
Log in to the Tuya IoT Development Platform, go to the SDK Development page, and then click the SDK to be managed.
On the page that appears, click the Get Key tab and click Download in the App Security Image for Android field.
Rename the security image as t_s.bmp
and put the image in the assets
folder of your project.
Return to the Android project, configure appkey
and appSecret
in AndroidManifest.xml
, and then set permissions for the app.
<meta-data
android:name="TUYA_SMART_APPKEY"
android:value="AppKey" />
<meta-data
android:name="TUYA_SMART_SECRET"
android:value="AppSecret" />
Configure obfuscation in proguard-rules.pro
#fastJson
-keep class com.alibaba.fastjson.**{*;}
-dontwarn com.alibaba.fastjson.**
#mqtt
-keep class com.tuya.smart.mqttclient.mqttv3.** { *; }
-dontwarn com.tuya.smart.mqttclient.mqttv3.**
#OkHttp3
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
-keep class okio.** { *; }
-dontwarn okio.**
-keep class com.tuya.**{*;}
-dontwarn com.tuya.**
Initialize the SDK in Application
. Make sure that all processes are initialized. Example:
public class TuyaSmartApp extends Application {
@Override
public void onCreate() {
super.onCreate();
TuyaSdk.init(this);
}
}
Configure appKey
and appSecret
in AndroidManifest.xml
, or run the initialization code.
TuyaSdk.init(Application application, String appkey, String appSerect)
In debug mode, you can enable SDK logging to facilitate troubleshooting.
We recommend that you disable logging in release mode.
TuyaSdk.setDebugMode(true);
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.
The demo app supports the following functions:
Demo app:
更多详情,请参考 https://github.com/tuya/tuya-residence-android-sdk-sample Github项目。
Choose app
> build.gradle
and change the value of applicationId
to your app package name.
Make sure that you have completed Step 3: Configure the security image, AppKey, and AppSecret.
Click Run to run the demo app.
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:
t_s.bmp
.Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback