├── settings.gradle
├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ └── layout
│ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── tinker
│ │ └── sample
│ │ └── android
│ │ └── app
│ │ ├── MainActivity.java
│ │ └── SampleApplicationLike.java
├── tinkerMultidexKeep.pro
├── build.gradle
├── proguardRules.pro
└── tinkerpatch.gradle
├── keystore
└── debug.keystore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .travis.yml
├── README.md
├── .gitignore
├── gradle.properties
├── LICENSE
├── gradlew.bat
└── gradlew
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
3 | /version.properties
4 |
--------------------------------------------------------------------------------
/keystore/debug.keystore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TinkerPatch/tinkerpatch-sample/HEAD/keystore/debug.keystore
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TinkerPatch/tinkerpatch-sample/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TinkerPatch/tinkerpatch-sample/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TinkerPatch/tinkerpatch-sample/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TinkerPatch/tinkerpatch-sample/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TinkerPatch/tinkerpatch-sample/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TinkerPatch/tinkerpatch-sample/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | tinker-sample-android
3 | I am in the base apk
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Nov 12 12:36:02 PST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | jdk: oraclejdk8
3 |
4 | cache:
5 | directories:
6 | - .autoconf
7 | - $HOME/.m2
8 |
9 | android:
10 | components:
11 | - tools
12 | - tools # see https://github.com/travis-ci/travis-ci/issues/6040#issuecomment-219367943
13 | - platform-tools
14 | - build-tools-26.0.2
15 | - android-26
16 | - extra-android-m2repository
17 |
18 | script: ./gradlew clean check test
19 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # This repository is DEPRECATED
2 |
3 | # TinkerPatch SDK Sample
4 |
5 | [](https://travis-ci.org/TinkerPatch/tinkerpatch-sample)
6 | [ ](https://bintray.com/simsun/maven/tinkerpatch-android-sdk/_latestVersion)
7 | [](https://slack.tinkerpatch.com)
8 |
9 | [相关文档](http://tinkerpatch.com/Docs/intro)
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 |
39 | # Keystore files
40 | *.jks
41 |
42 | .idea
43 | test.tmp
44 | reports
45 | .DS_Store
46 |
47 | example
48 |
--------------------------------------------------------------------------------
/app/tinkerMultidexKeep.pro:
--------------------------------------------------------------------------------
1 |
2 | #tinker multidex keep patterns:
3 | -keep public class * implements com.tencent.tinker.loader.app.ApplicationLifeCycle {
4 | (...);
5 | void onBaseContextAttached(android.content.Context);
6 | }
7 |
8 | -keep public class * extends com.tencent.tinker.loader.TinkerLoader {
9 | (...);
10 | }
11 |
12 | -keep public class * extends android.app.Application {
13 | ();
14 | void attachBaseContext(android.content.Context);
15 | }
16 |
17 | -keep class com.tencent.tinker.loader.TinkerTestAndroidNClassLoader {
18 | (...);
19 | }
20 |
21 | #your dex.loader patterns here
22 | -keep class tinker.sample.android.app.SampleApplication {
23 | (...);
24 | }
25 |
26 | -keep class com.tencent.tinker.loader.** {
27 | (...);
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx1024m -XX:MaxPermSize=256m
9 | org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Thu Dec 08 22:20:28 CST 2016
16 |
17 | TINKER_VERSION=1.9.2
18 | TINKERPATCH_VERSION=1.2.2
19 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Shengjie Sim Sun
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | dependencies {
4 | implementation fileTree(dir: 'libs', include: ['*.jar'])
5 | implementation "com.android.support:appcompat-v7:25.3.1"
6 | implementation "com.android.support:multidex:1.0.2"
7 | //若使用annotation需要单独引用,对于tinker的其他库都无需再引用
8 | annotationProcessor("com.tinkerpatch.tinker:tinker-android-anno:${TINKER_VERSION}") { changing = true }
9 | compileOnly("com.tinkerpatch.tinker:tinker-android-anno:${TINKER_VERSION}") { changing = true }
10 | implementation("com.tinkerpatch.sdk:tinkerpatch-android-sdk:${TINKERPATCH_VERSION}") { changing = true }
11 | }
12 |
13 |
14 | android {
15 | compileSdkVersion 26
16 | buildToolsVersion "26.0.2"
17 |
18 | signingConfigs {
19 | debug {
20 | storeFile rootProject.file("keystore/debug.keystore")
21 | }
22 | }
23 |
24 | defaultConfig {
25 | applicationId "tinker.sample.android"
26 | minSdkVersion 10
27 | targetSdkVersion 22
28 | versionName "1.0.0"
29 | versionCode 1
30 | multiDexEnabled true
31 | multiDexKeepProguard file("tinkerMultidexKeep.pro") //keep specific classes using proguard syntax
32 | }
33 |
34 | buildTypes {
35 | release {
36 | minifyEnabled true
37 | shrinkResources true
38 | signingConfig signingConfigs.debug
39 |
40 | proguardFiles 'proguardRules.pro', getDefaultProguardFile('proguard-android.txt')
41 | }
42 | debug {
43 | debuggable true
44 | minifyEnabled false
45 | signingConfig signingConfigs.debug
46 | }
47 | }
48 | sourceSets {
49 | main {
50 | jniLibs.srcDirs = ['libs']
51 | }
52 | }
53 | }
54 |
55 | apply from: 'tinkerpatch.gradle'
56 |
--------------------------------------------------------------------------------
/app/proguardRules.pro:
--------------------------------------------------------------------------------
1 | # help us to debug
2 | -renamesourcefileattribute SourceFile
3 | -keepattributes Exceptions
4 | -keepattributes SourceFile,LineNumberTable,keepattributes
5 | -keepattributes InnerClasses
6 | -keepattributes EnclosingMethod
7 | -keepattributes Signature
8 | -keepattributes *Annotation*
9 | -dontshrink
10 |
11 | # Config need by TinkerPatch
12 | -keep class com.tinkerpatch.sdk.TinkerPatch { *; }
13 | -keep class com.tinkerpatch.sdk.BuildConfig { *; }
14 |
15 | -keep class com.tinkerpatch.sdk.TinkerPatch$Builder { *; }
16 | -keep class com.tinkerpatch.sdk.server.RequestLoader { *; }
17 | -keep class com.tinkerpatch.sdk.util.ContentLengthInputStream { *; }
18 | -keep interface com.tinkerpatch.sdk.server.model.DataFetcher { *; }
19 | -keep interface com.tinkerpatch.sdk.server.model.DataFetcher$DataCallback { *; }
20 | -keep class com.tinkerpatch.sdk.server.model.TinkerClientUrl { *; }
21 | -keep class com.tinkerpatch.sdk.server.callback.** { *; }
22 | -keep class com.tinkerpatch.sdk.tinker.callback.** { *; }
23 | -keep public class * extends android.app.Application
24 | -keep class com.tinkerpatch.sdk.loader.TinkerPatchApplicationLike { *; }
25 | -keep class com.tencent.tinker.** { *; }
26 |
27 | # Config from tinker
28 | -dontwarn com.tencent.tinker.anno.AnnotationProcessor
29 | -keep @com.tencent.tinker.anno.DefaultLifeCycle public class *
30 | -keep public class * extends android.app.Application {
31 | *;
32 | }
33 |
34 | -keep public class com.tencent.tinker.loader.app.ApplicationLifeCycle {
35 | *;
36 | }
37 | -keep public class * implements com.tencent.tinker.loader.app.ApplicationLifeCycle {
38 | *;
39 | }
40 |
41 | -keep public class com.tencent.tinker.loader.TinkerLoader {
42 | *;
43 | }
44 | -keep public class * extends com.tencent.tinker.loader.TinkerLoader {
45 | *;
46 | }
47 | -keep public class com.tencent.tinker.loader.TinkerTestDexLoad {
48 | *;
49 | }
50 | -keep public class com.tencent.tinker.loader.TinkerTestAndroidNClassLoader {
51 | *;
52 | }
53 |
54 | #your dex.loader patterns here
55 | -keep class tinker.sample.android.app.SampleApplication
56 | -keep class com.tencent.tinker.loader.**
57 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
17 |
18 |
26 |
34 |
35 |
43 |
51 |
52 |
--------------------------------------------------------------------------------
/app/tinkerpatch.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'tinkerpatch-support'
2 |
3 | /**
4 | * TODO: 请按自己的需求修改为适应自己工程的参数
5 | */
6 | def bakPath = file("${buildDir}/bakApk/")
7 | def baseInfo = "app-1.0.0-1112-12-49-34"
8 | def variantName = "debug"
9 |
10 | /**
11 | * 对于插件各参数的详细解析请参考
12 | * http://tinkerpatch.com/Docs/SDK
13 | */
14 | tinkerpatchSupport {
15 | /** 可以在debug的时候关闭 tinkerPatch **/
16 | /** 当disable tinker的时候需要添加multiDexKeepProguard和proguardFiles,
17 | 这些配置文件本身由tinkerPatch的插件自动添加,当你disable后需要手动添加
18 | 你可以copy本示例中的proguardRules.pro和tinkerMultidexKeep.pro,
19 | 需要你手动修改'tinker.sample.android.app'本示例的包名为你自己的包名, com.xxx前缀的包名不用修改
20 | **/
21 | tinkerEnable = true
22 | reflectApplication = false
23 | /**
24 | * 是否开启加固模式,只能在APK将要进行加固时使用,否则会patch失败。
25 | * 如果只在某个渠道使用了加固,可使用多flavors配置
26 | **/
27 | protectedApp = false
28 | /**
29 | * 实验功能
30 | * 补丁是否支持新增 Activity (新增Activity的exported属性必须为false)
31 | **/
32 | supportComponent = true
33 |
34 | autoBackupApkPath = "${bakPath}"
35 |
36 | appKey = "f938475486f91936"
37 |
38 | /** 注意: 若发布新的全量包, appVersion一定要更新 **/
39 | appVersion = "1.0.0"
40 |
41 | def pathPrefix = "${bakPath}/${baseInfo}/${variantName}/"
42 | def name = "${project.name}-${variantName}"
43 |
44 | baseApkFile = "${pathPrefix}/${name}.apk"
45 | baseProguardMappingFile = "${pathPrefix}/${name}-mapping.txt"
46 | baseResourceRFile = "${pathPrefix}/${name}-R.txt"
47 |
48 | /**
49 | * 若有编译多flavors需求, 可以参照: https://github.com/TinkerPatch/tinkerpatch-flavors-sample
50 | * 注意: 除非你不同的flavor代码是不一样的,不然建议采用zip comment或者文件方式生成渠道信息(相关工具:walle 或者 packer-ng)
51 | **/
52 | }
53 |
54 | /**
55 | * 用于用户在代码中判断tinkerPatch是否被使能
56 | */
57 | android {
58 | defaultConfig {
59 | buildConfigField "boolean", "TINKER_ENABLE", "${tinkerpatchSupport.tinkerEnable}"
60 | }
61 | }
62 |
63 | /**
64 | * 一般来说,我们无需对下面的参数做任何的修改
65 | * 对于各参数的详细介绍请参考:
66 | * https://github.com/Tencent/tinker/wiki/Tinker-%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97
67 | */
68 | tinkerPatch {
69 | ignoreWarning = false
70 | useSign = true
71 | dex {
72 | dexMode = "jar"
73 | pattern = ["classes*.dex"]
74 | loader = []
75 | }
76 | lib {
77 | pattern = ["lib/*/*.so"]
78 | }
79 |
80 | res {
81 | pattern = ["res/*", "r/*", "assets/*", "resources.arsc", "AndroidManifest.xml"]
82 | ignoreChange = []
83 | largeModSize = 100
84 | }
85 |
86 | packageConfig {
87 | }
88 | sevenZip {
89 | zipArtifact = "com.tencent.mm:SevenZip:1.1.10"
90 | // path = "/usr/local/bin/7za"
91 | }
92 | buildConfig {
93 | keepDexApply = false
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/tinker/sample/android/app/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 Shengjie Sim Sun
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package tinker.sample.android.app;
26 |
27 | import android.os.Bundle;
28 | import android.support.v7.app.AppCompatActivity;
29 | import android.util.Log;
30 | import android.view.View;
31 | import android.widget.Button;
32 |
33 | import com.tencent.tinker.lib.util.TinkerLog;
34 | import com.tencent.tinker.loader.shareutil.ShareTinkerInternals;
35 | import com.tinkerpatch.sdk.TinkerPatch;
36 | import com.tinkerpatch.sdk.server.callback.ConfigRequestCallback;
37 |
38 | import java.util.HashMap;
39 |
40 | import tinker.sample.android.R;
41 |
42 |
43 | public class MainActivity extends AppCompatActivity {
44 | private static final String TAG = "Tinker.MainActivity";
45 |
46 | @Override
47 | protected void onCreate(Bundle savedInstanceState) {
48 | super.onCreate(savedInstanceState);
49 | setContentView(R.layout.activity_main);
50 | Log.e(TAG, "i am on onCreate classloader:" + MainActivity.class.getClassLoader().toString());
51 | //test resource change
52 | Log.e(TAG, "i am on onCreate string:" + getResources().getString(R.string.test_resource));
53 | // Log.e(TAG, "i am on patch onCreate");
54 |
55 | Button requestPatchButton = (Button) findViewById(R.id.requestPatch);
56 |
57 | //immediately 为 true, 每次强制访问服务器更新
58 | requestPatchButton.setOnClickListener(new View.OnClickListener() {
59 | @Override
60 | public void onClick(View v) {
61 | TinkerPatch.with().fetchPatchUpdate(true);
62 | }
63 | });
64 |
65 | Button requestConfigButton = (Button) findViewById(R.id.requestConfig);
66 |
67 | //immediately 为 true, 每次强制访问服务器更新
68 | requestConfigButton.setOnClickListener(new View.OnClickListener() {
69 | @Override
70 | public void onClick(View v) {
71 | TinkerPatch.with().fetchDynamicConfig(new ConfigRequestCallback() {
72 |
73 | @Override
74 | public void onSuccess(HashMap configs) {
75 | TinkerLog.w(TAG, "request config success, config:" + configs);
76 | }
77 |
78 | @Override
79 | public void onFail(Exception e) {
80 | TinkerLog.w(TAG, "request config failed, exception:" + e);
81 | }
82 | }, true);
83 | }
84 | });
85 |
86 | Button cleanPatchButton = (Button) findViewById(R.id.cleanPatch);
87 |
88 | cleanPatchButton.setOnClickListener(new View.OnClickListener() {
89 | @Override
90 | public void onClick(View v) {
91 | TinkerPatch.with().cleanAll();
92 | }
93 | });
94 |
95 | Button killSelfButton = (Button) findViewById(R.id.killSelf);
96 |
97 | killSelfButton.setOnClickListener(new View.OnClickListener() {
98 | @Override
99 | public void onClick(View v) {
100 | ShareTinkerInternals.killAllOtherProcess(getApplicationContext());
101 | android.os.Process.killProcess(android.os.Process.myPid());
102 | }
103 | });
104 | }
105 |
106 |
107 | @Override
108 | protected void onResume() {
109 | Log.e(TAG, "i am on onResume");
110 | // Log.e(TAG, "i am on patch onResume");
111 | super.onResume();
112 |
113 | }
114 |
115 | @Override
116 | protected void onPause() {
117 | super.onPause();
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/tinker/sample/android/app/SampleApplicationLike.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 Shengjie Sim Sun
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package tinker.sample.android.app;
26 |
27 |
28 | import android.annotation.TargetApi;
29 | import android.app.Application;
30 | import android.content.Context;
31 | import android.content.Intent;
32 | import android.os.Build;
33 | import android.support.multidex.MultiDex;
34 | import android.util.Log;
35 |
36 | import com.tencent.tinker.anno.DefaultLifeCycle;
37 | import com.tencent.tinker.lib.listener.DefaultPatchListener;
38 | import com.tencent.tinker.lib.patch.UpgradePatch;
39 | import com.tencent.tinker.lib.reporter.DefaultLoadReporter;
40 | import com.tencent.tinker.lib.reporter.DefaultPatchReporter;
41 | import com.tencent.tinker.lib.service.PatchResult;
42 | import com.tencent.tinker.loader.app.ApplicationLifeCycle;
43 | import com.tencent.tinker.loader.app.DefaultApplicationLike;
44 | import com.tencent.tinker.loader.shareutil.ShareConstants;
45 | import com.tinkerpatch.sdk.TinkerPatch;
46 | import com.tinkerpatch.sdk.server.callback.ConfigRequestCallback;
47 | import com.tinkerpatch.sdk.server.callback.RollbackCallBack;
48 | import com.tinkerpatch.sdk.server.callback.TinkerPatchRequestCallback;
49 | import com.tinkerpatch.sdk.tinker.callback.ResultCallBack;
50 | import com.tinkerpatch.sdk.tinker.service.TinkerServerResultService;
51 |
52 | import java.util.HashMap;
53 |
54 | import tinker.sample.android.BuildConfig;
55 |
56 | /**
57 | * because you can not use any other class in your application, we need to
58 | * move your implement of Application to {@link ApplicationLifeCycle}
59 | * As Application, all its direct reference class should be in the main dex.
60 | *
61 | * We use tinker-android-anno to make sure all your classes can be patched.
62 | *
63 | * application: if it is start with '.', we will add SampleApplicationLifeCycle's package name
64 | *
65 | * flags:
66 | * TINKER_ENABLE_ALL: support dex, lib and resource
67 | * TINKER_DEX_MASK: just support dex
68 | * TINKER_NATIVE_LIBRARY_MASK: just support lib
69 | * TINKER_RESOURCE_MASK: just support resource
70 | *
71 | * loaderClass: define the tinker loader class, we can just use the default TinkerLoader
72 | *
73 | * loadVerifyFlag: whether check files' md5 on the load time, defualt it is false.
74 | *
75 | * Created by zhangshaowen on 16/3/17.
76 | */
77 | @SuppressWarnings("unused")
78 | @DefaultLifeCycle(application = "tinker.sample.android.app.SampleApplication",
79 | flags = ShareConstants.TINKER_ENABLE_ALL,
80 | loadVerifyFlag = false)
81 | public class SampleApplicationLike extends DefaultApplicationLike {
82 | private static final String TAG = "Tinker.SampleAppLike";
83 |
84 | public SampleApplicationLike(Application application,
85 | int tinkerFlags,
86 | boolean tinkerLoadVerifyFlag,
87 | long applicationStartElapsedTime,
88 | long applicationStartMillisTime,
89 | Intent tinkerResultIntent
90 | ) {
91 | super(
92 | application,
93 | tinkerFlags,
94 | tinkerLoadVerifyFlag,
95 | applicationStartElapsedTime,
96 | applicationStartMillisTime,
97 | tinkerResultIntent
98 | );
99 | }
100 |
101 | /**
102 | * install multiDex before install tinker
103 | * so we don't need to put the tinker lib classes in the main dex
104 | */
105 | @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
106 | @Override
107 | public void onBaseContextAttached(Context base) {
108 | super.onBaseContextAttached(base);
109 | //you must install multiDex whatever tinker is installed!
110 | MultiDex.install(base);
111 | }
112 |
113 | /**
114 | * 我们需要确保至少对主进程跟patch进程初始化 TinkerPatch
115 | */
116 | @Override
117 | public void onCreate() {
118 | super.onCreate();
119 | initTinker();
120 | }
121 |
122 | private void initTinker() {
123 | if (BuildConfig.TINKER_ENABLE) {
124 | //开始检查是否有补丁,这里配置的是每隔访问3小时服务器是否有更新。
125 | TinkerPatch.init(this)
126 | .reflectPatchLibrary()
127 | .setPatchRollbackOnScreenOff(true)
128 | .setPatchRestartOnSrceenOff(true)
129 | .setFetchPatchIntervalByHours(3);
130 |
131 | // 获取当前的补丁版本
132 | Log.d(TAG, "current patch version is " + TinkerPatch.with().getPatchVersion());
133 |
134 | //每隔3个小时去访问后台时候有更新,通过handler实现轮训的效果
135 | TinkerPatch.with().fetchPatchUpdateAndPollWithInterval();
136 | }
137 | }
138 |
139 | /**
140 | * 在这里给出TinkerPatch的所有接口解释
141 | * 更详细的解释请参考:http://tinkerpatch.com/Docs/api
142 | */
143 | private void useSample() {
144 | TinkerPatch.init(this)
145 | //是否自动反射Library路径,无须手动加载补丁中的So文件
146 | //注意,调用在反射接口之后才能生效,你也可以使用Tinker的方式加载Library
147 | .reflectPatchLibrary()
148 | //向后台获取是否有补丁包更新,默认的访问间隔为3个小时
149 | //若参数为true,即每次调用都会真正的访问后台配置
150 | .fetchPatchUpdate(false)
151 | //设置访问后台补丁包更新配置的时间间隔,默认为3个小时
152 | .setFetchPatchIntervalByHours(3)
153 | //向后台获得动态配置,默认的访问间隔为3个小时
154 | //若参数为true,即每次调用都会真正的访问后台配置
155 | .fetchDynamicConfig(new ConfigRequestCallback() {
156 | @Override
157 | public void onSuccess(HashMap hashMap) {
158 |
159 | }
160 |
161 | @Override
162 | public void onFail(Exception e) {
163 |
164 | }
165 | }, false)
166 | //设置访问后台动态配置的时间间隔,默认为3个小时
167 | .setFetchDynamicConfigIntervalByHours(3)
168 | //设置当前渠道号,对于某些渠道我们可能会想屏蔽补丁功能
169 | //设置渠道后,我们就可以使用后台的条件控制渠道更新
170 | .setAppChannel("default")
171 | //屏蔽部分渠道的补丁功能
172 | .addIgnoreAppChannel("googleplay")
173 | //设置tinkerpatch平台的条件下发参数
174 | .setPatchCondition("test", "1")
175 | //设置补丁合成成功后,锁屏重启程序
176 | //默认是等应用自然重启
177 | .setPatchRestartOnSrceenOff(true)
178 | //我们可以通过ResultCallBack设置对合成后的回调
179 | //例如弹框什么
180 | .setPatchResultCallback(new ResultCallBack() {
181 | @Override
182 | public void onPatchResult(PatchResult patchResult) {
183 | Log.i(TAG, "onPatchResult callback here");
184 | }
185 | })
186 | //设置收到后台回退要求时,锁屏清除补丁
187 | //默认是等主进程重启时自动清除
188 | .setPatchRollbackOnScreenOff(true)
189 | //我们可以通过RollbackCallBack设置对回退时的回调
190 | .setPatchRollBackCallback(new RollbackCallBack() {
191 | @Override
192 | public void onPatchRollback() {
193 | Log.i(TAG, "onPatchRollback callback here");
194 | }
195 | });
196 | }
197 |
198 | /**
199 | * 自定义Tinker类的高级用法,一般不推荐使用
200 | * 更详细的解释请参考:http://tinkerpatch.com/Docs/api
201 | */
202 | private void complexSample() {
203 | TinkerPatch.Builder builder = new TinkerPatch.Builder(this);
204 | //修改tinker的构造函数,自定义类
205 | builder.listener(new DefaultPatchListener(getApplication()))
206 | .loadReporter(new DefaultLoadReporter(getApplication()))
207 | .patchReporter(new DefaultPatchReporter(getApplication()))
208 | .resultServiceClass(TinkerServerResultService.class)
209 | .upgradePatch(new UpgradePatch())
210 | .patchRequestCallback(new TinkerPatchRequestCallback());
211 |
212 | TinkerPatch.init(builder.build());
213 | }
214 | }
215 |
--------------------------------------------------------------------------------