使用jcenter自动集成
说明 : 使用jcenter自动集成的开发者,不需要在项目中添加jar和so,jcenter会自动完成依赖;在AndroidManifest.xml中不需要添加任何JPush SDK 相关的配置,jcenter会自动导入。
一.进入极光推送官网,如果是新用户则需要注册账号
二.进行登陆并获取Appkey
三.参照Android SDK集成指南进行以下操作
1. 确认android studio的 Project 根目录的主 gradle 中配置了jcenter支持。
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'org.greenrobot:greendao-gradle-plugin:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
2.
在 module 的 gradle 中添加依赖和AndroidManifest的替换变量。
defaultConfig {
applicationId "com.zhiyuan3g.newseveryday"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
ndk{
//选择要添加的对应cpu类型的.so库。
abiFilters 'armeabi', 'armeabi-v7a', 'armeabi-v8a','x86','x86_64', 'mips', 'mips64'
}
manifestPlaceholders = [
JPUSH_PKGNAME : applicationId,
JPUSH_APPKEY : "50626445f265d47a30a6fb84", //JPush上注册的包名对应的appkey.
JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
]
dependencies {
compile 'cn.jiguang.sdk:jpush:3.0.3' // 此处以JPush 3.0.3 版本为例。
compile 'cn.jiguang.sdk:jcore:1.1.1' // 此处以JCore 1.1.1 版本为例。
}
3.在自定义Application类中进行初始化操作
public class MyApplication extends Application{
@Override
public void onCreate() {
super.onCreate();
JPushInterface.init(this);
}
}
三.在极光推送官网上进行发送一条消息
四.打开虚拟机并运行程序