介紹Android SDK在開發(fā)過程中遇到的常見問題和解決方法。
Q:登錄App或注冊時,提示網(wǎng)絡(luò)不順暢
A:檢查以下內(nèi)容是否正確。
- 確認手機時間是否設(shè)置正確,如果有偏差,則會被安全監(jiān)測攔截而導致無法登錄。
- 確認安全圖片是否在src/drawable目錄下。詳細操作請參見集成安全圖片。
//設(shè)置圖片后綴 ConfigManager.getInstance().setSecGuardImagePostfix("xxxx"); //xxxx為安全圖片的后綴名
- 確認初始化中是否有拋出異常。
- 其中ErrorCode=110的異常碼可以忽略
- 以下幾種Warn可以忽略(用來檢查社交賬號SDK)
W/oa_Oauth: [] : Umeng is not available, Umeng Oauth Service Provider is disabled W/oa_Oauth: [] : Taobao MemberSDK is not available, Taobao 3rd Oauth Service Provider is disabled W/oa_Oauth: [] : Taobao login4android SDK is not available, Taobao 2nd Oauth Service Provider is disabled W/oa_Oauth: [] : Alipay sdk is not available, Alipay Oauth Service Provider is disabled
- 如果是用Demo中提供的OALoginAdapter,下面異常日志可以忽略。
java.lang.NullPointerException: Attempt to invoke virtual method 'long java.lang.Long.longValue()' on a null object reference at com.aliyun.iot.aep.sdk.login.oa.OALoginAdapter.a(OALoginAdapter.java:343)
無法打開登錄頁面
A:檢查以下內(nèi)容是否正確。
- 確認日志中是否有以下異常輸出。
init failed code = 10010 message = 發(fā)生錯誤,消息為null,請使用LogCat查看細節(jié), 或者搜索Failed resolution of: Lcom/ut/mini/UTHitBuilders@UTCustomHitBuilder
這種情況說明主工程缺少UT SDK的依賴,請在主工程里增加如下兩個依賴,或者在平臺上重新下載SDK依賴文件。compile 'com.aliyun.ams:alicloud-android-utdid:1.1.5.4' compile 'com.aliyun.ams:alicloud-android-ut:5.1.0'
- 如果啟動直接Crash,查看日志有提示XML相關(guān)的報錯,請檢查Manifest.xml中的packageName和build.gradle中的applicationID必須保持一致。
Q:API通道SDK初始化時,出現(xiàn)ErrorCode=103錯誤
A:查看logcat中是否有類似如下的報錯日志。
12-16 16:26:11.430 10486-10486/? W/System.err: ErrorCode = 103 12-16 16:26:11.430 10486-10486/? W/System.err: com.alibaba.wireless.security.open.SecException: java.lang.UnsatisfiedLinkError: dlopen failed: "/data/data/com.aliyun.iot.demo.wuxi.demoapp/app_SGLib/app_1513412765/libsgmainso-5.3.38.so" is 32-bit instead of 64-bit 12-16 16:26:11.430 10486-10486/? W/System.err: at com.alibaba.wireless.security.mainplugin.SecurityGuardMainPlugin.onPluginLoaded(Unknown Source) 12-16 16:26:11.430 10486-10486/? W/System.err: at com.alibaba.wireless.security.framework.e.a(Unknown Source) 12-16 16:26:11.430 10486-10486/? W/System.err: at com.alibaba.wireless.security.framework.e.c(Unknown Source) 12-16 16:26:11.431 10486-10486/? W/System.err: at com.alibaba.wireless.security.framework.e.c(Unknown Source) 12-16 16:26:11.431 10486-10486/? W/System.err: at com.alibaba.wireless.security.open.initialize.b.a(Unknown Source) 12-16 16:26:11.431 10486-10486/? W/System.err: at com.alibaba.wireless.security.open.initialize.a.loadLibrarySync(Unknown Source) 12-16 16:26:11.431 10486-10486/? W/System.err: at com.alibaba.wireless.security.open.initialize.a.initialize(Unknown Source) 12-16 16:26:11.431 10486-10486/? W/System.err: at com.alibaba.wireless.security.jaq.SecurityInit.Initialize(Unknown Source) 12-16 16:26:11.431 10486-10486/? W/System.err: at com.aliyun.iot.demo.wuxi.demoapp.DemoApplication.onCreate(DemoApplication.java:34) 12-16 16:26:11.431 10486-10486/? W/System.err: at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1025) 12-16 16:26:11.431 10486-10486/? W/System.err: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5403) 12-16 16:26:11.431 10486-10486/? W/System.err: at android.app.ActivityThread.-wrap2(ActivityThread.java) 12-16 16:26:11.431 10486-10486/? W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545) 12-16 16:26:11.431 10486-10486/? W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102) 12-16 16:26:11.431 10486-10486/? W/System.err: at android.os.Looper.loop(Looper.java:154) 12-16 16:26:11.431 10486-10486/? W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6119) 12-16 16:26:11.431 10486-10486/? W/System.err: at java.lang.reflect.Method.invoke(Native Method) 12-16 16:26:11.431 10486-10486/? W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 12-16 16:26:11.431 10486-10486/? W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
如果出現(xiàn)以上日志,一般是so文件加載失敗導致的,可以在build.gradle文件中添加如下配置。
android {
compileSdkVersion 28
defaultConfig {
...
ndk {
abiFilters "arm64-v8a","armeabi-v7a" //API level 7及以上版本的SDK
// abiFilters "armeabi", "x86" //API level 6以及低版本的SDK,過濾除armeabi和x86以外的so文件
}
}
}
Q:API通道SDK初始化時,出現(xiàn)app key or app secret must be initialed錯誤
A:查看logcat中是否有類似如下的報錯日志如下。
10-22 03:03:37.555 18552-18552/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.rnd.kx, PID: 18552 java.lang.RuntimeException: Unable to create application com.rnd.kx.MyApplication: com.alibaba.cloudapi.sdk.exception.SdkException: app key or app secret must be initialed at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4710) at android.app.ActivityThread.-wrap1(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: com.alibaba.cloudapi.sdk.exception.SdkException: app key or app secret must be initialed
如果出現(xiàn)以上日志,檢查以下內(nèi)容是否正確。
- 檢查是否出現(xiàn)203錯誤碼,并根據(jù)導致錯誤的可能原因進行詳細排查。
- 請檢查libsgmain.so是否被打包到APK包的build/outputs/apk/debug目錄下,且確保lib/armeabi和lib/x86文件夾內(nèi)包含該文件。
Q:API 通道 SDK 初始化的時候,出現(xiàn)ErrorCode=202錯誤
A:查看logcat中是否有類似如下的報錯日志如下。
12-16 13:19:06.586 9344-9344/com.aliyun.iot.demo W/System.err: ErrorCode = 202 12-16 13:19:06.587 9344-9344/com.aliyun.iot.demo W/System.err: com.alibaba.wireless.security.open.SecException: 12-16 13:19:06.594 9344-9344/com.aliyun.iot.demo W/System.err: at com.taobao.wireless.security.adapter.JNICLibrary.doCommandNative(Native Method) 12-16 13:19:06.595 9344-9344/com.aliyun.iot.demo W/System.err: at com.alibaba.wireless.security.mainplugin.a.doCommand(Unknown Source:0) 12-16 13:19:06.595 9344-9344/com.aliyun.iot.demo W/System.err: at com.alibaba.wireless.security.a.j.a.getAppKeyByIndex(Unknown Source:21) 12-16 13:19:06.596 9344-9344/com.aliyun.iot.demo W/System.err: at com.alibaba.sdk.android.push.securitybox.alipush.a.getAppKey(Unknown Source:7) 12-16 13:19:06.597 9344-9344/com.aliyun.iot.demo W/System.err: at com.alibaba.sdk.android.push.vip.AppRegister.h(Unknown Source:17) 12-16 13:19:06.597 9344-9344/com.aliyun.iot.demo W/System.err: at com.alibaba.sdk.android.push.vip.AppRegister.a(Unknown Source:34) 12-16 13:19:06.597 9344-9344/com.aliyun.iot.demo W/System.err: at com.alibaba.sdk.android.push.impl.j.a(Unknown Source:30) 12-16 13:19:06.597 9344-9344/com.aliyun.iot.demo W/System.err: at com.alibaba.sdk.android.push.impl.j.register(Unknown Source:1) 12-16 13:19:06.599 9344-9344/com.aliyun.iot.demo W/System.err: at com.aliyun.iot.aep.demo.DemoApplication.initPush(DemoApplication.java:115) 12-16 13:19:06.599 9344-9344/com.aliyun.iot.demo W/System.err: at com.aliyun.iot.aep.demo.DemoApplication.onCreate(DemoApplication.java:27) 12-16 13:19:06.599 9344-9344/com.aliyun.iot.demo W/System.err: at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1118) 12-16 13:19:06.599 9344-9344/com.aliyun.iot.demo W/System.err: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5791) 12-16 13:19:06.599 9344-9344/com.aliyun.iot.demo W/System.err: at android.app.ActivityThread.-wrap1(Unknown Source:0) 12-16 13:19:06.601 9344-9344/com.aliyun.iot.demo W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661) 12-16 13:19:06.601 9344-9344/com.aliyun.iot.demo W/System.err: at android.os.Handler.dispatchMessage(Handler.java:105) 12-16 13:19:06.601 9344-9344/com.aliyun.iot.demo W/System.err: at android.os.Looper.loop(Looper.java:164) 12-16 13:19:06.601 9344-9344/com.aliyun.iot.demo W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6541) 12-16 13:19:06.601 9344-9344/com.aliyun.iot.demo W/System.err: at java.lang.reflect.Method.invoke(Native Method) 12-16 13:19:06.604 9344-9344/com.aliyun.iot.demo W/System.err: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 12-16 13:19:06.604 9344-9344/com.aliyun.iot.demo W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
如果出現(xiàn)以上日志,通常是安全圖片與當前APK的簽名不匹配導致的,可以修改當前APK簽名或者重新上傳APK生成新的安全圖片。
Q:API通道SDK初始化時,出現(xiàn)ErrorCode=203錯誤
A:查看logcat中是否有類似如下的報錯日志如下。
12-16 13:29:59.005 10232-10267/? W/System.err: ErrorCode = 203 12-16 13:29:59.005 10232-10267/? W/System.err: com.alibaba.wireless.security.open.SecException: 12-16 13:29:59.005 10232-10267/? W/System.err: at com.taobao.wireless.security.adapter.JNICLibrary.doCommandNative(Native Method) 12-16 13:29:59.005 10232-10267/? W/System.err: at com.alibaba.wireless.security.mainplugin.a.doCommand(Unknown Source:0) 12-16 13:29:59.005 10232-10267/? W/System.err: at com.alibaba.wireless.security.a.j.a.getAppKeyByIndex(Unknown Source:21) 12-16 13:29:59.005 10232-10267/? W/System.err: at com.alibaba.sdk.android.push.securitybox.alipush.a.getAppKey(Unknown Source:7) 12-16 13:29:59.005 10232-10267/? W/System.err: at com.alibaba.sdk.android.push.securitybox.alipush.a.a(Unknown Source:8) 12-16 13:29:59.005 10232-10267/? W/System.err: at com.alibaba.sdk.android.push.securitybox.alipush.a.getMpsDeviceId(Unknown Source:2) 12-16 13:29:59.005 10232-10267/? W/System.err: at com.alibaba.sdk.android.push.vip.AppRegister$a.b(Unknown Source:68) 12-16 13:29:59.005 10232-10267/? W/System.err: at com.alibaba.sdk.android.push.vip.AppRegister$a.a(Unknown Source:0) 12-16 13:29:59.006 10232-10267/? W/System.err: at com.alibaba.sdk.android.push.vip.b.handleMessage(Unknown Source:54) 12-16 13:29:59.006 10232-10267/? W/System.err: at android.os.Handler.dispatchMessage(Handler.java:105) 12-16 13:29:59.006 10232-10267/? W/System.err: at android.os.Looper.loop(Looper.java:164) 12-16 13:29:59.006 10232-10267/? W/System.err: at android.os.HandlerThread.run(HandlerThread.java:65)
如果出現(xiàn)以上日志,檢查以下內(nèi)容是否正確。
- 沒有找到圖片文件,請確保安全圖片在res\drawable目錄下,并檢查安全圖片的名稱的末四位和當前authCode是否一致。
- 安卓環(huán)境下可能是因為資源優(yōu)化被優(yōu)化成了0,請檢查APK中的圖片。
- 如果開啟混淆,需要檢查發(fā)布包335大小不為0,shrinkResources true會導致
yw_1222_
開頭的圖片大小為0。release { minifyEnabled true // 是否混淆 shrinkResources true //會導致安全圖片大小為0 proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" }
可通過放棄資源壓縮或新建res/raw/keep.xml文件,并在文件中添加以下內(nèi)容。
<?xml version="1.0" encoding="UTF-8"?> resources xmlns:tools="http://schemas.android.com/tools" tools:keep="@drawable/yw_1222_0335, @drawable/yw_1222,@drawable/yw_1222_china_production"
- 如果是在android studio下調(diào)試發(fā)現(xiàn)找不到圖片,但是確認過圖片是正常的,請關(guān)閉Android studio的instant run功能,在instant run下APK并非一個完整bundle,其資源文件被拆分到特定bundle中,圖片路徑發(fā)生改變會導致保鏢找不到圖片。
- 如果開啟混淆,需要檢查發(fā)布包335大小不為0,shrinkResources true會導致
Q:無法初始化登錄SDK,提示發(fā)生錯誤且消息為null
init failed code = 10010 message =
A:可以使用LogCat查看更多日志細節(jié)??赡茉驗槿鄙賁DK依賴,請在主工程的build.gradle中添加以下2個依賴,或者在平臺上重新生成一份dependency.gradle文件。
compile 'com.aliyun.ams:alicloud-android-utdid:1.1.5.4' compile 'com.aliyun.ams:alicloud-android-ut:5.1.0'
Q:訪問API時,API網(wǎng)關(guān)出現(xiàn)以下報錯
code:403, message:request forbidden, localizedMsg:請求被禁止
A:可能原因為該項目AppKey沒有訪問API的權(quán)限,請通過控制臺右上角的工單聯(lián)系我們,并備注AppKey以及請求API的名稱。
Q:出現(xiàn)“unsupported auth type iotAuth”報錯
unsupported auth type iotAuth, maybe you forgot to register IoTAuthProvider
A:參見SDK初始化文檔初始化SDK,初始化IoTCredentialProviderImpl
模塊代碼也放在應用內(nèi)。如需要主動調(diào)用接口還需添加setAuthType("iotAuth")
。
Q:Demo App切換國際站或更換安全圖片后,提示網(wǎng)絡(luò)不順暢或無法連接
A:解決辦法如下。
- 設(shè)置BuildConfig.BUILD_COUNTRY=OVERSEA
- build.gradle里面的CHINA更改為OVERSEA
- Demo App里面的SINGAPORE都更改為OVERSEA
- drawable里面的安全圖片需要更改為國際站的安全圖片
- 將
EnvConfigure.putEnvArg(RNContainerComponentDelegate.KEY_RN_CONTAINER_PLUGIN_ENV, "test");
更改為EnvConfigure.putEnvArg(RNContainerComponentDelegate.KEY_RN_CONTAINER_PLUGIN_ENV, "release");
- RNContainerComponentDelegate.java里面的
BoneConfig.set("region", "china");
更改為BoneConfig.set("region", "singapore");
- 如采用release.gradle里面打包APK方式,更改src/oversea/res和/configure/oversea/里的安全圖片
Q:提示libreactnativejni.so無法找到
A: 查看logcat有如下提示。
java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libreactnativejni.so
at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:738)
at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:591)
at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:529)
at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:484)
at com.facebook.react.bridge.ReactBridge.staticInit(ReactBridge.java:31)
at com.facebook.react.bridge.NativeMap.<clinit>(NativeMap.java:19)
at com.facebook.react.jscexecutor.JSCExecutorFactory.create(JSCExecutorFactory.java:25)
at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:944)
at java.lang.Thread.run(Thread.java:764)
出現(xiàn)上面的錯誤的可能原因是CPU架構(gòu)不支持(目前我們不再支持armeabi和x86架構(gòu)),您可以通過添加以下代碼解決。
android {
compileSdkVersion 28
defaultConfig {
...
ndk {
abiFilters "armeabi-v7a", "arm64-v8a" //過濾armeabi和x86的so文件
}
}
}