Tinker是腾讯出的一款热修复框架,关于热修复框架Tinker介绍本文就不描述太多了,网络已经很多了
本文主要介绍主要基础的集成使用,本文主要使用Gradle方式集成
Tinker的github地址,详细介绍可以看wiki
https://github.com/Tencent/tinker
demo的github地址:
https://github.com/ZhiLiangT/tinkerdemo
demo的CSDN链接:
https://download.csdn.net/download/tzl0322/10616326
1,新建项目,集成相关配置
1)在AS中新建项目TinkerDemo
我当前使用的是Tinker版本是1.9.8
所以在gradle.properties中这样配置
TINKER_VERSION=1.9.8
GRADLE_3=true
2)在app module下的build.gradle中直接进行配置,配置如下,直接粘过去就可以,部分内容需要修改
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
def javaVersion = JavaVersion.VERSION_1_7
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//tinker
implementation("com.tencent.tinker:tinker-android-lib:${TINKER_VERSION}") { changing = true }
annotationProcessor("com.tencent.tinker:tinker-android-anno:${TINKER_VERSION}") { changing = true }
compileOnly("com.tencent.tinker:tinker-android-anno:${TINKER_VERSION}") { changing = true }
implementation "com.android.support:multidex:1.0.3"
}
def gitSha() {
try {
String gitRev = 'tzl'
if (gitRev == null) {
throw new GradleException("can't get git rev, you should add git to system path or just input test value, such as 'testTinkerId'")
}
return gitRev
} catch (Exception e) {
throw new GradleException("can't get git rev, you should add git to system path or just input test value, such as 'testTinkerId'")
}
}
android {
compileSdkVersion 27
compileOptions {
sourceCompatibility javaVersion
targetCompatibility javaVersion
}
dexOptions {
jumboMode = true
maxProcessCount 4
javaMaxHeapSize "2g"
}
signingConfigs {
release {
try {
storeFile file("./keystore/release.jks")
storePassword "123456"
keyAlias "key0"
keyPassword "123456"
} catch (ex) {
throw new InvalidUserDataException(ex.toString())
}
}
debug {
storeFile file("./keystore/release.jks")
storePassword "123456"
keyAlias "key0"
keyPassword "123456"
}
}
defaultConfig {
applicationId "com.example.tzl.tinker_demo"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true
buildConfigField "String", "MESSAGE", "\"I am the base apk\""
buildConfigField "String", "TINKER_ID", "\"${getTinkerIdValue()}\""
buildConfigField "String", "PLATFORM", "\"all\""
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
minifyEnabled false
signingConfig signingConfigs.debug
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
}
def bakPath = file("${buildDir}/bakApk/")
ext {
//for some reason, you may want to ignore tinkerBuild, such as instant run debug build?
tinkerEnabled = true
//for normal build
//old apk file to build patch apk
tinkerOldApkPath = "${bakPath}/app-debug-0816-14-48-31.apk"
//proguard mapping file to build patch apk
tinkerApplyMappingPath = "${bakPath}/app-debug-1018-17-32-47-mapping.txt"
//resource R.txt to build patch apk, must input if there is resource changed
tinkerApplyResourcePath = "${bakPath}/app-debug-0816-14-48-31.txt"
//only use for build all flavor, if not, just ignore this field
tinkerBuildFlavorDirectory = "${bakPath}/app-1018-17-32-47"
}
def getOldApkPath() {
return hasProperty("OLD_APK") ? OLD_APK : ext.tinkerOldApkPath
}
def getApplyMappingPath() {
return hasProperty("APPLY_MAPPING") ? APPLY_MAPPING : ext.tin