推荐Gradle接入方式
1.仓库 Project:build.gradle
buildscript {
repositories {
google()
jcenter()
maven { url 'https://dl.bintray.com/umsdk/release' }
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://dl.bintray.com/umsdk/release' }
maven { url "https://dl.bintray.com/thelasterstar/maven/" }
}
}
2.依赖 Module:build.gradle
若已经集成了阿里系utdid,去掉友盟的
android {
defaultConfig {
multiDexEnabled true
// 友盟分享qq清单文件占位
manifestPlaceholders = [qqappid: "123456"]
}
}
dependencies {
/**
* 下面各SDK根据宿主App是否使用相关业务按需引入。
* OAID目前为目前国内市场主流的Android Q设备标识,可根据需要选择。
* 友盟统计SDK
*/
implementation 'com.umeng.umsdk:common:9.1.3'
// asms包依赖(必选)
implementation 'com.umeng.umsdk:asms:1.1.3'
// native crash包依赖(必选)
implementation 'com.umeng.umsdk:crash:0.0.4'
// (可选)
implementation 'com.umeng.umsdk:oaid_lenovo:1.0.0'
implementation 'com.umeng.umsdk:oaid_mi:1.0.0'
implementation 'com.umeng.umsdk:oaid_oppo:1.0.4'
implementation 'com.umeng.umsdk:oaid_vivo:1.0.0.1'
//友盟push相关依赖(必须)
implementation 'com.umeng.umsdk:push:6.1.0'
implementation 'com.umeng.umsdk:huawei-basetb:2.6.3.306'
implementation 'com.umeng.umsdk:huawei-pushtb:2.6.3.306'
implementation 'com.umeng.umsdk:huawei-umengaccs:1.2.4'
implementation 'com.umeng.umsdk:meizu-push:3.8.7'
implementation 'com.umeng.umsdk:meizu-umengaccs:1.1.1'
implementation 'com.umeng.umsdk:oppo-push:2.0.2'
implementation 'com.umeng.umsdk:oppo-umengaccs:1.0.6'
implementation 'com.umeng.umsdk:vivo-push:2.3.5'
implementation 'com.umeng.umsdk:vivo-umengaccs:1.1.0'
implementation 'com.umeng.umsdk:xiaomi-push:3.7.0'
implementation 'com.umeng.umsdk:xiaomi-umengaccs:1.1.4'
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.8.8-open-fix2'
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'
// 分享(短信、邮件、pocket使用jar)
implementation 'com.umeng.umsdk:share-core:7.0.2'
implementation 'com.umeng.umsdk:share-board:7.0.2'
implementation 'com.umeng.umsdk:share-qq:7.0.2'
implementation 'com.umeng.umsdk:share-wx:7.0.2'
implementation 'com.umeng.umsdk:share-sina:7.0.2'
implementation 'com.sina.weibo.sdk:core:4.4.3:openDefaultRelease@aar'
}
3.清单文件 AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MyApp"
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:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning"
tools:replace="android:allowBackup">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- 友盟 start -->
<!-- 分享、推送 -->
<!-- 新浪 -->
<activity
android:name="com.umeng.socialize.media.WBShareCallBackActivity"
android:configChanges="keyboardHidden|orientation"
android:exported="false"
android:maxAspectRatio="2.4"
android:minAspectRatio="1.0"
android:resizeableActivity="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<!-- 微信 -->
<activity
android:name=".wxapi.WXEntryActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:maxAspectRatio="2.4"
android:minAspectRatio="1.0"
android:resizeableActivity="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name="com.umeng.socialize.editorpage.ShareActivity"
android:excludeFromRecents="true"
android:maxAspectRatio="2.4"
android:minAspectRatio="1.0"
android:resizeableActivity="true"
android:theme="@style/Theme.UMDefault" />
<!-- QQ -->
<activity
android:name="com.tencent.tauth.AuthActivity"
android:launchMode="singleTask"
android:maxAspectRatio="2.4"
android:minAspectRatio="1.0"
android:noHistory="true"
android:resizeableActivity="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tencent123456" />
</intent-filter>
</activity>
<activity
android:name="com.tencent.connect.common.AssistActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:maxAspectRatio="2.4"
android:minAspectRatio="1.0"
android:resizeableActivity="true"
android:screenOrientation="behind"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
tools:replace="android:configChanges" />
<!-- 钉钉 -->
<activity
android:name=".ddshare.DDShareActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:maxAspectRatio="2.4"
android:minAspectRatio="1.0"
android:resizeableActivity="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<!-- 友盟推送 -->
<meta-data
android:name="UMENG_MESSAGE_SECRET"
android:value="xxx"></meta-data>
<activity
android:name=".UmengPushActivity"
android:maxAspectRatio="2.4"
android:minAspectRatio="1.0"
android:resizeableActivity="true"></activity>
<!-- 友盟厂商推送通道消息接收 -->
<activity
android:name=".UmengChannelNotifyClickActivity"
android:exported="true"
android:launchMode="singleTask"
android:maxAspectRatio="2.4"
android:minAspectRatio="1.0"
android:resizeableActivity="true" />
<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:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE">
<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:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE" />
<provider
android:name="com.umeng.message.provider.MessageProvider"
android:authorities="${applicationId}.umeng.message"
android:exported="false">
<grant-uri-permission android:pathPattern=".*" />
</provider>
<!--魅族push应用定义消息receiver声明 -->
<receiver android:name=".MeizuPushRecevier">
<intent-filter>
<!-- 接收push消息 -->
<action android:name="com.meizu.flyme.push.intent.MESSAGE" />
<!-- 接收register消息 -->
<action android:name="com.meizu.flyme.push.intent.REGISTER.FEEDBACK" />
<!-- 接收unregister消息-->
<action android:name="com.meizu.flyme.push.intent.UNREGISTER.FEEDBACK" />
<!-- 兼容低版本Flyme3推送服务配置 -->
<action android:name="com.meizu.c2dm.intent.REGISTRATION" />
<action android:name="com.meizu.c2dm.intent.RECEIVE" />
<category android:name="com.ruanmei.ithome"></category>
</intent-filter>
</receiver>
<!--vivo push参数声明 -->
<!-- vivo start-->
<meta-data
android:name="com.vivo.push.api_key"
android:value="xxx" />
<meta-data
android:name="com.vivo.push.app_id"
android:value="xxx" />
<!-- VIVO end-->
<!-- 友盟 end -->
</application>
4.混淆 Proguard Rules for app
#友盟分享
-dontusemixedcaseclassnames
-dontshrink
-dontoptimize
-dontwarn com.google.android.maps.**
-dontwarn android.webkit.WebView
-dontwarn com.umeng.**
-dontwarn com.tencent.weibo.sdk.**
-dontwarn com.facebook.**
-keep public class javax.**
-keep public class android.webkit.**
-dontwarn android.support.v4.**
-keep enum com.facebook.**
-keepattributes Exceptions,InnerClasses,Signature
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep public interface com.facebook.**
-keep public interface com.tencent.**
-keep public interface com.umeng.socialize.**
-keep public interface com.umeng.socialize.sensor.**
-keep public interface com.umeng.scrshot.**
-keep class com.android.dingtalk.share.ddsharemodule.** { *; }
-keep public class com.umeng.socialize.* {*;}
-keep class com.facebook.**
-keep class com.facebook.** { *; }
-keep class com.umeng.scrshot.**
-keep public class com.tencent.** {*;}
-keep class com.umeng.socialize.sensor.**
-keep class com.umeng.socialize.handler.**
-keep class com.umeng.socialize.handler.*
-keep class com.umeng.weixin.handler.**
-keep class com.umeng.weixin.handler.*
-keep class com.umeng.qq.handler.**
-keep class com.umeng.qq.handler.*
-keep class UMMoreHandler{*;}
-keep class com.tencent.mm.sdk.modelmsg.WXMediaMessage {*;}
-keep class com.tencent.mm.sdk.modelmsg.** implements com.tencent.mm.sdk.modelmsg.WXMediaMessage$IMediaObject {*;}
-keep class im.yixin.sdk.api.YXMessage {*;}
-keep class im.yixin.sdk.api.** implements im.yixin.sdk.api.YXMessage$YXMessageData{*;}
-keep class com.tencent.mm.sdk.** {
*;
}
-keep class com.tencent.mm.opensdk.** {
*;
}
-dontwarn twitter4j.**
-keep class twitter4j.** { *; }
-keep class com.tencent.** {*;}
-dontwarn com.tencent.**
-keep public class com.umeng.com.umeng.soexample.R$*{
public static final int *;
}
-keep public class com.linkedin.android.mobilesdk.R$*{
public static final int *;
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class com.tencent.open.TDialog$*
-keep class com.tencent.open.TDialog$* {*;}
-keep class com.tencent.open.PKDialog
-keep class com.tencent.open.PKDialog {*;}
-keep class com.tencent.open.PKDialog$*
-keep class com.tencent.open.PKDialog$* {*;}
-keep class com.sina.** {*;}
-dontwarn com.sina.**
-keep class com.alipay.share.sdk.** {
*;
}
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
-keep class com.linkedin.** { *; }
-keepattributes Signature
#友盟推送
-dontwarn com.taobao.**
-dontwarn anet.channel.**
-dontwarn anetwork.channel.**
-dontwarn org.android.**
-dontwarn org.apache.thrift.**
-dontwarn com.xiaomi.**
-dontwarn com.huawei.**
-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 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 *;
}
5.初始化
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
}
}