16年记录了一篇,现在官方文档更新了;重新记录下
在工程build.gradle配置脚本中buildscript和allprojects段中添加【友盟+】SDK新maven仓库地址
maven { url 'https://dl.bintray.com/umsdk/release' }
添加后的结果
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven { url 'https://dl.bintray.com/umsdk/release' }//添加的依赖
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://dl.bintray.com/umsdk/release' }//添加的依赖
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
在工程App 对应build.gradle配置脚本dependencies段中添加统计SDK库和其它库依赖:
// 下面各SDK根据宿主App是否使用相关业务按需引入。
// OAID目前为目前国内市场主流的Android Q设备标识,可根据需要选择。
// 友盟统计SDK
implementation 'com.umeng.umsdk:common:9.1.0' // (必选)
implementation 'com.umeng.umsdk:game:9.1.0+G' // 游戏统计SDK依赖(可选)
implementation 'com.umeng.umsdk:asms:1.1.3' // asms包依赖(必选)
implementation 'com.umeng.umsdk:crash:0.0.4' // native crash包依赖(必选)
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' // (可选)
因自己使用环境只用到了统计,所以只加了如下三个依赖
implementation 'com.umeng.umsdk:common:9.1.0' // (必选)
implementation 'com.umeng.umsdk:asms:1.1.3' // asms包依赖(必选)
implementation 'com.umeng.umsdk:crash:0.0.4' // native crash包依赖(必选)
添加后的结果
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.test001"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.umeng.umsdk:common:9.1.0' // (必选)
implementation 'com.umeng.umsdk:asms:1.1.3' // asms包依赖(必选)
implementation 'com.umeng.umsdk:crash:0.0.4' // native crash包依赖(必选)
}
添加权限
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
添加后的结果
<?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="com.example.test001">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".App"
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"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
初始化(这里直接使用了AUTO页面采集模式)
package com.example.test001;
import android.app.Application;
import com.umeng.analytics.MobclickAgent;
import com.umeng.commonsdk.UMConfigure;
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
// 初始化SDK appkey在官方注册应用即可获取
UMConfigure.init(this, "5efbf5110cafb29d4b000013", "Umeng", UMConfigure.DEVICE_TYPE_PHONE, null);
// 选用AUTO页面采集模式,如果是在AUTO页面采集模式下,则需要注意,所有Activity中都不能调用MobclickAgent.onResume和onPause方法
MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO);
}
}
运行后,即可在我的产品中看到用户的分析
模拟一个bug查看到的异常统计