1.依赖
根Build.gradle
添加:maven { url ‘https://repo1.maven.org/maven2/’ }
全部代码,包含阿里云
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url 'https://repo1.maven.org/maven2/' }
maven{ url 'https://maven.aliyun.com/repository/central'}
maven{ url 'https://maven.aliyun.com/repository/public'}
maven{ url 'https://maven.aliyun.com/repository/public'}
maven{ url 'https://maven.aliyun.com/repository/google'}
maven{ url 'https://maven.aliyun.com/repository/gradle-plugin'}
maven{ url 'https://maven.aliyun.com/repository/spring'}
maven{ url 'https://maven.aliyun.com/repository/spring-plugin'}
maven{ url 'https://maven.aliyun.com/repository/grails-core'}
maven{ url 'https://maven.aliyun.com/repository/apache-snapshots'}
maven { url "https://dl.bintray.com/thelasterstar/maven/" }
maven { url 'https://dl.bintray.com/umsdk/release' }
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.3"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url 'https://repo1.maven.org/maven2/' }
maven{ url 'https://maven.aliyun.com/repository/central'}
maven{ url 'https://maven.aliyun.com/repository/public'}
maven{ url 'https://maven.aliyun.com/repository/public'}
maven{ url 'https://maven.aliyun.com/repository/google'}
maven{ url 'https://maven.aliyun.com/repository/gradle-plugin'}
maven{ url 'https://maven.aliyun.com/repository/spring'}
maven{ url 'https://maven.aliyun.com/repository/spring-plugin'}
maven{ url 'https://maven.aliyun.com/repository/grails-core'}
maven{ url 'https://maven.aliyun.com/repository/apache-snapshots'}
maven { url "https://dl.bintray.com/thelasterstar/maven/" }
maven { url 'https://dl.bintray.com/umsdk/release' }
google()
jcenter()
maven { url "http://lib.gcssloop.com:8081/repository/gcssloop-central/" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
// 友盟统计SDK
implementation 'com.umeng.umsdk:common:9.4.0'// 必选
implementation 'com.umeng.umsdk:asms:1.2.3'// 必选
implementation 'com.umeng.umsdk:apm:1.3.1' // 错误分析升级为独立SDK,看crash数据请一定集成,可选
implementation 'com.umeng.umsdk:abtest:1.0.0'//使用U-App中ABTest能力,可选
2.在application添加key
其中key是自己申请的key(例子:5433fert35t532)
冷启动
//友盟统计
// 初始化SDK appkey在官方注册应用即可获取
//按规定,这里用冷启动,既要同意了,执行Init才开始统计,不然不统计
//参数介绍:第一个是上下文,第二个是友盟可以,第三个是打包渠道,这里可以多渠道打包,没有的话
UMConfigure.preInit(this,BuildConfig.umeng_app_Key,BuildConfig.URL);
用户点击同意后,执行真正的 统计
UMConfigure.init(HdztwelcomeActivity.this, BuildConfig.umeng_app_Key, BuildConfig.URL, UMConfigure.DEVICE_TYPE_PHONE, null);
3.再baseActivity里的onResume,onPause写东西
@Override
protected void onResume() {
super.onResume();
MobclickAgent.onResume(this);
}
@Override
protected void onPause() {
super.onPause();
MobclickAgent.onPause(this);
}