Android SDK 集成指南

最近更新:2026-08-27
展开全部
Android SDK 集成指南

使用提示

本文是 JPush Android SDK 标准的集成指南文档。用以指导 SDK 的使用方法,默认读者已经熟悉 IDE(Eclipse 或者 Android Studio)的基本使用方法,以及具有一定的 Android 编程知识基础。

本篇指南匹配的 JPush Android SDK 版本为:3.0.0 及以后版本。

  • 三分钟完成 Demo 体验(Android):如果您想要快速地测试、感受下极光推送的效果,请参考本文在几分钟内跑通 Demo。
  • 极光推送 文档网站 上,有极光推送相关的所有指南、API、教程等全部的文档。包括本文档的更新版本,都会及时地发布到该网站上。
  • 如果您看到本文档,但还未下载 Android SDK,请访问 组装 SDK 服务 并下载。

产品功能说明

极光推送(JPush)是一个端到端的推送服务,使得服务器端消息能够及时地推送到终端用户手机上,让开发者积极地保持与用户的连接,从而提高用户活跃度、提高应用的留存率。极光推送客户端支持 Android,iOS,HarmonyOS,QuickApp 多个平台。

本 Android SDK 方便开发者基于 JPush 来快捷地为 Android App 增加推送功能。

主要功能

  • 保持与服务器的长连接,以便消息能够即时推送到达客户端
  • 接收通知与自定义消息,并向开发者 App 传递相关信息

主要特点

  • 客户端维持连接占用资源少、耗电低
  • SDK 丰富的接口,可定制通知栏提示样式
  • 服务器大容量、稳定

SDK 所支持的 Android 系统版本

  • 从 JPush Android SDK v6.0.3 起,最低支持 Android 5.0(API 21)。集成 v6.0.3 及以上版本时,应用的 minSdkVersion 必须不低于 21,富媒体信息流、应用内消息功能同样受此最低系统版本限制。
  • 更早版本请以对应版本的 SDK 集成包和版本说明为准,并同时满足所用 JCore 和厂商通道 SDK 的系统版本要求。

使用 JPush Android SDK v6.0.3 及以上版本时,在应用模块的 build.gradle 中配置最低系统版本,例如:

android { defaultConfig { minSdkVersion 21 } }
          android {
    defaultConfig {
        minSdkVersion 21
    }
}

        
此代码块在浮窗中显示

Gradle 自动集成方式(推荐)

通过 Gradle 自动集成,无需手动添加 SDK 的 JAR 和 SO。SDK 依赖由 Gradle 解析下载,AAR 中的 Manifest 由 Android 构建工具合并;AppKey、回调组件等仍需按下文配置。

如果需要处理收到的消息、使用 3.0.7 版本支持的别名与标签的新接口,AndroidManifest 中的自定义广播接收器仍需开发者手动配置,参考 SDK 压缩包里的 AndroidManifest.xml 样例文件。

修改组件属性

如果开发者需要修改组件属性,可以在本地的 AndroidManifest 中定义同名的组件并配置想要的属性,然后用 xmlns:tools 来控制本地组件覆盖 SDK AAR 中的组件。示例:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.tests.flavorlib.app" xmlns:tools="http://schemas.android.com/tools"> <application android:icon="@drawable/icon" android:name="com.example.jpushdemo.ExampleApplication" android:label="@string/app_name" > </application> </manifest>
          <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.tests.flavorlib.app"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:icon="@drawable/icon"
        android:name="com.example.jpushdemo.ExampleApplication"
        android:label="@string/app_name" >

  </application>

</manifest>

        
此代码块在浮窗中显示

配置 SDK 依赖仓库

在工程的依赖仓库配置中添加极光官方 SDK Maven 仓库,无需下载账号。SDK 的 groupId、artifactId 与依赖声明保持不变,版本按下节所选已发布版本填写。请保留 google() 和 mavenCentral(),用于解析工程的其他依赖。

如果工程已在 settings.gradle 或 settings.gradle.kts 中集中管理依赖仓库,请在现有 dependencyResolutionManagement.repositories 中加入以下 Maven 配置,不要重复创建配置块。以下写法同时适用于这两种文件,保留工程原有的 repositoriesMode 配置。

dependencyResolutionManagement { repositories { google() maven { url = uri("https://maven.jiguang.cn/nexus/content/repositories/releases/") } mavenCentral() } }
          dependencyResolutionManagement {
    repositories {
        google()
        maven {
            url = uri("https://maven.jiguang.cn/nexus/content/repositories/releases/")
        }
        mavenCentral()
    }
}

        
此代码块在浮窗中显示

旧工程如果仍在根目录的 build.gradle 中通过 allprojects.repositories 管理依赖仓库,请在该处添加:

allprojects { repositories { google() maven { url = uri("https://maven.jiguang.cn/nexus/content/repositories/releases/") } mavenCentral() } }
          allprojects {
    repositories {
        google()
        maven {
            url = uri("https://maven.jiguang.cn/nexus/content/repositories/releases/")
        }
        mavenCentral()
    }
}

        
此代码块在浮窗中显示

按工程现有的仓库管理位置选择上述一种方式,不要重复配置。SDK 仓库用于依赖解析,不要只添加到插件使用的 buildscript.repositories,也无需修改原有的插件仓库配置。

