Skip to content

Commit 376450b

Browse files
committed
提交《热修复——Bugly让热修复变得如此简单》Demo
1 parent 127d755 commit 376450b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+30727
-1
lines changed

.idea/modules.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo3Ex/app-release-R.txt

+1,734
Large diffs are not rendered by default.

Demo3Ex/app-release-mapping.txt

+28,010
Large diffs are not rendered by default.

Demo3Ex/app-release.apk

1.7 MB
Binary file not shown.

Demo3Ex/patch_signed_7zip.apk

20.8 KB
Binary file not shown.

Demo3Ex/readme.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
app-release.apk: tinker-bugly��Demoʾ��apk��
2+
patch_signed_7zip.apk: app-release.apk�IJ�����
3+
4+
����Խ�app-release.apk��װ���Լ��ֻ�������һ�¡�

build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
apply from: 'config.gradle'// tinker-bugly的tinker-support.gradle和build.gradle需要用到同一个versionName,故加第三个gradle配置
23

34
buildscript {
45

@@ -9,6 +10,8 @@ buildscript {
910
dependencies {
1011
classpath 'com.android.tools.build:gradle:3.0.0'
1112
classpath('com.tencent.tinker:tinker-patch-gradle-plugin:1.9.1')
13+
// tinkersupport插件(1.0.3以上无须再配置tinker插件)
14+
classpath "com.tencent.bugly:tinker-support:1.1.1"
1215

1316
// NOTE: Do not place your application dependencies here; they belong
1417
// in the individual module build.gradle files

config.gradle

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ext {
2+
android = [compileSdkVersion: 26,
3+
applicationId : "com.lqr.tinker_bugly",
4+
minSdkVersion : 16,
5+
targetSdkVersion : 26,
6+
versionCode : 1,
7+
versionName : "1.0"]
8+
// dependencies = ["appcompat-v7": "com.android.support:appcompat-v7:23.4.0"]
9+
}

settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
include ':app', ':tinker-local'
1+
include ':app', ':tinker-local', ':tinker-bugly'
22

33
//, ':jnitest'

tinker-bugly/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

tinker-bugly/build.gradle

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
apply plugin: 'com.android.application'
2+
apply from: 'tinker-support.gradle'
3+
4+
android {
5+
compileSdkVersion 26
6+
defaultConfig {
7+
applicationId rootProject.ext.android.applicationId
8+
minSdkVersion rootProject.ext.android.minSdkVersion
9+
targetSdkVersion rootProject.ext.android.targetSdkVersion
10+
versionCode rootProject.ext.android.versionCode
11+
versionName rootProject.ext.android.versionName
12+
13+
// 开启multidex
14+
multiDexEnabled true
15+
}
16+
// recommend
17+
dexOptions {
18+
jumboMode = true
19+
}
20+
// 签名配置
21+
signingConfigs {
22+
release {
23+
try {
24+
storeFile file("./keystore/release.keystore")
25+
storePassword "testres"
26+
keyAlias "testres"
27+
keyPassword "testres"
28+
} catch (ex) {
29+
throw new InvalidUserDataException(ex.toString())
30+
}
31+
}
32+
33+
debug {
34+
storeFile file("./keystore/debug.keystore")
35+
}
36+
}
37+
38+
// 构建类型
39+
buildTypes {
40+
release {
41+
minifyEnabled true
42+
signingConfig signingConfigs.release
43+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
44+
}
45+
debug {
46+
debuggable true
47+
minifyEnabled false
48+
signingConfig signingConfigs.debug
49+
}
50+
}
51+
52+
sourceSets {
53+
main {
54+
jniLibs.srcDirs = ['libs']
55+
}
56+
}
57+
}
58+
59+
dependencies {
60+
implementation fileTree(dir: 'libs', include: ['*.jar'])
61+
62+
implementation 'com.android.support:appcompat-v7:26.1.0'
63+
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
64+
testImplementation 'junit:junit:4.12'
65+
androidTestImplementation 'com.android.support.test:runner:1.0.1'
66+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
67+
68+
implementation "com.android.support:multidex:1.0.1" // 多dex配置
69+
implementation 'com.tencent.bugly:crashreport_upgrade:1.3.4'// 远程仓库集成方式(推荐)
70+
}

tinker-bugly/keystore/debug.keystore

1.24 KB
Binary file not shown.
4 KB
Binary file not shown.
13.4 KB
Binary file not shown.
13.4 KB
Binary file not shown.

tinker-bugly/libs/x86/libLQRJni.so

5.41 KB
Binary file not shown.

tinker-bugly/proguard-rules.pro

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Bugly混淆规则
16+
-dontwarn com.tencent.bugly.**
17+
-keep public class com.tencent.bugly.**{*;}
18+
19+
# 避免影响升级功能,需要keep住support包的类
20+
-keep class android.support.**{*;}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.lqr;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.lqr", appContext.getPackageName());
25+
}
26+
}
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.lqr.tinker_bugly">
4+
5+
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
8+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
9+
<uses-permission android:name="android.permission.READ_LOGS"/>
10+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
11+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
12+
13+
<application
14+
android:name="com.lqr.MyApplication"
15+
android:allowBackup="true"
16+
android:icon="@mipmap/ic_launcher"
17+
android:label="@string/app_name"
18+
android:roundIcon="@mipmap/ic_launcher_round"
19+
android:supportsRtl="true"
20+
android:theme="@style/AppTheme">
21+
<activity android:name="com.lqr.MainActivity">
22+
<intent-filter>
23+
<action android:name="android.intent.action.MAIN"/>
24+
25+
<category android:name="android.intent.category.LAUNCHER"/>
26+
</intent-filter>
27+
</activity>
28+
29+
<!--Bugly热修复配置-->
30+
<activity
31+
android:name="com.tencent.bugly.beta.ui.BetaActivity"
32+
android:configChanges="keyboardHidden|orientation|screenSize|locale"
33+
android:theme="@android:style/Theme.Translucent"/>
34+
35+
<provider
36+
android:name="android.support.v4.content.FileProvider"
37+
android:authorities="${applicationId}.fileProvider"
38+
android:exported="false"
39+
android:grantUriPermissions="true">
40+
<meta-data
41+
android:name="android.support.FILE_PROVIDER_PATHS"
42+
android:resource="@xml/provider_paths"/>
43+
</provider>
44+
</application>
45+
46+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.lqr;
2+
3+
import android.os.Bundle;
4+
import android.os.Environment;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.view.View;
7+
import android.widget.TextView;
8+
import android.widget.Toast;
9+
10+
import com.lqr.jnitest.JniUtil;
11+
import com.lqr.tinker_bugly.R;
12+
import com.tencent.bugly.beta.Beta;
13+
import com.tencent.tinker.lib.library.TinkerLoadLibrary;
14+
15+
public class MainActivity extends AppCompatActivity {
16+
17+
private TextView mTvAbi;
18+
19+
@Override
20+
protected void onCreate(Bundle savedInstanceState) {
21+
super.onCreate(savedInstanceState);
22+
setContentView(R.layout.activity_main);
23+
mTvAbi = findViewById(R.id.tv_abi);
24+
mTvAbi.setText(mTvAbi.getText() + android.os.Build.CPU_ABI);
25+
}
26+
27+
public void say(View view) {
28+
// Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_SHORT).show();
29+
Toast.makeText(getApplicationContext(), "Hello World", Toast.LENGTH_SHORT).show();
30+
// Toast.makeText(getApplicationContext(), "Hello World 123", Toast.LENGTH_SHORT).show();
31+
}
32+
33+
public void string_from_so(View view) {
34+
String string = JniUtil.hello();
35+
Toast.makeText(getApplicationContext(), string, Toast.LENGTH_SHORT).show();
36+
}
37+
38+
public void install_patch(View view) {
39+
Beta.applyTinkerPatch(getApplicationContext(), Environment.getExternalStorageDirectory().getAbsolutePath() + "/patch_signed_7zip.apk");
40+
}
41+
42+
public void uninstall_patch(View view) {
43+
boolean now = true;
44+
Beta.cleanTinkerPatch(now);
45+
}
46+
47+
public void check_upgrade(View view) {
48+
Beta.checkUpgrade();
49+
}
50+
51+
/**
52+
* 用户主动下载补丁文件
53+
* <p>
54+
* 适用于Beta.canAutoDownloadPatch = false;的情况。 开发者自己选择下载补丁的时机。
55+
*/
56+
public void download_patch(View view) {
57+
Beta.downloadPatch();
58+
}
59+
60+
/**
61+
* 用户主动合成补丁
62+
* <p>
63+
* 适用于Beta.canAutoPatch = true;的情况。 开发者自己选择合成补丁的时机。
64+
*/
65+
public void apply_patch(View view) {
66+
Beta.applyDownloadedPatch();
67+
}
68+
69+
public void kill_myself(View view) {
70+
android.os.Process.killProcess(android.os.Process.myPid());
71+
}
72+
73+
74+
/*------------------ Tinker封装好的非hack方式加载so库方法 begin ------------------*/
75+
// 使用非Hack的方式(测试失败)
76+
public void load_library_no_hack(View view) {
77+
Beta.loadLibrary(JniUtil.LIB_NAME);
78+
}
79+
80+
public void load_library_armeabi(View view) {
81+
Beta.loadArmLibrary(getApplicationContext(), JniUtil.LIB_NAME);// 底层使用的跟Beta.loadLibrary一样,故测试失败
82+
}
83+
84+
public void load_library_armeabi_v7a(View view) {
85+
Beta.loadArmV7Library(getApplicationContext(), JniUtil.LIB_NAME);// 底层使用的跟Beta.loadLibrary一样,故测试失败
86+
}
87+
/*------------------ Tinker封装好的非hack方式加载so库方法 end ------------------*/
88+
89+
/*------------------ Tinker的原生接口 ------------------*/
90+
// 使用Hack的方式(测试成功)
91+
public void load_library_hack(View view) {
92+
String CPU_ABI = android.os.Build.CPU_ABI;
93+
// 将tinker library中的 CPU_ABI架构的so 注册到系统的library path中。
94+
TinkerLoadLibrary.installNavitveLibraryABI(this, CPU_ABI);
95+
}
96+
97+
}

0 commit comments

Comments
 (0)