具体 步骤 :
参照 官网 的 集成文档说明 ,但是鉴于 之前 出现的问题 ,再做一次 总结。
1.
jcenter()
保证 project 的 gradle 中 支持 jcenter
而且目前 一般 新创建的项目 都支持
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() maven { url "https://jitpack.io" }//recyclerviewadapterhelper的依赖 } }
2.app 的gradle 中 添加 极光 相关的内容
defaultConfig { applicationId "自己项目的包名" minSdkVersion 15 targetSdkVersion 25 versionCode 113 versionName "1.1.3" multiDexEnabled true testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" ndk { //选择要添加的对应cpu类型的.so库。 abiFilters 'armeabi', 'armeabi-v7a', 'armeabi-v8a' // 还可以添加 'x86', 'x86_64', 'mips', 'mips64' } manifestPlaceholders = [ JPUSH_PKGNAME : applicationId, JPUSH_APPKEY : "自己的APPkey", //JPush上注册的包名对应的appkey. JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可. ] }
注意添加的位置
3.
/** 极光推送的sdk 依赖 */ compile 'cn.jiguang.sdk:jpush:3.1.0' // 此处以JPush 3.1.0 版本为例。 compile 'cn.jiguang.sdk:jcore:1.1.8' // 此处以JCore 1.1.8 版本为例。
添加依赖
4.第四步 : 直接 clean project 即可 :
注意:此时 已经完成 ,所有的 集成 过程 ,不需要 再手动拷贝 jar包 so文件 等
也不需要 在配置文件中 ,拷贝 相关的 service 之类的内容 ,配置文件中 ,如果需要 自定义的消息 做处理 添加 接收自定义消息的 receiver 即可
<!-- 用户自定义的广播接收器 用于处理 自定义的消息--> <receiver android:name=".receiver.MyReceiver" android:enabled="true" android:exported="false"> <intent-filter> <action android:name="cn.jpush.android.intent.REGISTRATION"/> <!--Required 用户注册SDK的intent--> <action android:name="cn.jpush.android.intent.UNREGISTRATION"/> <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED"/> <!--Required 用户接收SDK消息的intent--> <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED"/> <!--Required 用户接收SDK通知栏信息的intent--> <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED"/> <!--Required 用户打开自定义通知栏的intent--> <action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK"/> <!--Optional 用户接受Rich Push Javascript 回调函数的intent--> <action android:name="cn.jpush.android.intent.CONNECTION"/><!-- 接收网络变化 连接/断开 since 1.6.3 --> <category android:name="${applicationId}"/> </intent-filter> </receiver>