Last Updated on : 2024-03-21 07:04:01download
This topic describes how to integrate the Commercial Lock App SDK into your project.
Create a project in Android Studio.
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/*/libv8android.so'
pickFirst 'lib/*/libv8wrapper.so'
pickFirst 'lib/*/libc++_shared.so'
}
}
dependencies {
implementation 'com.facebook.soloader:soloader:0.10.4'
implementation 'com.alibaba:fastjson:1.1.67.android'
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.14.9'
implementation 'com.thingclips.smart:thingsmartlocksdk:1.3.1-lock'
}
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/' }
maven { url "https://maven-other.tuya.com/repository/maven-commercial-releases/" }
maven { url 'https://jitpack.io' }
google()
mavenCentral()
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://central.maven.org/maven2/' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://developer.huawei.com/repo/' }
}
Go to SDK Development on the Tuya IoT Development Platform and open the target app.
Click the Get Key tab and download the App Security Image for Android.
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="THING_SMART_APPKEY"
android:value="Appkey" />
<meta-data
android:name="THING_SMART_APPKEY"
android:value="AppSecret" />
Configure the app certificate.
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.**
# Keep native methods
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclassmembers class * {
native <methods>;
}
Initialize the SDK in the main thread of the Application
. Make sure that all processes are initialized. Example:
public class TuyaSmartApp extends Application {
@Override
public void onCreate() {
super.onCreate();
ThingSdk.init(this);
ThingSmartNetWork.mSdkVersion = "1.3.0";
}
}
Configure appKey
and appSecret
in AndroidManifest.xml
, or set them during initialization.
ThingSdk.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.
ThingSdk.setDebugMode(true);
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. 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 developing with the SDK. Before the development of your app, we recommend that you run the demo app.
The demo app supports the following features:
Demo app:
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.
Run the code.
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.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback