全部产品
云市场

移动推送Android SDK:推送在初始化时报"java.lang.UnsatisfiedLinkError"或”TNET-JNI-LOAD-SO-FAIL“错误,这是什么原因引起的?

更新时间:2017-06-07 13:26:11

1.问题

在推送SDK初始化的过程中报类似如下的错误:

  1. java.lang.UnsatisfiedLinkError: No implementation found for int org.android.spdy.SpdyAgent.configLogFileN(java.lang.String, int, int) (tried Java_org_android_spdy_SpdyAgent_configLogFileN and Java_org_android_spdy_SpdyAgent_configLogFileN__Ljava_lang_String_2II)
  2. at org.android.spdy.SpdyAgent.configLogFileN(Native Method)
  3. at org.android.spdy.SpdyAgent.configLogFile(Unknown Source)
  4. at com.taobao.accs.net.e.<init>(Unknown Source)
  5. at com.taobao.accs.net.BaseConnection.a(Unknown Source)
  6. at com.taobao.accs.internal.ACCSManagerImpl.sendControlMessage(Unknown Source)
  7. at com.taobao.accs.internal.ACCSManagerImpl.bindApp(Unknown Source)
  8. at com.taobao.accs.a.a(Unknown Source)
  9. at com.taobao.agoo.AliyunRegister.register(Unknown Source)
  10. at com.alibaba.sdk.android.push.vip.AppRegister$a.b(Unknown Source)
  11. at com.alibaba.sdk.android.push.vip.AppRegister$a.a(Unknown Source)
  12. at com.alibaba.sdk.android.push.vip.b.handleMessage(Unknown Source)
  13. at android.os.Handler.dispatchMessage(Handler.java:102)
  14. at android.os.Looper.loop(Looper.java:148)
  15. at android.os.HandlerThread.run(HandlerThread.java:61)

  1. 04-20 11:34:02.035 15264-15383/cloud.aliyun.test E/awcn.TnetSpdySession: |[seq:AWCN2_2] connect exception org.android.spdy.SpdyErrorException: TNET_JNI_ERR_LOAD_SO_FAIL
  2. at org.android.spdy.SpdyAgent.checkLoadSo(Unknown Source)
  3. at org.android.spdy.SpdyAgent.agentIsOpen(Unknown Source)
  4. at org.android.spdy.SpdyAgent.createSession(Unknown Source)
  5. at org.android.spdy.SpdyAgent.createSession(Unknown Source)
  6. at anet.channel.d.l.b(Unknown Source)
  7. at anet.channel.SessionRequest.a(Unknown Source)
  8. at anet.channel.SessionRequest.a(Unknown Source)
  9. at anet.channel.SessionRequest$a.onFailed(Unknown Source)
  10. at anet.channel.k.onEvent(Unknown Source)
  11. at anet.channel.i.run(Unknown Source)
  12. at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
  13. at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  14. at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
  15. at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
  16. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  17. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  18. at java.lang.Thread.run(Thread.java:818)

这是什么原因引起的?

2.问题原因

推送SDK包含有so包(libtnet、libcocklogic),出现上述错误都是由于so包没有被成功加载导致的。请通过以下方法确认so包是被被正常添加:

将生成的.apk文件以.zip文件解压,查看对应的jniLibs是否正确包含armeabi、armeabi-v7a、x86体系架构的目录,检查是否有移动推送的libcocklogic.so和libtnet.so

3.解决方案

  1. 通过远程同步的方式集成推送SDK。推送SDK在V3.0.0及以上版本开始支持远程同步集成,在远程同步的过程中so包也被自动同步。推送SDK当前提供:armeabi,armeabi-v7a,arm64-v8a,mips,mips-64,x86,x86_64等架构的so包,如果您不需要这么多,可以在build.gradle文件中进行配置,选择需要的so包:

    1. android {
    2. ......
    3. defaultConfig {
    4. applicationId "com.xxx.xxx"
    5. ......
    6. ndk {
    7. //选择要添加的对应cpu类型的.so库。
    8. abiFilters 'armeabi', 'armeabi-v7a', 'armeabi-v8a'
    9. // 还可以添加 'x86', 'x86_64', 'mips', 'mips64'
    10. }
    11. ......
    12. }
    13. ......
    14. }
  2. 手动添加so包,将所需架构的so包放到指定路径默认为”src/main/jniLibs/‘’,若设置其他路径如libs,需要手动在build.gradle文件中指定:

    1. android {
    2. compileSdkVersion 23
    3. buildToolsVersion "23.0.1"
    4. sourceSets {
    5. main {
    6. jniLibs.srcDirs = ['libs']
    7. }
    8. }
    9. }