Add dependencies {classpath ‘com.tencent. Bugly :tinker-support:1.1.5’} 2. Gradle project adds buyly and Tinker hotupdate dependencies
defaultConfig { multiDexEnabled true}
Dependencies {implementation “com. Android. Support: appcompat – v7: ${project. FastjsonLibVersion}” / / dex configuration implementation ‘com. Android. Support: multidex: 1.0.2’ aar way / / / / local integration the compile (name: ‘bugly_crashreport_upgrade – 1.3.6, ext: ‘aar) / / remote rely on integrated way (recommended) implementation’ com. Tencent. Bugly: crashreport_upgrade: 1.3.6 ‘/ / specified tinker rely on version (note: Application upgrade 1.3.5 version, no longer built-in tinker) implementation ‘com. Tencent. Tinker: tinker – android – lib: 1.9.9’}
// Rely on plug-in scriptsCopy the code
apply from: ‘tinker-support.gradle’
====================tinker-support.gradle=============
apply plugin: ‘com.tencent.bugly.tinker-support’
def bakPath = file(“${buildDir}/bakApk/”)
/ * *
- */ /def baseApkDir = “app-1108-15-10-04” def baseApkDir = “app-0420-14-55-27”
/ * *
-
*/ tinkerSupport {
// Enable tinker-support. The default value is true enable = true
// Automatically generates tinkerId, you do not need to worry about tinkerId, default is false autoGenerateTinkerId = true
Tinker autoBackupApkDir = “${bakPath}”
/ / whether to enable cover tinkerPatch configuration function, the default value is false / / open tinkerPatch configuration is not effective after, namely without adding tinkerPatch overrideTinkerPatchConfiguration = true
// @{link tinkerpatch.oldapk} baseApk = “// The base version of apK must be specified when compiling the patch package. The default value is null.{baseApkDir}/app-release.apk” // baseApk = “{baseApkDir}/app-debug.apk”
// baseApkProguardMapping =”{baseApkDir}/app-release-mapping.txt” // baseApkProguardMapping = “{baseApkDir}/app-debug-mapping.txt”
ApplyResourceMapping baseApkResourceMapping =”{baseApkDir}/app-release-R.txt” // baseApkResourceMapping = “{baseApkDir}/app-debug-R.txt”
TinkerId = “1.0.6-patch” tinkerId = “1.0.6-patch”
// buildAllFlavorsDir =”{baseApkDir}”
The default value is false. IsProtectedApp = true
// Whether to integrate by reflecting Application without changing Application enabxyApplication = true
New Activity supportHotplugComponent = true is supported
}
/ * *
-
Generally speaking, we do not need to make any changes to the following parameters
-
For details about each parameter, please refer to:
-
Github.com/Tencent/tin… / tinkerPatch { tinkerEnable = true ignoreWarning = false useSign = false 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 / 7 za”} buildConfig {keepDexApply = false // tinkerId = “base-2.0.1”}}
=====================Application================== public class BuglyTinkerApplication extends Application { @Override public void onCreate() { super.onCreate();
setStrictMode(); EnableHotfix = true; // Set whether to enable hot updates. / / Settings are automatically download patch Beta. CanAutoDownloadPatch = true; / / set whether to prompt the user to restart the Beta. CanNotifyUserRestart = true; CanAutoPatch = true; /** * patch callback interface, BetaPatchListener = new betaPatchListener () {@override public void onPatchReceived(String) patchFileUrl) { Toast.makeText(getApplicationContext(), patchFileUrl, Toast.LENGTH_SHORT).show(); } @Override public void onDownloadReceived(long savedLength, long totalLength) {Copy the code
// Toast.makeText(getApplicationContext(), String.format(Locale.getDefault(), // “%s %d%%”, // Beta.strNotificationDownloading, // (int) (totalLength == 0 ? 0 : savedLength * 100 / totalLength)), Toast.LENGTH_SHORT).show(); // }
@Override
public void onDownloadSuccess(String patchFilePath) {
Copy the code
// Toast.makeText(getApplicationContext(), patchFilePath, Toast.LENGTH_SHORT).show(); // Beta.applyDownloadedPatch(); }
@Override
public void onDownloadFailure(String msg) {
Copy the code
// Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show(); }
@Override
public void onApplySuccess(String msg) {
Toast.makeText(getApplicationContext(), "2222222222", Toast.LENGTH_SHORT).show();
}
@Override
public void onApplyFailure(String msg) {
Copy the code
// Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show(); }
@Override
public void onPatchRollback() {
Copy the code
// Toast.makeText(getApplicationContext(), “onPatchRollback”, Toast.LENGTH_SHORT).show(); }};
Bugly.init(this, "273D6fb859 ", true); bugly. init(this," 273D6fb859 ", true) } @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); // you must install multiDex whatever tinker is installed! MultiDex.install(base); // installTinker beta.installtinker (); } @TargetApi(9) protected void setStrictMode() { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build()); }Copy the code
}
The baseline package is generated by build Release
Def baseApkDir = “app-1108-15-10-04” tinkerId = “1.0.1-base” Baseline package-bakapk generates a directory such as app-1108-18-13-15
Def baseApkDir = “app-1108-18-13-15” tinkerId = “1.0.1-patch” patch package def baseApkDir = “app-1108-18-13-15” tinkerId = “1.0.1-patch” patch package
Test: place the patch in the phone’s local directory and start the fix