unity sdk(android)-友盟推送SDK接入

注意:一开始想接友盟Unity的SDk,但是导入后缺少各种jar,所以最后还是接了android的,demo文档齐全

官方文档:开发者中心

按照官方文档对接即可,

接入流程

1、项目中com.android.tools.build:gradle配置,如果版本号>=3.0.0,请使用如下配置脚本添加远程依赖:

//基础组件库依赖(必须) 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.3'
implementation 'com.umeng.umsdk:crash:0.0.5'

//友盟push相关依赖(必须)
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'

2、在工程build.gradle配置脚本中buildscript和allprojects段中添加【友盟+】sdk 新maven仓库地址(注意位置别添加错,不然依赖项出错)

buildscript {
    repositories {
        google()
        jcenter()
        //友盟添加
        maven { url 'https://dl.bintray.com/umsdk/release' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        //友盟添加
        maven { url 'https://dl.bintray.com/umsdk/release' }
    }
}

3、【特别注意】添加aranger库的依赖。下载aranger-x.x.x.jar库拷贝到项目工程的libs目录并引用该库。

4、在AndroidManifest.xml文件中引入权限声明:

<!-- 以下为需要的基本权限,需要自行添加至您的AndroidManifest文件中 start-->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.BROADCAST_PACKAGE_ADDED" />
    <uses-permission android:name="android.permission.BROADCAST_PACKAGE_CHANGED" />
    <uses-permission android:name="android.permission.BROADCAST_PACKAGE_INSTALL" />
    <uses-permission android:name="android.permission.BROADCAST_PACKAGE_REPLACED" />
    <uses-permission android:name="android.permission.GET_TASKS" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <!-- 以下为需要的基本权限,需要自行添加至您的AndroidManifest文件中 end-->

在AndroidManifest.xml文件中引入相关基础组件:

<!-- 以下为基本配置信息,需要自行添加至您的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-->

5、引入so文件:全平台so文件下载地址

注意下载的so文件要和sdk里面平台一致,缺少会导致deviceToken获取失败,最好从demo全部复制出来用, unity项目要加在 libs和jnilibs里面

基础接口引入

1、务必在工程的自定义Application类的 onCreate() 方法中做SDK代码初始化工作。

// 在此处调用基础组件包提供的初始化函数 相应信息可在应用管理 -> 应用信息 中找到 http://message.umeng.com/list/apps
// 参数一:当前上下文context;
// 参数二:应用申请的Appkey(需替换);
// 参数三:渠道名称;
// 参数四:设备类型,必须参数,传参数为UMConfigure.DEVICE_TYPE_PHONE则表示手机;传参数为UMConfigure.DEVICE_TYPE_BOX则表示盒子;默认为手机;
// 参数五:Push推送业务的secret 填充Umeng Message Secret对应信息(需替换)
UMConfigure.init(this, "替换为Appkey,服务后台位置:应用管理 -> 应用信息 -> Appkey", "Umeng", UMConfigure.DEVICE_TYPE_PHONE, "替换为秘钥信息,服务后台位置:应用管理 -> 应用信息 -> Umeng Message Secret");

//例如:UMConfigure.init(this, "5fbb2b49690bda19c7877192", "toutiao", UMConfigure.DEVICE_TYPE_PHONE, "6a2abdbd2938c67e698e949cc9335e3e");

2、Push注册在UMConfigure.init方法之后注册,注册成功后可获取deviceToken,进行消息下发。调用代码如下所示:


UMConfigure.init(this, "替换为Appkey,服务后台位置:应用管理 -> 应用信息 -> Appkey", "Umeng", UMConfigure.DEVICE_TYPE_PHONE, "替换为秘钥信息,服务后台位置:应用管理 -> 应用信息 -> Umeng Message Secret");
//获取消息推送代理示例
PushAgent mPushAgent = PushAgent.getInstance(this);
//注册推送服务,每次调用register方法都会回调该接口
mPushAgent.register(new IUmengRegisterCallback() {

  @Override
  public void onSuccess(String deviceToken) {
    //注册成功会返回deviceToken deviceToken是推送消息的唯一标志
    Log.i(TAG,"注册成功:deviceToken:-------->  " + deviceToken);
  }

  @Override
  public void onFailure(String s, String s1) {
    Log.e(TAG,"注册失败:-------->  " + "s:" + s + ",s1:" + s1);
  }
});

混淆配置

在proguard-unity.txt添加如下混淆代码

-dontwarn com.umeng.**
-dontwarn com.taobao.**
-dontwarn anet.channel.**
-dontwarn anetwork.channel.**
-dontwarn org.android.**
-dontwarn org.apache.thrift.**
-dontwarn com.xiaomi.**
-dontwarn com.huawei.**
-dontwarn com.meizu.**

-keepattributes *Annotation*

-keep class com.taobao.** {*;}
-keep class org.android.** {*;}
-keep class anet.channel.** {*;}
-keep class com.umeng.** {*;}
-keep class com.xiaomi.** {*;}
-keep class com.huawei.** {*;}
-keep class com.meizu.** {*;}
-keep class org.apache.thrift.** {*;}

-keep class com.alibaba.sdk.android.**{*;}
-keep class com.ut.**{*;}
-keep class com.ta.**{*;}

-keep public class **.R$*{
   public static final int *;
}

注意事项:

1、Appkey一定得用对应包名生成出来的。

2、载的so文件要和sdk里面平台一致,缺少会导致deviceToken获取失败,最好从demo全部复制出来用, unity项目要加在 libs和jnilibs里面

3、无法获取到Device Token

P_10000

问法1:注册不成功,无法获取到device token,并且log中显示accs bindapp error

问法2:注册不成功,无法获取到device token,并且TNET_LOAD_SO_FAIL

解决方案:

1、检查appkey和secret key是否配置正确。

2、解压缩你的apk,看一下libs目录里的so文件夹,确保每个so文件夹里都有PushSDK的so文件。

3、PushSDK 3.x默认只提供armeabi和x86两种so文件夹,若主工程(除PushSDK外的Module均看做是主工程)中的so文件夹与PushSDK下的so文件夹不一致,则可以有两种方式处理(选择一种即可):

1) 删除主工程下多余的so文件夹,与PushSDK下的so文件夹保持一致。

2) 在官网PushSDK下载处,下载全平台so文件,添加缺少的so文件夹至 PushSDK下,使PushSDK的so文件夹与主工程的so文件夹保持一致。

下载链接:https://files.alicdn.com/tpsservice/7c94e1a0a2e35f6f27038c974ad9ffbf.zip

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值