1.在項目的根目錄中build.gradle 中的
dependencies 中添加
classpath "com.tinkerpatch.sdk:tinkerpatch-gradle-plugin:1.2.14.6"
2.在app/build.gradle 中增加依賴
provided("com.tinkerpatch.tinker:tinker-android-anno:1.9.14.6") compile("com.tinkerpatch.sdk:tinkerpatch-android-sdk:1.2.14.6")
3.下載官網中 tinkerpatch.gradle 文件,並且放到app 目錄下,並且在app/build.gradle 中添加
apply from: 'tinkerpatch.gradle'
注意: 需要 在
android{ //其他文件省略
defaultConfig{ //需要添加一下這句話,否則生成補丁失敗
javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
}
}
4.初始化sdk
1.tinkerpatch.build 中reflectApplication = true
//不需要繼承
2.1.tinkerpatch.build 中reflectApplication = false
//application 需要extends DefaultApplicationLike
在application 的oncrete 中添加
ApplicationLike tinkerApplicationLike = TinkerPatchApplicationLike.getTinkerPatchApplicationLike();
// 初始化TinkerPatch SDK, 更多配置可參照API章節中的,初始化SDK
TinkerPatch.init(tinkerApplicationLike)
.reflectPatchLibrary()
.setPatchRollbackOnScreenOff(true)
.setPatchRestartOnSrceenOff(true)
.setFetchPatchIntervalByHours(3);
// 每隔3個小時(通過setFetchPatchIntervalByHours設置)去訪問後臺時候有更新,通過handler實現輪訓的效果
TinkerPatch.with().fetchPatchUpdateAndPollWithInterval();
5. 有問題的包暫且稱爲基準包,修復完的暫且稱爲 修復 包
1.在tinkerpatch.gradle 中配置基準包的位置,然後設置基準包路徑,
2.修復完bug的包 用terminal 執行gradle 命令 gradlew tinkerPatchRelease ,執行完成之後會根據 基準包和 修復過的內容生成一個修復包,目錄在\app\build\outputs\apk\tinkerPatch\release 目錄下,然後裏邊生成了四個文件夾,根目錄下 patch_signed_7zip.apk 就是修復包,需要往tinker 上傳的(http://www.tinkerpatch.com/Apps/patch/id/27383)