Android关于友盟推送升级相关问题解决

420 阅读2分钟

【版权声明】本文首发于上海竖排网络科技有限公司官方知乎账号,由本人撰写发布,现摘抄至自己掘金账户下,归类学习,复习。 【摘要】最近app在使用友盟相关功能的时候,出现了一系列的问题,直接导致app闪退。。。按道理来说应该不会出现这种情况,所以,特此记载一下。希望别的小伙伴,不要因为一个小问题,搞得没有头绪。

【作者:清泓】

过程:由于要上架商店,反复测试,发现在清除缓存之后的第一次打开app的时候,会导致app闪退的情况。

刚开始以为是初次打开在application里面权限没及时得到,导致获取手机IMEI报空指针。

经过多方面排查,发现是友盟版本过低导致手机IMEI获取异常的问题。

版本由

s=-11,s1=accs bindapp error

//友盟基础组件库         
implementation 'com.umeng.umsdk:common:2.0.2'       
   //友盟PushSDK必须依赖utdid库,所以需要加入对应依赖        
 implementation 'com.umeng.umsdk:utdid:1.1.5.3'        
  //友盟PushSDK       
  implementation 'com.umeng.umsdk:push:5.0.2'

升级为:

//基础组件库依赖(必须) Push 6.2.0版本必须升级新版本Common SDK

 implementation 'com.umeng.umsdk:common:9.3.0'    
 implementation 'com.umeng.umsdk:utdid:1.5.2'  
 implementation  'com.umeng.umsdk:asms:1.1.4'
 //友盟PushSDK implementation 'com.umeng.umsdk:push:6.2.0'
 implementation 'com.umeng.umsdk:alicloud-httpdns:1.2.5'
 implementation 'com.umeng.umsdk:alicloud-utils:1.1.5' 
implementation 'com.umeng.umsdk:alicloud_beacon:1.0.1'
 implementation 'com.umeng.umsdk:agoo-accs:3.3.9.7-open' 
implementation 'com.umeng.umsdk:agoo_networksdk:3.5.5' 
implementation 'com.umeng.umsdk:agoo_tlog:3.0.0.17'
 implementation 'com.umeng.umsdk:agoo_tnet4android:3.1.14.9'
 implementation  'com.umeng.umsdk:oaid_mi:1.0.0' // (可选)
 implementation  'com.umeng.umsdk:oaid_oppo:1.0.4' // (可选)
 implementation  'com.umeng.umsdk:oaid_vivo:1.0.0.1' // (可选)

方案一.检查APP_KEY ,MESSAGE_SCREATE是否正确。就两个字符串,大家都是复制粘贴,这能出什么错。大家初始化失败第一件事就是检查这个吧。

方案二.版本升级检查so是否正确。我这里是第一次集成就出现这问题,显然不是版本升级的原因。说实话,以上两答案说了就跟没说一样。

<!-- 以下为基本配置信息,需要自行添加至您的AndroidManifest文件中 start-->
<service
    android:name="com.taobao.accs.ChannelService"
    android:exported="true"
    android:process=":channel">
    <intent-filter>
        <action android:name="com.taobao.accs.intent.action.SERVICE" />
    </intent-filter>
    <intent-filter>
        <action android:name="com.taobao.accs.intent.action.ELECTION" />
    </intent-filter>
</service>

<service
    android:name="com.taobao.accs.data.MsgDistributeService"
    android:exported="true">
    <intent-filter>
        <action android:name="com.taobao.accs.intent.action.RECEIVE" />
    </intent-filter>
</service>

<receiver
    android:name="com.taobao.accs.EventReceiver"
    android:process=":channel">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_REMOVED" />
        <data android:scheme="package" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.USER_PRESENT" />
    </intent-filter>
</receiver>