配置依赖和替换变量

在 module 的 gradle 中添加依赖和 AndroidManifest 的替换变量。

android { ...... defaultConfig { applicationId "com.xxx.xxx" //JPush 上注册的包名. ...... ndk { //选择要添加的对应 cpu 类型的 .so 库。 abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a' // 还可以添加 'x86', 'x86_64', 'mips', 'mips64' } manifestPlaceholders = [ JPUSH_PKGNAME : applicationId, JPUSH_APPKEY : "你的 Appkey ", //JPush 上注册的包名对应的 Appkey. JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可. ] ...... } ...... } dependencies { ...... implementation 'cn.jiguang.sdk:jpush:6.x.x' // 必选,此处填写当前最新发布版本(版本填写格式示例:6.2.0),注意:5.0.0 版本开始可以自动拉取 JCore 包,无需另外配置 implementation 'cn.jiguang.sdk:joperate:x.x.x' // 可选,集成极光分析SDK后,即可支持行为触发推送消息、推送转化率统计,用户行为分析和用户标签等功能 }
          android {
    ......
    defaultConfig {
    applicationId "com.xxx.xxx" //JPush 上注册的包名.
    ......

    ndk {
        //选择要添加的对应 cpu 类型的 .so 库。
        abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a'
        // 还可以添加 'x86', 'x86_64', 'mips', 'mips64'
    }

    manifestPlaceholders = [
        JPUSH_PKGNAME : applicationId,
        JPUSH_APPKEY : "你的 Appkey ", //JPush 上注册的包名对应的 Appkey.
        JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
    ]
    ......
}
......
}

dependencies {
......

implementation 'cn.jiguang.sdk:jpush:6.x.x'        // 必选,此处填写当前最新发布版本(版本填写格式示例:6.2.0),注意:5.0.0 版本开始可以自动拉取 JCore 包,无需另外配置
implementation 'cn.jiguang.sdk:joperate:x.x.x'     // 可选,集成极光分析SDK后,即可支持行为触发推送消息、推送转化率统计,用户行为分析和用户标签等功能

}

        
此代码块在浮窗中显示

极光分析SDK更多功能和API详见极光分析SDK集成指南

  • 如果需要使用指定版本的 JCore,可以使用如下命令,不再自动拉取最新版jcore

    implementation ('cn.jiguang.sdk:jpush:6.x.x'){ exclude group: 'cn.jiguang.sdk', module: 'jcore' //不再使用自动拉取的最新版 JCore } implementation 'cn.jiguang.sdk:jcore:5.x.x' //使用指定的 JCore 版本
              implementation ('cn.jiguang.sdk:jpush:6.x.x'){
         exclude group: 'cn.jiguang.sdk', module: 'jcore'   //不再使用自动拉取的最新版 JCore
    }
    implementation 'cn.jiguang.sdk:jcore:5.x.x'               //使用指定的 JCore 版本
    
            
    此代码块在浮窗中显示
  • 当使用的 JPush ≥ 5.0.0 且 JCore < 4.2.0时,需要在清单文件中添加以下配置:

<provider tools:node="remove" android:exported="false" android:authorities="${applicationId}.jiguang.InitProvider" android:name="cn.jpush.android.service.InitProvider"></provider>
          <provider tools:node="remove"
            android:exported="false"
            android:authorities="${applicationId}.jiguang.InitProvider"
            android:name="cn.jpush.android.service.InitProvider"></provider>

        
此代码块在浮窗中显示
  • 如果使用的 JPush < 5.0.0 版本时,需要配置 JCore 依赖:
implementation 'cn.jiguang.sdk:jpush:4.x.x' implementation 'cn.jiguang.sdk:jcore:4.x.x'
          implementation 'cn.jiguang.sdk:jpush:4.x.x'
implementation 'cn.jiguang.sdk:jcore:4.x.x'

        
此代码块在浮窗中显示

Google Play 版本

如果你希望使用 Google Play 版本,则自动集成时需要选择 Google Play 版本对应 SDK

  • 5.0.0 版本开始可以自动拉取 JCore 包,无需另外配置,配置如下:
dependencies { ...... implementation 'cn.jiguang.sdk:jpush-google:6.x.x' // 此处填写当前最新发布版本(版本填写格式示例:6.2.0) }
          dependencies {
......

implementation 'cn.jiguang.sdk:jpush-google:6.x.x'  // 此处填写当前最新发布版本(版本填写格式示例:6.2.0)

}

        
此代码块在浮窗中显示
  • 如果想剔除 JPush 自动依赖的 JCore,可以使用以下方式:
implementation ('cn.jiguang.sdk:jpush-google:6.x.x'){ // 此处填写您实际集成版本(版本填写格式示例:6.2.0) exclude group: 'cn.jiguang.sdk', module: 'jcore-google'//会自动把 JCore 剔除 }
          
implementation ('cn.jiguang.sdk:jpush-google:6.x.x'){  // 此处填写您实际集成版本(版本填写格式示例:6.2.0)
       exclude group: 'cn.jiguang.sdk', module: 'jcore-google'//会自动把 JCore 剔除
}

        
此代码块在浮窗中显示
  • 注意 :当使用JPush 5.0.0 及以上版本时,用户移除了JPush自动依赖的JCore版本,而使用自己依赖的JCore其他版本当JCore版本< 4.2.0时,需要在清单文件中添加以下配置:
<provider tools:node="remove" android:exported="false" android:authorities="${applicationId}.jiguang.InitProvider" android:name="cn.jpush.android.service.InitProvider"></provider>
          <provider tools:node="remove"
            android:exported="false"
            android:authorities="${applicationId}.jiguang.InitProvider"
            android:name="cn.jpush.android.service.InitProvider"></provider>

        
此代码块在浮窗中显示
  • 如果使用 JPush 5.0.0 及以下版本时,需要配置 JCore 依赖:
implementation 'cn.jiguang.sdk:jpush-google:4.x.x' implementation 'cn.jiguang.sdk:jcore-google:4.x.x'
          implementation 'cn.jiguang.sdk:jpush-google:4.x.x'
implementation 'cn.jiguang.sdk:jcore-google:4.x.x'

        
此代码块在浮窗中显示

配置 Service

如果你使用的 JCore 是 2.0.0 及以上的版本,需要额外在 Androidmanifest 中配置一个 Service,以在更多手机平台上获得更稳定的支持,示例如下。(JCore1.x 版本不需要)

<!-- Since JCore2.0.0 Required SDK核心功能--> <!-- 可配置android:process参数将Service放在其他进程中;android:enabled属性不能是false --> <!-- 这个是自定义Service,要继承极光JCommonService,可以在更多手机平台上使得推送通道保持的更稳定 --> <service android:name="xx.xx.XService" android:enabled="true" android:exported="false" android:process=":pushcore"> <intent-filter> <action android:name="cn.jiguang.user.service.action" /> </intent-filter> </service>
           <!-- Since JCore2.0.0 Required SDK核心功能-->
 <!-- 可配置android:process参数将Service放在其他进程中;android:enabled属性不能是false -->
 <!-- 这个是自定义Service,要继承极光JCommonService,可以在更多手机平台上使得推送通道保持的更稳定 -->
 <service android:name="xx.xx.XService"
         android:enabled="true"
         android:exported="false"
         android:process=":pushcore">
         <intent-filter>
             <action android:name="cn.jiguang.user.service.action" />
         </intent-filter>
 </service>

        
此代码块在浮窗中显示

配置 Receiver

从 JPush3.0.7 开始,需要配置继承 JPushMessageReceiver 的广播,原来如果配了 MyReceiver 现在可以弃用。示例如下。

<!-- Required since 3.0.7 --> <!-- 新的 tag/alias 接口结果返回需要开发者配置一个自定的广播 --> <!-- 3.3.0开始所有事件将通过该类回调 --> <!-- 该广播需要继承 JPush 提供的 JPushMessageReceiver 类, 并如下新增一个 Intent-Filter --> <receiver android:name="自定义 Receiver" android:enabled="true" android:exported="false" > <intent-filter> <!-- 从 JPush v5.4.0 版本开始,请特别注意 RECEIVER_MESSAGE 写法, 如配置错误则无法找到回调类 --> <action android:name="cn.jpush.android.intent.RECEIVER_MESSAGE" /> <category android:name="您应用的包名" /> </intent-filter> </receiver>
           <!-- Required since 3.0.7 -->
 <!-- 新的 tag/alias 接口结果返回需要开发者配置一个自定的广播 -->
 <!-- 3.3.0开始所有事件将通过该类回调 -->
 <!-- 该广播需要继承 JPush 提供的 JPushMessageReceiver 类, 并如下新增一个 Intent-Filter -->
 <receiver
       android:name="自定义 Receiver"
       android:enabled="true"
       android:exported="false" >
       <intent-filter>
            <!-- 从 JPush v5.4.0 版本开始,请特别注意 RECEIVER_MESSAGE 写法, 如配置错误则无法找到回调类 -->
            <action android:name="cn.jpush.android.intent.RECEIVER_MESSAGE" />
            <category android:name="您应用的包名" />
       </intent-filter>
 </receiver>

        
此代码块在浮窗中显示

注 :SDK回调方式说明

  • SDK版本:3.0.7<= x < 5.2.0 和 5.4.0及以上 使用receiver 方式
  • SDK版本:5.2.0<= x <=5.3.1 使用service 方式

注 : 如果在添加以上 abiFilter 配置之后 android Studio 出现以下提示:

NDK integration is deprecated in the current plugin. Consider trying the new experimental plugin
          NDK integration is deprecated in the current plugin. Consider trying the new experimental plugin

        
此代码块在浮窗中显示

则在 Project 根目录的 gradle.properties 文件中添加:

android.useDeprecatedNdk=true
          android.useDeprecatedNdk=true

        
此代码块在浮窗中显示

注 : 使用 NDK r17 时,可能 Android Studio 会出现以下提示:

A problem occurred starting process ‘command ‘/Users/xxx/Library/Android/sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt /darwin-x86_64/bin/mips64el-linux-android-strip” 系统找不到指定的文件
          A problem occurred starting process ‘command
‘/Users/xxx/Library/Android/sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt
/darwin-x86_64/bin/mips64el-linux-android-strip”

系统找不到指定的文件

        
此代码块在浮窗中显示

这是因为 NDK r17 之后不再支持 mips 平台,在 build.gradle 里增加如下配置可解决

android { defaultConfig { ..... } packagingOptions { doNotStrip '*/mips/*.so' doNotStrip '*/mips64/*.so' } }
          android {

    defaultConfig {
        .....
    }

    packagingOptions {
        doNotStrip '*/mips/*.so'
        doNotStrip '*/mips64/*.so'
    }
}

        
此代码块在浮窗中显示

若没有 res/drawable-xxxx/jpush_notification_icon 这个资源默认使用应用图标作为通知 icon,在 5.0 以上系统将应用图标作为 statusbar icon 可能显示不正常,用户可定义没有阴影和渐变色的 icon 替换这个文件,文件名不要变。

配置和代码说明

必须权限说明

权限 用途
You Package.permission.JPUSH_MESSAGE 官方定义的权限,允许应用接收 JPush 内部代码发送的广播消息。
INTERNET 允许应用可以访问网络。
ACCESS_NETWORK_STATE 允许应用获取网络信息状态,如当前的网络连接是否有效。

集成 JPush Android SDK 的混淆

  • 请下载 4.x 及以上版本的 proguard.jar, 并替换你 Android SDK "tools\proguard\lib\proguard.jar"

  • 请在工程的混淆文件中添加以下配置:

-dontoptimize -dontpreverify -dontwarn cn.jpush.** -keep class cn.jpush.** { *; } -keep class * extends cn.jpush.android.service.JPushMessageReceiver { *; } -dontwarn cn.jiguang.** -keep class cn.jiguang.** { *; }
              -dontoptimize
    -dontpreverify

    -dontwarn cn.jpush.**
    -keep class cn.jpush.** { *; }
    -keep class * extends cn.jpush.android.service.JPushMessageReceiver { *; }

    -dontwarn cn.jiguang.**
    -keep class cn.jiguang.** { *; }

        
此代码块在浮窗中显示
  • 2.0.5 ~ 2.1.7 版本有引入 gson 和 protobuf,增加排除混淆的配置。(2.1.8 版本不需配置)
#==================gson && protobuf========================== -dontwarn com.google.** -keep class com.google.gson.** {*;} -keep class com.google.protobuf.** {*;}
                  #==================gson && protobuf==========================
        -dontwarn com.google.**
        -keep class com.google.gson.** {*;}
        -keep class com.google.protobuf.** {*;}

        
此代码块在浮窗中显示

关于资源混淆

极光 SDK 资源不能混淆,如果有资源混淆需要添加以下白名单:

andResGuard { ... whiteList = [ "R.xml.jpush*", "R.drawable.jpush*", "R.layout.jpush*", "R.layout.push*", "R.string.jg*", "R.style.MyDialogStyle", "R.style.JPushTheme" ] ... }
          andResGuard {
   ...
    whiteList = [
        "R.xml.jpush*",
        "R.drawable.jpush*",
        "R.layout.jpush*",
        "R.layout.push*",
        "R.string.jg*",
        "R.style.MyDialogStyle",
        "R.style.JPushTheme"
    ]
    ...
}

        
此代码块在浮窗中显示

添加代码

JPush SDK 提供的 API 接口,都主要集中在 cn.jpush.android.api.JPushInterface 类里。

基础 API

  • init 初始化 SDK 与开启推送服务 API

特别提醒:
1. 考虑 APP 上线合规,开发者必须在APP用户同意了隐私政策,并且开发者确定为App用户开始提供推送服务后,再调用此接口启用推送业务功能来使用极光服务。
2. 关于 APP 隐私政策建议和说明,具体可以参考 极光推送SDK合规指引。

public static void init(Context context, JPushConfig config);
          public static void init(Context context, JPushConfig config);

        
此代码块在浮窗中显示
  • setDebugMode 设置调试模式

注:该接口需在 init 接口之前调用,避免出现部分日志没打印的情况。多进程情况下建议在自定义的 Application 中 onCreate 中调用。

// You can enable debug mode in developing state. You should close debug mode when release. public static void setDebugMode(boolean debugEnalbed)
          // You can enable debug mode in developing state. You should close debug mode when release.
public static void setDebugMode(boolean debugEnalbed)

        
此代码块在浮窗中显示

添加统计代码

调用示例代码(参考 example 项目)

  • init 只需要在应用程序启动时调用一次该 API 即可。

  • 以下代码定制一个本应用程序 Application 类。需要在 AndoridManifest.xml 里配置。请参考上面 AndroidManifest.xml 片断,或者 example 项目。

public class ExampleApplication extends Application { @Override public void onCreate() { super.onCreate(); JPushInterface.setDebugMode(true); // 调整点一:调用启用推送业务功能代码前增加setAuth调用 boolean isPrivacyReady; // app根据是否已弹窗获取隐私授权来赋值 if(!isPrivacyReady){ // JCore 5.0.4之前版本需要显式设置false if (JCoreInterface.getJCoreSDKVersionInt() < 504) { // 5.0.4版本号对应504 JCollectionAuth.setAuth(context, false); } // 所有版本在未授权时都不应初始化SDK return; } JPushInterface.init(this); // 调整点二:App用户同意了隐私政策授权,并且开发者确定要开启推送服务后调用 // JCore 5.0.4+会自动处理授权状态,可不需要显式设置true JCollectionAuth.setAuth(context, true); } }
          public class ExampleApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        JPushInterface.setDebugMode(true);

      // 调整点一:调用启用推送业务功能代码前增加setAuth调用
      boolean isPrivacyReady; // app根据是否已弹窗获取隐私授权来赋值
      if(!isPrivacyReady){
        // JCore 5.0.4之前版本需要显式设置false
        if (JCoreInterface.getJCoreSDKVersionInt() < 504) { // 5.0.4版本号对应504
          JCollectionAuth.setAuth(context, false);
        }
        // 所有版本在未授权时都不应初始化SDK
        return;
      }
      JPushInterface.init(this);


      // 调整点二:App用户同意了隐私政策授权,并且开发者确定要开启推送服务后调用
      // JCore 5.0.4+会自动处理授权状态,可不需要显式设置true
      JCollectionAuth.setAuth(context, true);
      
    }
}

        
此代码块在浮窗中显示

测试确认

  • 确认所需的权限都已经添加。如果必须的权限未添加,日志会提示错误。
  • 确认 AppKey(在 Portal 上生成的)已经正确的写入 Androidmanifest.xml 。
  • 确认在程序启动时候调用了 init(context)接口
  • 确认测试手机(或者模拟器)已成功连入网络 + 客户端调用 init 后不久,如果一切正常,应有登录成功的日志信息
  • 启动应用程序,在 Portal 上向应用程序发送自定义消息或者通知栏提示。详情请参考 创建推送。
  • 在几秒内,客户端应可收到下发的通知或者正定义消息,如果 SDK 工作正常,则日志信息会如下:
[JPushInterface] action:init ....... [ConnectingHelper] Login succeed
          [JPushInterface] action:init
.......
[ConnectingHelper] Login succeed

        
此代码块在浮窗中显示

如图所示,客户端启动分为 4 步:

  • 检查 metadata 的 appKey 和 channel,如果不存在,则启动失败
  • 初始化 JPush SDK,检查 JNI 等库文件的有效性,如果库文件无效,则启动失败
  • 检查 Androidmanifest.xml,如果有 Required 的权限不存在,则启动失败
  • 连接服务器登录,如果存在网络问题,则登陆失败,或者前面三步有问题,不会启动 JPush SDK

进阶功能

获取 Registration ID 交互建议

由于极光推送所有形式的推送最后都会转化为对 Registration ID 推送,因此排查客户问题的时候需要提供 Registration ID。为了方便线上客户准确提供信息,减少沟通成本,我们建议您完成 SDK 集成后,在 App 的【关于】、【意见反馈】、【我的】等比较不常用的 UI 中展示客户的 Registration ID 。

示例代码:

JPushInterface.getRegistrationID(getContext());
          JPushInterface.getRegistrationID(getContext());

        
此代码块在浮窗中显示

效果如图:

其他功能

请参考:

API:Android

其他集成方式

组装服务集成方式

组包服务是对手动集成 SDK 的封装服务,通过将 SDK 组合到单独的 jiguang module,将手动集成的共同配置业务隐藏,开发者只需关注自己本身的个性化配置,减少集成步骤,提高开发者接入效率。

如您需要使用 JPush 组包服务,请在组包服务界面勾选 JPush 服务,并 组装 SDK。 jpush_android_3m

jiguang_sdk.zip 集成压缩包内容说明

  • jiguang
    • JIGUANG SDK 组合包
    • JPush aar 包已在该 module 的 libs/ 中依赖,SDK 组件与资源随 aar 自动合并,无需再手动拷贝依赖
  • jiguang-demo
    • JIGUANG SDK 组合包集成 demo,是一个完整的 Android 项目,通过这个演示了组包服务的基本用法,可以用来做参考
    • 根据您勾选的服务自动组合构建,组包前预设的相关配置会同时预埋到 demo 中

导入 JIGUANG SDK

通过 AS 将 SDK 作为 module 导入项目。

导入步骤:AndroidStudio -> File -> New -> Import Module -> 选择 jiguang 导入

配置 JIGUANG SDK

settings.gradle 配置添加:

include ':jiguang'
          include ':jiguang'

        
此代码块在浮窗中显示

在应用 gradle 中添加 SDK 依赖:

android { ...... defaultConfig { applicationId "com.xxx.xxx" //JPush 上注册的包名. ...... manifestPlaceholders = [ JPUSH_PKGNAME : applicationId, JPUSH_APPKEY : "你的 Appkey ", //JPush 上注册的包名对应的 Appkey. JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可. ] ...... } ...... } dependencies { ...... implementation project(':jiguang') ...... }
          android {
    ......
    defaultConfig {
        applicationId "com.xxx.xxx" //JPush 上注册的包名.
        ......
        manifestPlaceholders = [
            JPUSH_PKGNAME : applicationId,
            JPUSH_APPKEY : "你的 Appkey ", //JPush 上注册的包名对应的 Appkey.
            JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
        ]
        ......
    }
    ......
}

dependencies {
    ......
    implementation project(':jiguang')
    ......
}

        
此代码块在浮窗中显示

在应用 AndroidManifest 中配置(SDK 自身组件已随 aar 合并,只需以下两项):

<!-- Since JCore2.0.0 Required SDK 核心功能 --> <!-- 可配置 android:process 参数将 Service 放在其他进程中;android:enabled 属性不能是 false --> <!-- 这个是自定义 Service,要继承极光 JCommonService,可以在更多手机平台上使得推送通道保持的更稳定 --> <service android:name="xx.xx.XService" android:enabled="true" android:exported="false" android:process=":pushcore"> <intent-filter> <action android:name="cn.jiguang.user.service.action" /> </intent-filter> </service> <!-- Required since 3.0.7 --> <!-- 新的 tag/alias 接口结果返回需要开发者配置一个自定的广播 --> <!-- 3.3.0 开始所有事件将通过该类回调 --> <!-- 该广播需要继承 JPush 提供的 JPushMessageReceiver 类,并如下新增一个 Intent-Filter --> <receiver android:name="自定义 Receiver" android:enabled="true" android:exported="false"> <intent-filter> <action android:name="cn.jpush.android.intent.RECEIVER_MESSAGE" /> <category android:name="您应用的包名" /> </intent-filter> </receiver>
          <!-- Since JCore2.0.0 Required SDK 核心功能 -->
<!-- 可配置 android:process 参数将 Service 放在其他进程中;android:enabled 属性不能是 false -->
<!-- 这个是自定义 Service,要继承极光 JCommonService,可以在更多手机平台上使得推送通道保持的更稳定 -->
<service
    android:name="xx.xx.XService"
    android:enabled="true"
    android:exported="false"
    android:process=":pushcore">
    <intent-filter>
        <action android:name="cn.jiguang.user.service.action" />
    </intent-filter>
</service>

<!-- Required since 3.0.7 -->
<!-- 新的 tag/alias 接口结果返回需要开发者配置一个自定的广播 -->
<!-- 3.3.0 开始所有事件将通过该类回调 -->
<!-- 该广播需要继承 JPush 提供的 JPushMessageReceiver 类,并如下新增一个 Intent-Filter -->
<receiver
    android:name="自定义 Receiver"
    android:enabled="true"
    android:exported="false">
    <intent-filter>
        <action android:name="cn.jpush.android.intent.RECEIVER_MESSAGE" />
        <category android:name="您应用的包名" />
    </intent-filter>
</receiver>

        
此代码块在浮窗中显示

手动集成方式

以下集成包说明与 AndroidManifest 示例适用于 JPush Android SDK v6.3.0 及以上版本(离线包为 aar)。集成更早版本时,请使用对应版本集成包中的配置;JPush Android SDK v6.0.3 及以上版本的最低系统版本为 Android 5.0(API 21),应用的 minSdkVersion 须不低于 21。

手动集成压缩包下载链接:前往下载

6.3.0 起,离线集成包内的 SDK 文件为 aar,与 Maven Central 发布的是同一份文件。aar 内已包含 SDK 所需的 AndroidManifest 组件、res 资源与混淆规则,接入方只需引入 aar 并配置 AppKey。

jpush-android-6.x.x-release.zip 集成压缩包内容

  • AndroidManifest.xml
    • 客户端嵌入 SDK 参考的配置文件,只包含权限、AppKey / Channel 配置与需开发者自定义的组件;SDK 自身组件已随 aar 合并,无需再声明。
  • libs/jpush-android-6.x.x.aar
    • JPush SDK 开发包,含混淆后的 class、SDK 组件的 AndroidManifest 声明、res 资源与 consumer 混淆规则。
  • res/
    • 与 aar 内资源相同的一份副本,仅供需要定制通知样式(如 jpush_notification_icon)或富媒体页面时参考;不定制时无需复制。
  • example/
    • 完整的 Android 示例项目,演示 JPush SDK 的基本用法,example/demo/libs/ 内同样以 aar 方式引入。
  • README.txt、ChangeLog.txt

JCore 核心包不在本压缩包内,请另行下载 JCore 压缩包(jcore-android-x.x.x-release.zip,内含 jcore-android-x.x.x.aar),JPush 6.3.0 要求 JCore 5.6.0 及以上。

SDK 文件移植

  1. 解压缩 jpush-android-6.x.x-release.zip。
  2. 复制 libs/jpush-android-6.x.x.aar 到工程 libs/ 目录下。
  3. 复制 JCore 压缩包中的 jcore-android-x.x.x.aar 到工程 libs/ 目录下。
  4. 在应用 module 的 build.gradle 中引入 libs 下的 aar:
dependencies { ...... implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs') ...... }
          dependencies {
    ......
    implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
    ......
}

        
此代码块在浮窗中显示

说明 1:aar 内已包含 SDK 的 res 资源,不需要再复制 res/ 到工程。若要自定义通知栏图标,在工程 res/drawable-xxxx/ 下放置同名的 jpush_notification_icon,即可覆盖 aar 内的默认资源;文件名不要变,建议使用没有阴影和渐变色的 icon。

说明 2:JCore 的 so 库已打包在 jcore-android-x.x.x.aar 内,不需要手动复制 so,也不需要配置 jniLibs.srcDirs。

说明 3:aar 内附带 consumer 混淆规则,AGP 会自动应用;如项目对混淆有额外限制,可参考本页"集成 JPush Android SDK 的混淆"章节。

配置 AndroidManifest.xml

根据 SDK 压缩包里的 AndroidManifest.xml 样例文件,来配置应用程序项目的 AndroidManifest.xml。

主要步骤为:

  • 复制备注为 "Required" 的权限部分
  • 配置 JPUSH_APPKEY 与 JPUSH_CHANNEL 两个 meta-data,AppKey 为在 Portal 上创建该应用后应用信息中的 Appkey,例如:9fed5bcb7b9b87413678c407
  • 声明一个继承自 cn.jpush.android.service.JPushMessageReceiver 的自定义 Receiver,用于接收 tag / alias 结果与各类推送事件回调
  • 声明一个继承自 cn.jpush.android.service.JCommonService 的自定义 Service,放在 :pushcore 进程,用于在更多手机平台上保持推送通道稳定

以下 SDK 组件已随 aar 内的 AndroidManifest.xml 自动合并,不需要在应用的 AndroidManifest.xml 中声明:PushService、DataProvider、PushReceiver、PushActivity、PopWinActivity、AlarmReceiver、SchedulerReceiver、JNotifyActivity、JLocalNotifyActivity、JLocalNotifyReceiver、JTransitActivity、AsusPushMessageReceiver、InitProvider。

如需定制这些组件(例如把 PushService 放到其它进程),在应用的 AndroidManifest.xml 中声明同名组件并使用 tools:replace / tools:node 覆盖,例如:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <application> <service android:name="cn.jpush.android.service.PushService" android:process=":mypush" tools:replace="android:process" /> </application> </manifest>
          <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <application>
        <service
            android:name="cn.jpush.android.service.PushService"
            android:process=":mypush"
            tools:replace="android:process" />
    </application>
</manifest>

        
此代码块在浮窗中显示

说明:如果使用 Android Studio,可在 AndroidManifest 中引用 applicationId 的值,在 build.gradle 的 defaultConfig 节点下配置:

defaultConfig { applicationId "cn.jpush.example" //您应用的包名 ...... manifestPlaceholders = [ JPUSH_APPKEY : "您应用的 Appkey", JPUSH_CHANNEL : "developer-default", ] }
          defaultConfig {
    applicationId "cn.jpush.example" //您应用的包名
    ......
    manifestPlaceholders = [
        JPUSH_APPKEY : "您应用的 Appkey",
        JPUSH_CHANNEL : "developer-default",
    ]
}

        
此代码块在浮窗中显示

在 AndroidManifest 中使用 ${applicationId} 引用 gradle 中定义的包名。

AndroidManifest 示例

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="您应用的包名"> <!-- Required --> <permission android:name="${applicationId}.permission.JPUSH_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="${applicationId}.permission.JPUSH_MESSAGE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- 适配 Android 13,弹出通知必须权限 --> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> <!-- Optional. 为了提高 sdk 识别唯一用户的能力,保证消息推送的精准送达,建议集成以下权限 --> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" /> <uses-permission android:name="android.permission.GET_TASKS" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- Optional. 如您需要接入地理围栏业务,建议集成以下权限 --> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> <!-- Optional. 如您需要对应设备通知相关的能力,建议集成以下权限 --> <uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE" /><!-- 华为角标 --> <uses-permission android:name="com.vivo.notification.permission.BADGE_ICON" /><!-- vivo 角标 --> <uses-permission android:name="com.hihonor.android.launcher.permission.CHANGE_BADGE" /><!-- honor 角标 --> <uses-permission android:name="com.oplus.notification.permission.BADGE_DIGITAL" /><!-- OPPO ColorOS 16+ 桌面数字角标,since 6.3.0 --> <uses-permission android:name="android.permission.VIBRATE" /><!-- 振动器权限,JPUSH 支持通知开启振动功能,小米推送必须 --> <!-- 扩展备用权限(可选) --> <permission android:name="${applicationId}.permission.JOPERATE_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="${applicationId}.permission.JOPERATE_MESSAGE" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:name="Your Application Name"> <!-- Since JCore2.0.0 Required SDK 核心功能 --> <!-- 可配置 android:process 参数将 Service 放在其他进程中;android:enabled 属性不能是 false --> <!-- 这个是自定义 Service,要继承极光 JCommonService,可以在更多手机平台上使得推送通道保持的更稳定 --> <service android:name="xx.xx.XService" android:enabled="true" android:exported="false" android:process=":pushcore"> <intent-filter> <action android:name="cn.jiguang.user.service.action" /> </intent-filter> </service> <!-- Required since 3.0.7 --> <!-- 新的 tag/alias 接口结果返回需要开发者配置一个自定义的广播 --> <!-- 3.3.0 开始所有事件将通过该类回调 --> <!-- 该广播需要继承 JPush 提供的 JPushMessageReceiver 类,并如下新增一个 Intent-Filter --> <receiver android:name="自定义 Receiver" android:enabled="true" android:exported="false"> <intent-filter> <action android:name="cn.jpush.android.intent.RECEIVER_MESSAGE" /> <category android:name="${applicationId}" /> </intent-filter> </receiver> <!-- ================================================================== 以下 JPush SDK 核心组件已随 jpush-android aar 内的 AndroidManifest.xml 自动合并, 接入方无需再声明:PushService、DataProvider、PushReceiver、PushActivity、PopWinActivity、 AlarmReceiver、SchedulerReceiver、JNotifyActivity、JLocalNotifyActivity、JLocalNotifyReceiver、 JTransitActivity、AsusPushMessageReceiver、InitProvider。 如需把 PushService 放到其它进程等定制,请用 tools:replace / tools:node 覆盖。 ================================================================== --> <!-- Required. AppKey copied from Portal --> <meta-data android:name="JPUSH_APPKEY" android:value="${JPUSH_APPKEY}" /> <!-- Required. 渠道,暂时填写默认值即可 --> <meta-data android:name="JPUSH_CHANNEL" android:value="${JPUSH_CHANNEL}" /> </application> </manifest>
          <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="您应用的包名">

    <!-- Required -->
    <permission
        android:name="${applicationId}.permission.JPUSH_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="${applicationId}.permission.JPUSH_MESSAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!-- 适配 Android 13,弹出通知必须权限 -->
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

    <!-- Optional. 为了提高 sdk 识别唯一用户的能力,保证消息推送的精准送达,建议集成以下权限 -->
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
    <uses-permission android:name="android.permission.GET_TASKS" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    <!-- Optional. 如您需要接入地理围栏业务,建议集成以下权限 -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

    <!-- Optional. 如您需要对应设备通知相关的能力,建议集成以下权限 -->
    <uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE" /><!-- 华为角标 -->
    <uses-permission android:name="com.vivo.notification.permission.BADGE_ICON" /><!-- vivo 角标 -->
    <uses-permission android:name="com.hihonor.android.launcher.permission.CHANGE_BADGE" /><!-- honor 角标 -->
    <uses-permission android:name="com.oplus.notification.permission.BADGE_DIGITAL" /><!-- OPPO ColorOS 16+ 桌面数字角标,since 6.3.0 -->
    <uses-permission android:name="android.permission.VIBRATE" /><!-- 振动器权限,JPUSH 支持通知开启振动功能,小米推送必须 -->

    <!-- 扩展备用权限(可选) -->
    <permission android:name="${applicationId}.permission.JOPERATE_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="${applicationId}.permission.JOPERATE_MESSAGE" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:name="Your Application Name">

        <!-- Since JCore2.0.0 Required SDK 核心功能 -->
        <!-- 可配置 android:process 参数将 Service 放在其他进程中;android:enabled 属性不能是 false -->
        <!-- 这个是自定义 Service,要继承极光 JCommonService,可以在更多手机平台上使得推送通道保持的更稳定 -->
        <service
            android:name="xx.xx.XService"
            android:enabled="true"
            android:exported="false"
            android:process=":pushcore">
            <intent-filter>
                <action android:name="cn.jiguang.user.service.action" />
            </intent-filter>
        </service>

        <!-- Required since 3.0.7 -->
        <!-- 新的 tag/alias 接口结果返回需要开发者配置一个自定义的广播 -->
        <!-- 3.3.0 开始所有事件将通过该类回调 -->
        <!-- 该广播需要继承 JPush 提供的 JPushMessageReceiver 类,并如下新增一个 Intent-Filter -->
        <receiver
            android:name="自定义 Receiver"
            android:enabled="true"
            android:exported="false">
            <intent-filter>
                <action android:name="cn.jpush.android.intent.RECEIVER_MESSAGE" />
                <category android:name="${applicationId}" />
            </intent-filter>
        </receiver>

        <!-- ==================================================================
             以下 JPush SDK 核心组件已随 jpush-android aar 内的 AndroidManifest.xml 自动合并,
             接入方无需再声明:PushService、DataProvider、PushReceiver、PushActivity、PopWinActivity、
             AlarmReceiver、SchedulerReceiver、JNotifyActivity、JLocalNotifyActivity、JLocalNotifyReceiver、
             JTransitActivity、AsusPushMessageReceiver、InitProvider。
             如需把 PushService 放到其它进程等定制,请用 tools:replace / tools:node 覆盖。
             ================================================================== -->

        <!-- Required. AppKey copied from Portal -->
        <meta-data android:name="JPUSH_APPKEY" android:value="${JPUSH_APPKEY}" />
        <!-- Required. 渠道,暂时填写默认值即可 -->
        <meta-data android:name="JPUSH_CHANNEL" android:value="${JPUSH_CHANNEL}" />
    </application>
</manifest>

        
此代码块在浮窗中显示

技术支持

当出现问题时:

  • 请仔细阅读 Android FAQ 文档,查看是否有遗漏。
  • 你可以到极光社区搜索类似问题
  • 给我们的 support 发邮件 support@jiguang.cn

为了更快速的解决问题,在寻求帮助时,请提供下列信息:

  • 你需要咨询的产品是 JPush,是否同时使用了极光其他的产品
  • 你所调用的是什么 API,所传参数,完整的报错信息,出现异常的时间点
  • 如果收不到消息,提供应用的 Appkey,消息的 Message ID,设备的 registration ID 信息
  • 如果是 SDK 问题请提供对应的 SDK 版本和完整的日志记录,日志信息请使用 TXT 文件上传
  • 出现异常的设备是 Android ,列出具体的机型和系统
文档内容是否对您有帮助?

Copyright 2011-2026, jiguang.cn, All Rights Reserved. 粤ICP备12056275号-13 深圳市和讯华谷信息技术有限公司

在文档中心打开