极光推送傻瓜版配置(Android Studio)

版权声明:歡迎转載 https://blog.csdn.net/jinjianghai/article/details/80336099

Step1 : 

    build.gradle(Project : 项目名)中加入以下红色部分配置(新 Android Studio 中默认就有)

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Step2 : 打开极光推送官网(  https://www.jiguang.cn/  )创建一个新的 APP,


应用名称随便写



获取 APP_key


获取应用包名:


输入你的 Android Studio 项目的包名 (build.gradle(Module : app)中的 applicationId)



Step3 : 打开 build.gradle (Module : app) 在 defaultConfig 加入如下配置 :

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

JPUSH_APPKEY : "这里写在极光官网的那个 APP-Key", //JPush上注册的包名对应的appkey.

JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.]
Step4 : 打开 build.gradle (Module : app),加入红色配置
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile 'cn.jiguang.sdk:jpush:3.1.1'  // 此处以JPush 3.1.1 版本为例。
    compile 'cn.jiguang.sdk:jcore:1.1.9'  // 此处以JCore 1.1.9 版本为例。
}
 
 
Step5 : 创建一个Java 类:
public class ExampleApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        JPushInterface.setDebugMode(true);     // 设置开启日志,发布时请关闭日志
        JPushInterface.init(this);            // 初始化 JPush
    }
}
Step6 : 把这个类加入到 AndroidManifest.xml
Step7 : 把 JPush 用到一个 Service 注入进来

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:name="msgtest.cybersmart.com.msg2.ExampleApplication"
    >
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>

            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

    <service android:name="cn.jpush.android.service.PushService"
             android:process=":multiprocess"
             tools:node="replace" >
    </service>
</application>



猜你喜欢

转载自blog.csdn.net/jinjianghai/article/details/80336099