<receiver
    android:name="com.taobao.accs.ServiceReceiver"
    android:process=":channel">
    <intent-filter>
        <action android:name="com.taobao.accs.intent.action.COMMAND" />
    </intent-filter>
    <intent-filter>
        <action android:name="com.taobao.accs.intent.action.START_FROM_AGOO" />
    </intent-filter>
</receiver>

<service
    android:name="com.taobao.accs.internal.AccsJobService"
    android:permission="android.permission.BIND_JOB_SERVICE"
    android:process=":channel"/>

<service
    android:name="com.taobao.accs.ChannelService$KernelService"
    android:process=":channel" />

<service
    android:name="org.android.agoo.accs.AgooService"
    android:exported="true">
    <intent-filter>
        <action android:name="com.taobao.accs.intent.action.RECEIVE" />
    </intent-filter>
</service>

<service
    android:name="com.umeng.message.UmengIntentService"
    android:exported="true"
    android:process=":channel">
    <intent-filter>
        <action android:name="org.agoo.android.intent.action.RECEIVE" />
    </intent-filter>
</service>

<service
    android:name="com.umeng.message.XiaomiIntentService"
    android:exported="true"
    android:process=":channel">
    <intent-filter>
        <action android:name="org.agoo.android.intent.action.RECEIVE" />
    </intent-filter>
</service>

<receiver
    android:name="com.taobao.agoo.AgooCommondReceiver"
    android:exported="true"
    android:process=":channel">
    <intent-filter>
        <action android:name="${applicationId}.intent.action.COMMAND" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_REMOVED" />
        <data android:scheme="package" />
    </intent-filter>
</receiver>

<service
    android:name="com.umeng.message.UmengMessageIntentReceiverService"
    android:exported="true"
    android:process=":channel">
    <intent-filter>
        <action android:name="org.android.agoo.client.MessageReceiverService" />
    </intent-filter>
</service>

<receiver
    android:name="com.umeng.message.NotificationProxyBroadcastReceiver"
    android:exported="false" />

<service
    android:name="com.umeng.message.UmengMessageCallbackHandlerService"
    android:permission="android.permission.BIND_JOB_SERVICE"
    android:exported="false">
    <intent-filter>
        <action android:name="com.umeng.messge.registercallback.action" />
    </intent-filter>
    <intent-filter>
        <action android:name="com.umeng.message.enablecallback.action" />
    </intent-filter>
    <intent-filter>
        <action android:name="com.umeng.message.disablecallback.action" />
    </intent-filter>
    <intent-filter>
        <action android:name="com.umeng.message.message.handler.action" />
    </intent-filter>
    <intent-filter>
        <action android:name="com.umeng.message.message.sendmessage.action" />
    </intent-filter>
</service>

<service
    android:name="com.umeng.message.UmengDownloadResourceService"
    android:permission="android.permission.BIND_JOB_SERVICE"
    android:exported="false" />

<provider
    android:name="com.umeng.message.provider.MessageProvider"
    android:authorities="${applicationId}.umeng.message"
    android:exported="false">
    <grant-uri-permission android:pathPattern=".*" />
</provider>
<!-- 以下为基本配置信息,需要自行添加至您的AndroidManifest文件中 end-->

一直绑定失败,log也看不出啥来,demo操作和项目操作一样,那到底哪里出问题了呢?Umeng Push 3.x的集成方式换成了Module的方式,再不是复制拷贝jar和so了。Module直接导入即可,那jar和so到底倒入成功了么?jar导入不成功代码是会报错的,so是否成功解压一下apk看看就知道了。解压了之后果然没有so。呵呵呵。。。。。

在PushSDK 这个 Module 的gradle文件中添加如下代码

android{
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
}
repositories {
    mavenCentral()
    flatDir {
        dirs 'libs' //this way we can find the .aar file in libs folder
    }
}

成功绑定,拿到token

做完上面的操作,注册拿到token,千真万确。我还清除数据重启确认了,确实可以。但是过了一会又失败了,我已经无语了。

最后把so文件干脆拷贝到主工程的libs中。成功解决。