Bugly implements hot update of APP
Bugly implements thermal repair using Wechat Tinker Technology. Tinker is simplified.
Bugly Hot Repair Official Documents
Configuration parameters
-
Adding plug-in dependencies
Add:
buildscript { repositories { jcenter() } dependencies { // The tinkersupport plug-in, where latest.release refers to the latest version number, can also specify a specific version number, such as 1.0.3 classpath "com.tencent.bugly:tinker-support:latest.release" } }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
II. Integrated SDK
-
gradle configuration
Add (example configuration) to the "build.gradle" file of app module:
dependencies { compile "com.android.support:multidex:1.0.1" compile 'com.tencent.bugly:crashreport_upgrade:latest.release' }
- 1
- 2
- 3
- 4
Add:
// Dependent plug-in scripts apply from: 'tinker-support.gradle'
- 1
- 2
-
The contents of tinker-support.gradle are as follows (example configuration):
You need to create the tinker-support.gradle file in the same directory
apply plugin: 'com.tencent.bugly.tinker-support' def bakPath = file("${buildDir}/bakApk/") def appName = "app-0111-15-18-41" /** * For detailed analysis of plug-in parameters, please refer to */ tinkerSupport { // Open the tinker-support plug-in with the default value true enable = true // Specify the archive directory, default value of current module subdirectory tinker autoBackupApkDir = "${bakPath}" // Whether to enable overlay tinkerPatch configuration function, default value false // The tinkerPatch configuration does not take effect after opening, that is, there is no need to add tinkerPatch overrideTinkerPatchConfiguration = true // When compiling patch packs, you must specify the baseline version of the apk, which defaults to null // If null, it means that the patch package is not compiled // @{link tinkerPatch.oldApk } baseApk = "${bakPath}/${appName}/app-release.apk" // applyMapping corresponding to tinker plug-in baseApkProguardMapping = "${bakPath}/${appName}/app-release-mapping.txt" // ApplyResource Mapping for the tinker plug-in baseApkResourceMapping = "${bakPath}/${appName}/app-release-R.txt" // Uniquely identifies the current version tinkerId = "1.0.1-base" // Whether to open the proxy Application or not, there is no need to modify the Application after setting, the default is false. enableProxyApplication = false }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
Initialization of SDK
enableProxyApplication = false
- Custom Application
public class SampleApplication extends TinkerApplication {
public SampleApplication() {
super(ShareConstants.TINKER_ENABLE_ALL, "com.yiba.test.buglypatch.SampleApplicationLike",
"com.tencent.tinker.loader.TinkerLoader", false);
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- Custom Application Like
public class SampleApplicationLike extends DefaultApplicationLike {
public static final String TAG = "Tinker.SampleApplicationLike";
public SampleApplicationLike(Application application, int tinkerFlags,
boolean tinkerLoadVerifyFlag, long applicationStartElapsedTime,
long applicationStartMillisTime, Intent tinkerResultIntent, Resources[] resources,
ClassLoader[] classLoader, AssetManager[] assetManager) {
super(application, tinkerFlags, tinkerLoadVerifyFlag, applicationStartElapsedTime,
applicationStartMillisTime, tinkerResultIntent, resources, classLoader,
assetManager);
}
@Override
public void onCreate() {
super.onCreate();
// SDK initialization is implemented here, and appId is replaced by your appId applied for on the Bugly platform.
Bugly.init(getApplication(), "900029763", true);
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
public void onBaseContextAttached(Context base) {
super.onBaseContextAttached(base);
// you must install multiDex whatever tinker is installed!
MultiDex.install(base);
// Install tinker
// TinkerManager.installTinker(this); replace with the method provided by Bugly below
Beta.installTinker(this);
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void registerActivityLifecycleCallback(Application.ActivityLifecycleCallbacks callbacks) {
getApplication().registerActivityLifecycleCallbacks(callbacks);
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
IV. Android Manifest. XML Configuration
- Permission configuration
<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"/>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- Activity configuration
<activity
android:name="com.tencent.bugly.beta.ui.BetaActivity"
android:theme="@android:style/Theme.Translucent" />
- 1
- 2
- 3
-
Configure FileProvider (after Android N)
see File
V. Confusion Configuration
To avoid confusion with SDK, add the following configuration to the Proguard confusion file:
-dontwarn com.tencent.bugly.**
-keep public class com.tencent.bugly.**{*;}
- 1
- 2
If you use the support-v4 package, you also need to configure the following confusion rules:
-keep class android.support.**{*;}
- 1
6. Compilation Benchmark Package
Benchmark packages are packages that originally run bug s.
Click the Gradle button in the upper right corner of Android Studio to find the assemble Release task of the project, and double-click to execute the assemble Release task.
When the task is completed, the following files are generated in the build directory:
Repair the base code
Prefix code:
public class BugClass {
public String bug() {
String str = "This is a bug";
str = null;
Log.e("zhang", "BugClass --> bug--> str length :" + str.length());
return str;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
Repair the following code:
public class BugClass {
public String bug() {
String str = "This is a bug";
// str = null;
Log.e("zhang", "BugClass --> bug--> str length :" + str.length());
return str + " , fixed!!!";
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
Call code:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BugClass bugClass = new BugClass();
String bug = bugClass.bug();
Toast.makeText(MainActivity.this, bug, Toast.LENGTH_SHORT).show();
}
});
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
8. Generating patch packs
- Modifying appName names and file names need to be consistent. At the same time, tinkerid=1.0.1-base of the reference package is changed to tinkerid=1.0.1-patch of the patch package.
- Generate patch packs
Perform the task operation of generating the patch package:
After the task is executed, three files are generated, of which patch_signed_7zip.apk is the patch package we need.
Upload the patch package to the hot update of bugly's application upgrade module
Specific view bugly's official documentation.
Uploading patches may not take effect immediately. Just try a few more times.
Change from: https://blog.csdn.net/qq_33689414/article/details/54911918