Bugly目前采用微信Tinker的開源方案
已經(jīng)集成異常上報功能
使用指南:
- 在項(xiàng)目根目錄下的build.gradle文件中添加插件依賴:
buildscript {
repositories {
jcenter()
}
dependencies {
// tinkersupport插件, 其中l(wèi)astest.release指拉取最新版本报辱,也可以指定明確版本號聚请,例如1.0.4
classpath "com.tencent.bugly:tinker-support:latest.release"
}
}
- 在app目錄下的build.gradle文件中添加依賴和屬性配置:
dependencies {
// 注釋掉原有bugly的倉庫
// compile 'com.tencent.bugly:crashreport:latest.release'
// 其中l(wèi)atest.release指代最新版本號括授,也可以指定明確的版本號议惰,例如1.2.0
compile 'com.tencent.bugly:crashreport_upgrade:latest.release'
compile "com.android.support:multidex:1.0.1" // 多dex配置
}
// 依賴插件腳本
apply from: 'tinker-support.gradle'
- 在app目錄下創(chuàng)建tinker-support.gradle文件并添加如下配置:
apply plugin: 'com.tencent.bugly.tinker-support'
def bakPath = file("${buildDir}/bakApk/")
// 此處填寫每次構(gòu)建生成的基準(zhǔn)包目錄
def baseApkDir = "app-0504-16-23-46"
// 對于插件各參數(shù)的詳細(xì)解析請參考
tinkerSupport {
// 開啟tinker-support插件,默認(rèn)值true
enable = true
// 自動生成tinkerId, 你無須關(guān)注tinkerId,默認(rèn)為false
autoGenerateTinkerId = true
// 指定歸檔目錄拗踢,默認(rèn)值當(dāng)前module的子目錄tinker
autoBackupApkDir = "${bakPath}"
// 是否啟用覆蓋tinkerPatch配置功能,默認(rèn)值false
// 開啟后tinkerPatch配置不生效向臀,即無需添加tinkerPatch
overrideTinkerPatchConfiguration = true
// 編譯補(bǔ)丁包時巢墅,必需指定基線版本的apk,默認(rèn)值為空
// 如果為空券膀,則表示不是進(jìn)行補(bǔ)丁包的編譯
// @{link tinkerPatch.oldApk }
baseApk = "${bakPath}/${baseApkDir}/app-release.apk"
// 對應(yīng)tinker插件applyMapping
baseApkProguardMapping = "${bakPath}/${baseApkDir}/app-release-mapping.txt"
// 對應(yīng)tinker插件applyResourceMapping
baseApkResourceMapping = "${bakPath}/${baseApkDir}/app-release-R.txt"
// 構(gòu)建基準(zhǔn)包跟補(bǔ)丁包都要修改tinkerId君纫,主要用于區(qū)分
// tinkerId = "1.0.3-patch"
// 打多渠道補(bǔ)丁時指定目錄
// buildAllFlavorsDir = "${bakPath}/${baseApkDir}"
// 是否使用加固模式,默認(rèn)為false
// isProtectedApp = true
// 是否采用反射Application的方式集成芹彬,無須改造Application
enableProxyApplication = true
}
/**
* 一般來說,我們無需對下面的參數(shù)做任何的修改
* 對于各參數(shù)的詳細(xì)介紹請參考:
* https://github.com/Tencent/tinker/wiki/Tinker-%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97
*/
tinkerPatch {
tinkerEnable = true
ignoreWarning = false
useSign = true
dex {
dexMode = "jar"
pattern = ["classes*.dex"]
loader = []
}
lib {
pattern = ["lib/*/*.so"]
}
res {
pattern = ["res/*", "r/*", "assets/*", "resources.arsc", "AndroidManifest.xml"]
ignoreChange = []
largeModSize = 100
}
packageConfig {
}
sevenZip {
zipArtifact = "com.tencent.mm:SevenZip:1.1.10"
// path = "/usr/local/bin/7za"
}
buildConfig {
keepDexApply = false
// tinkerId = "base-2.0.1"
}
}
- 初始化SDK(enableProxyApplication = true 的情況)
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// 這里實(shí)現(xiàn)SDK初始化蓄髓,appId替換成你的在Bugly平臺申請的appId,調(diào)試時舒帮,將第三個參數(shù)改為true
Bugly.init(this, "注冊時申請的APPID", true);
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
// you must install multiDex whatever tinker is installed!
MultiDex.install(base);
// 安裝tinker
Beta.installTinker();
}
}
- 在AndroidManifest.xml中添加權(quán)限:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<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_LOGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
- 在app目錄下創(chuàng)建keystore文件夾会喝,添加release.keystore及debug.keystore:
- 在app目錄下的build.gradle文件中添加簽名配置:
android {
// 簽名配置
signingConfigs {
release {
try {
storeFile file("./keystore/release.keystore")
storePassword "testres"
keyAlias "testres"
keyPassword "testres"
} catch (ex) {
throw new InvalidUserDataException(ex.toString())
}
}
debug {
storeFile file("./keystore/debug.keystore")
}
}
buildTypes {
release {
minifyEnabled true
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
minifyEnabled false
signingConfig signingConfigs.debug
}
}
}