Tinker

0.Check your version of gradle,Ensure the version of gradle greater than 2.14.1

e.g. 2.14.1 3.1 3.2 3.2.1
You can download the gradle from this website
https://services.gradle.org/distributions

add adb ,gradle on your path
You can see this article How to adb into your path

You can see the Tinker wiki.
https://github.com/Tencent/tinker/wiki

1.DownLoad the source code of tinker from github
git clone git@github.com:Tencent/tinker.git

2.Open the Sample project
cd tinker/tinker-sample-android

3.DownLoad the dependencies of sample,It may take a long time when you run firstly,you can drink a cup of coffee.
gradle clean

4.Buid debug apk
gradle assembleDebug

5.Install the debug base apk into your phone or emulator(e.g. Genymotion,Bluestacks)
adb uninstall tinker.sample.android && adb install app/build/bakApk/*.apk

6.Start the debug base apk
adb shell am start tinker.sample.android/.app.MainActivity

7.Change some codes in order to fix bugs

TODO:// Coding in order to fix bug1
TODO:// Coding in order to fix bug2

e.g.Change the Log TAG of MainActivity

one: get row of TAG
grep -n "TAG" app/src/main/java/tinker/sample/android/app/MainActivity.java | head -n 1 | cut -d ":" -f 1

two: Replace the TAG to your tag eg:TestTinker
sed -i '42s/.*/private static final String TAG = "TestTinker";/' app/src/main/java/tinker/sample/android/app/MainActivity.java

three: confirm the change successfully
grep -n "TestTinker" app/src/main/java/tinker/sample/android/app/MainActivity.java

8.Get the base debug apk fileName
find app/build/bakApk/ -type f -name *.apk -print | xargs ls -ltr | head -n 1 | awk '{print $9}' | cut -d "/" -f 4

9.Get “tinkerOldApkPath” first occurrence of rows which from tinker-sample-android/app/build.gradle
grep -n "tinkerOldApkPath" app/build.gradle | head -n 1 | cut -d ":" -f 1

10.Change the config of app/build.gradle to Updte the tinkerOldApkPath

Replace the line numbers which from number9 and apkName which from number8

e.g.
tinker10

number8 app-debug-1130-12-54-43.apk
number9 147

thus,you can get the command.

sed -i ‘number8s/.*/tinkerOldApkPath=”${bakPath}\/number9”/’ app/build.gradle

e.g.
sed -i '147s/.*/tinkerOldApkPath="${bakPath}\/app-debug-1130-12-54-43.apk"/' app/build.gradle

11.confirm the number11 do successfully

grep -n “number8” app/build.gradle

e.g.
grep -n "app-debug-1130-12-54-43.apk" app/build.gradle

12.Build in order to the patch apk
gradle tinkerPatchDebug

13.Push patch apk into phone or emulator
adb push app/build/outputs/tinkerPatch/debug/patch_signed_7zip.apk /sdcard/

14.Click LOADPATH Button on the Sample App
If PATH load success,the you can see the Toast which is patch success,please restart process.

15.kill the running apk or restart the running apk
adb shell am force-stop tinker.sample.android

or

If you phone is root,you can use adb shell kill -9 pid
./kill.sh

the content of kill.sh

kill.sh

a.vim kill.sh && chmod 777 ./kill.sh
b.input content of kill.sh
c.then ./kill.sh

16.Start the apk again
adb shell am start tinker.sample.android/.app.MainActivity

17.Click showinfo in order to confirm the patch load successfully or not.

adb logcat | grep TestTinker

If you see log which tag is “TestTinker”,Congratulate to you!

18.Change some codes in order to hot fix bugs from number 8

TODO:// Coding in order to fix bug1
TODO:// Coding in order to fix bug2




Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • Claude Code CLI 新手使用指南
  • AndroidX,migrate,jetifier
  • KDE Connect Indicator
  • BusyBox
  • Source for Android 28