{"id":1863,"date":"2023-03-29T22:11:20","date_gmt":"2023-03-29T14:11:20","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1863"},"modified":"2023-04-22T09:07:31","modified_gmt":"2023-04-22T01:07:31","slug":"tinker-hot-update-quick-integration","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/29\/tinker-hot-update-quick-integration\/","title":{"rendered":"Tinker\u70ed\u66f4\u65b0\u5feb\u901f\u96c6\u6210"},"content":{"rendered":"<h2>\u524d\u8a00<\/h2>\n<p>\u7531\u4e8e\u516c\u53f8\u9700\u8981\uff0c\u5165\u5751Tinker\uff0c\u7ed3\u679c\u53d1\u73b0dex\u4ee5\u53ca\u8d44\u6e90\u6587\u4ef6\uff0c\u53ef\u4ee5\u66ff\u6362\u3002\u800cSo\u6587\u4ef6\uff0cLog\u65e5\u5fd7\u63d0\u793a\u66ff\u6362\u6210\u529f\uff0c\u800c\u4f7f\u7528\u65f6\u4e0d\u597d\u4f7f\u3002<\/p>\n<h2>\u76ee\u6807<\/h2>\n<p><!-- more --><\/p>\n<p>\u66f4\u65b0Dex\uff0c\u8d44\u6e90\u6587\u4ef6\uff0c\u4ee5\u53caSo\u5e93\u6587\u4ef6<\/p>\n<h2>\u539f\u7406<\/h2>\n<p>\u7b80\u5355\u8bf4\u4e0bTinker\u7684\u539f\u7406\u3002\u901a\u8fc7\u7b97\u6cd5\uff0c\u5c06\u65b0\u7684\u66f4\u65b0\u7684APK\u548c\u539f\u7248\u7684BaseApk\u4e4b\u95f4\u7684\u5dee\u5f02\u751f\u6210\u4e00\u4e2aPatch\u8865\u4e01\u5305\u3002\u5c06\u8865\u4e01\u5305\u53d1\u9001\u5230\u624b\u673a\u672c\u5730\uff0c\u5728\u7528\u6237\u6253\u5f00\u624b\u673a\u65f6\u5c06\u8865\u4e01\u5305\u52a0\u8f7d\u8fdb\u624b\u673a\u3002\u66f4\u52a0\u5177\u4f53\u7684\u539f\u7406\uff0c\u6b64\u5904\u4e0d\u505a\u53d9\u8ff0\u3002<\/p>\n<h2>\u96c6\u6210<\/h2>\n<h3>tinker-patch-gradle-plugin\u63d2\u4ef6<\/h3>\n<p>\u5728\u5168\u5c40\u7684<code>build.gradle<\/code>\u4e2d\u65b0\u589eclasspath<\/p>\n<pre><code>classpath (&#039;com.tencent.tinker:tinker-patch-gradle-plugin:1.9.1&#039;)<\/code><\/pre>\n<h3>tinker\u4f9d\u8d56<\/h3>\n<p>\u5728app\u7684<code>build.gradle<\/code>\u4e2d\u6dfb\u52a0\u4f9d\u8d56<\/p>\n<pre><code class=\"language-java\">dependencies {\n    \/\/tinker\u6838\u5fc3\u5e93\n    implementation &#039;com.tencent.tinker:tinker-android-lib:1.9.1&#039;\n    \/\/\u53ef\u9009\uff0c\u7528\u4e8e\u751f\u6210application\u7c7b\n    annotationProcessor &#039;com.tencent.tinker:tinker-android-anno:1.9.1&#039;\n    compileOnly(&quot;com.tencent.tinker:tinker-android-anno:1.9.1&quot;) {changing = true}\n    \/\/multidex\n    implementation &#039;androidx.multidex:multidex:2.0.1&#039;\n}<\/code><\/pre>\n<h3>\u5bfc\u5165Tinker\u529f\u80fd\u5c01\u88c5\u7c7b\u5e76\u6ce8\u518cService<\/h3>\n<p>\u53c2\u8003\u5b98\u65b9\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/Tencent\/tinker\/tree\/dev\/tinker-sample-android\/app\/src\/main\/java\/tinker\/sample\/android\">https:\/\/github.com\/Tencent\/tinker\/tree\/dev\/tinker-sample-android\/app\/src\/main\/java\/tinker\/sample\/android<\/a><\/p>\n<pre><code class=\"language-xml\">&lt;service android:name=&quot;.service.SampleResultService&quot;\n        android:exported=&quot;false&quot;\/&gt;<\/code><\/pre>\n<h3>\u751f\u6210Application<\/h3>\n<p>\u65b0\u5efaApplicationLike\uff0c\u7ee7\u627f\u81eaDefaultApplication\u3002\u8fd9\u91cc\u662f\u4e3a\u4e86\u81ea\u52a8\u751f\u6210Application<\/p>\n<pre><code class=\"language-java\">\/\/application\u4e3a\u751f\u6210\u7684Application\u7684\u540d\u79f0\u3002flags\u4e3a\u53ef\u4ee5\u66ff\u6362\u7684\u7c7b\u578b\uff0c\u8fd9\u91ccTINKER_ENABLE_ALL\u4e3a\u5168\u90fd\u53ef\u4ee5\u66ff\u6362\uff08dex\uff0c\u8d44\u6e90\u6587\u4ef6\uff0cso\u5e93\uff09\n@DefaultLifeCycle(application = &quot;.TestTinkerApplication&quot;, flags = ShareConstants.TINKER_ENABLE_ALL)\npublic class TestTinkerLike extends DefaultApplicationLike {\n    private static TestTinkerLike mTestTinkerLike;\n    public TestTinkerLike(Application application, int tinkerFlags, boolean tinkerLoadVerifyFlag, long applicationStartElapsedTime, long applicationStartMillisTime, Intent tinkerResultIntent) {\n        super(application, tinkerFlags, tinkerLoadVerifyFlag, applicationStartElapsedTime, applicationStartMillisTime, tinkerResultIntent);\n        mTestTinkerLike=this;\n    }\n\n    \/**\n     * install multiDex before install tinker\n     * so we don&#039;t need to put the tinker lib classes in the main dex\n     *\n     * @param base\n     *\/\n    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)\n    @Override\n    public void onBaseContextAttached(Context base) {\n        super.onBaseContextAttached(base);\n        \/\/you must install multiDex whatever tinker is installed!\n        MultiDex.install(base);\n\n        TinkerManager.fastInstallAll(this);\n    }\n\n    public static TestTinkerLike getmTestTinkerLike(){\n        return mTestTinkerLike;\n    }\n}<\/code><\/pre>\n<h3>\u6ce8\u518cApplication<\/h3>\n<p>\u6ce8\u518cApplication\u4f1a\u62a5\u9519\uff0c\u56e0\u4e3aTestTinkerApplication\u6ca1\u6709\u751f\u6210\uff0cbuild\u4e00\u4e0b\u5373\u53ef<\/p>\n<pre><code class=\"language-xml\">&lt;application\n    android:name=&quot;.TestTinkerApplication&quot;<\/code><\/pre>\n<h2>\u70ed\u66f4\u65b0<\/h2>\n<h3>\u914d\u7f6e\u7b7e\u540d<\/h3>\n<pre><code class=\"language-java\">android {\n\n    \/\/\u7b7e\u540d\u914d\u7f6e\n    signingConfigs {\n        releaseConfig {\n            keyAlias &quot;AppBlog.CN&quot;\n            keyPassword &quot;AppBlog.CN&quot;\n            storeFile file(&quot;..\/keystore\/keystore.jks&quot;)\n            storePassword &quot;AppBlog.CN&quot;\n        }\n    }\n}<\/code><\/pre>\n<h3>\u751f\u6210\u57fa\u7840APK\u5305<\/h3>\n<p>\u751f\u6210\u65b9\u5f0f\uff1a<code>Gradle<\/code> -&gt; <code>app<\/code> -&gt; <code>build<\/code> -&gt; <code>assembleRelease<\/code><\/p>\n<p>\u751f\u6210\u4f4d\u7f6e\u53ef\u4ee5\u81ea\u884c\u914d\u7f6e\uff08\u5728<code>build.gradle<\/code>\u4e2d\u4fee\u6539bakPath\uff09<\/p>\n<h3>\u751f\u6210\u8865\u4e01\u5305<\/h3>\n<p>\u6ce8\u610f\uff1a\u8fd9\u91cc\u751f\u6210\u7684\u8865\u4e01\u5fc5\u987b\u662f\u57fa\u4e8e\u7528\u6237\u5b89\u88c5\u7684\u57fa\u7840APK\u3002\u5047\u5982\u7528\u6237\u5b89\u88c5\u7684\u662fA\u7248\u672c\uff0c\u800c\u4f60\u662f\u57fa\u4e8eB\u7248\u672c\u751f\u6210\u7684\u8865\u4e01\u5305\uff0c\u8fd9\u6837\u662f\u65e0\u6cd5\u5728A\u7248\u672c\u4e0a\u66f4\u65b0\u7684\u3002\u5373\u57fa\u7840APK\u5fc5\u987b\u662f\u7528\u6237\u6b63\u5728\u7528\u7684\u7248\u672c\u3002<\/p>\n<h3>\u5bfc\u5165\u8865\u4e01\u5305<\/h3>\n<p>\u5c06\u8865\u4e01\u5305\u653e\u5230\u624b\u673a\u4e2d\uff0c\u8fd9\u91cc\u6709\u4e00\u70b9\u9700\u8981\u6ce8\u610f\u5c31\u662f\u6743\u9650\u95ee\u9898<\/p>\n<pre><code class=\"language-java\">if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M &amp;&amp; ActivityCompat.checkSelfPermission(MainActivity.this, \n        Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {\n    ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);\n} else {\n    TinkerInstaller.onReceiveUpgradePatch(getApplicationContext(), Environment.getExternalStorageDirectory().getAbsolutePath() + &quot;\/patch_signed_7zip.apk&quot;);\n}<\/code><\/pre>\n<h3>\u52a0\u8f7dso\u5e93\u7684\u51e0\u79cd\u65b9\u5f0f<\/h3>\n<ul>\n<li>Hack\u65b9\u5f0f\uff08\u6210\u529f\u7387\u6700\u5927\u7684\u65b9\u5f0f\uff09<\/li>\n<\/ul>\n<pre><code class=\"language-java\">String CPU_ABI = android.os.Build.CPU_ABI;\n\/\/ \u5c06tinker library\u4e2d\u7684 CPU_ABI\u67b6\u6784\u7684so \u6ce8\u518c\u5230\u7cfb\u7edf\u7684library path\u4e2d\u3002\nTinkerLoadLibrary.installNavitveLibraryABI(MainActivity.this, CPU_ABI);<\/code><\/pre>\n<ul>\n<li>\u975eHack\u65b9\u5f0f<\/li>\n<\/ul>\n<pre><code class=\"language-java\">String CPU_ABI = android.os.Build.CPU_ABI;\nboolean a=TinkerLoadLibrary.loadLibraryFromTinker(getApplicationContext(), &quot;lib\/&quot; + CPU_ABI, &quot;native-lib&quot;);<\/code><\/pre>\n<ul>\n<li>Arm\u65b9\u5f0f<\/li>\n<\/ul>\n<pre><code class=\"language-java\">TinkerLoadLibrary.loadArmLibrary(getApplicationContext(), &quot;native-lib&quot;);<\/code><\/pre>\n<ul>\n<li>Arm-V7a\u65b9\u5f0f<\/li>\n<\/ul>\n<pre><code class=\"language-java\">TinkerApplicationHelper.loadArmV7aLibrary(TestTinkerLike.getmTestTinkerLike(), &quot;native-lib&quot;);<\/code><\/pre>\n<p>\u6ce8\u610f\uff1a\u8fd9\u91cc\u6709\u4e24\u4e2a\u7c7b\u53ef\u4ee5\u52a0\u8f7dSo\u6587\u4ef6\uff0c<code>TinkerLoadLibrary<\/code>\u548c<code>TinkerApplicationHelper<\/code>\uff0c\u4e0d\u8fc7\u5176\u539f\u7406\u662f\u4e00\u6837\u7684<\/p>\n<blockquote>\n<p>\u7279\u522b\u6ce8\u610f\uff1aso\u6587\u4ef6\u662f\u6253\u8865\u4e01\u7684\u65f6\u5019\u81ea\u52a8\u52a0\u8f7d\u7684\uff0c\u4f46\u662f\u5374\u9700\u8981\u624b\u52a8\u7684\u94fe\u4e00\u4e0b\uff0c\u76f8\u5f53\u4e8e\uff0c\u57fa\u7840apk\u672c\u8eab\u7684so\u6587\u4ef6A\u3002\u5728\u6253\u8865\u4e01\u7684\u65f6\u5019\u52a0\u8f7d\u4e86so\u6587\u4ef6B\u3002\u6b64\u65f6\u6709\u4e24\u4e2aso\u6587\u4ef6\u3002\u4f60\u6bcf\u6b21\u90fd\u8981\u624b\u52a8\u7684\u7528\u4e0a\u9762\u7684\u65b9\u6cd5\u52a0\u8f7dso\u5e93B\u3002\u5426\u5219\u9ed8\u8ba4\u8c03\u7528\u7684\u8fd8\u662f\u57fa\u7840APK\u7684so\u6587\u4ef6A\u4e2d\u7684\u65b9\u6cd5\u3002\u4e00\u65e6\u5728\u52a0\u8f7dso\u5e93\u524d\uff0c\u8c03\u7528\u4e86A\u4e2d\u7684\u65b9\u6cd5\uff0c\u9ed8\u8ba4\u52a0\u8f7d\u7684\u662fso\u5e93A\u3002\u6b64\u65f6\u8981\u662f\u8c03\u7528so\u5e93B\u4e2d\u65b0\u589e\u7684\u65b9\u6cd5\uff08so\u5e93B\u4e2d\u6709\uff0c\u4f46\u662fso\u5e93A\u4e2d\u6ca1\u6709\u7684\u65b9\u6cd5\uff09\uff0c\u5c31\u4f1a\u62a5\u9519\u3002<\/p>\n<\/blockquote>\n<ul>\n<li>MainActivity.java<\/li>\n<\/ul>\n<pre><code class=\"language-java\">public class MainActivity extends AppCompatActivity {\n    private Button installBtn;\n    private Button unInstallBtn;\n    private Button infoBtn;\n    private Button hackBtn;\n    private Button nohackBtn;\n    private Button armeabiBtn;\n    private Button v7aBtn;\n\n    \/\/ Used to load the &#039;native-lib&#039; library on application startup.\n    static {\n        System.loadLibrary(&quot;native-lib&quot;);\n    }\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n\n        installBtn = findViewById(R.id.btn_load_install);\n        unInstallBtn = findViewById(R.id.btn_load_unInstall);\n        mImg = findViewById(R.id.iv_main_test);\n        hackBtn = findViewById(R.id.btn_load_hack);\n        nohackBtn = findViewById(R.id.btn_load_nohack);\n        armeabiBtn = findViewById(R.id.btn_load_armeabi);\n        v7aBtn = findViewById(R.id.btn_load_armeabiv7a);\n        infoBtn = findViewById(R.id.btn_load_info);\n\n        installBtn.setOnClickListener(new View.OnClickListener() {\n            @Override\n            public void onClick(View v) {\n                if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M &amp;&amp; ActivityCompat.checkSelfPermission(MainActivity.this, \n                        Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {\n                    ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);\n                } else {\n                    TinkerInstaller.onReceiveUpgradePatch(getApplicationContext(), Environment.getExternalStorageDirectory().getAbsolutePath() + &quot;\/patch_signed_7zip.apk&quot;);\n                }\n                Toast.makeText(MainActivity.this, &quot;\u5b89\u88c5\u8865\u4e01&quot;, Toast.LENGTH_SHORT).show();\n            }\n        });\n\n        unInstallBtn.setOnClickListener(new View.OnClickListener() {\n            @Override\n            public void onClick(View v) {\n                TinkerInstaller.cleanPatch(MainActivity.this);\n                Toast.makeText(MainActivity.this, &quot;\u5378\u8f7d\u8865\u4e01&quot;, Toast.LENGTH_SHORT).show();\n            }\n        });\n\n        infoBtn.setOnClickListener(new View.OnClickListener() {\n            @Override\n            public void onClick(View v) {\n                Toast.makeText(MainActivity.this, getInfo(),Toast.LENGTH_SHORT).show();\n            }\n        });\n\n        hackBtn.setOnClickListener(new View.OnClickListener() {\n            @Override\n            public void onClick(View v) {\n                String CPU_ABI = android.os.Build.CPU_ABI;\n                \/\/ \u5c06tinker library\u4e2d\u7684 CPU_ABI\u67b6\u6784\u7684so \u6ce8\u518c\u5230\u7cfb\u7edf\u7684library path\u4e2d\u3002\n                TinkerLoadLibrary.installNavitveLibraryABI(MainActivity.this, CPU_ABI);\n            }\n        });\n\n        nohackBtn.setOnClickListener(new View.OnClickListener() {\n            @Override\n            public void onClick(View v) {\n                String CPU_ABI = android.os.Build.CPU_ABI;\n                boolean a = TinkerLoadLibrary.loadLibraryFromTinker(getApplicationContext(), &quot;lib\/&quot; + CPU_ABI, &quot;native-lib&quot;);\n                Toast.makeText(MainActivity.this, &quot;so\u5e93\u5b89\u88c5\uff1a&quot; + a, Toast.LENGTH_SHORT).show();\n            }\n        });\n\n        armeabiBtn.setOnClickListener(new View.OnClickListener() {\n            @Override\n            public void onClick(View v) {\n                TinkerLoadLibrary.loadArmLibrary(getApplicationContext(), &quot;native-lib&quot;);\n            }\n        });\n\n        v7aBtn.setOnClickListener(new View.OnClickListener() {\n            @Override\n            public void onClick(View v) {\n                TinkerApplicationHelper.loadArmV7aLibrary(TestTinkerLike.getmTestTinkerLike(), &quot;native-lib&quot;);\n            }\n        });\n    }\n\n    \/**\n     * A native method that is implemented by the &#039;native-lib&#039; native library,\n     * which is packaged with this application.\n     *\/\n    public native String getInfo();\n}<\/code><\/pre>\n<ul>\n<li>native-lib.cpp<\/li>\n<\/ul>\n<pre><code class=\"language-c\">#include &lt;jni.h&gt;\n#include &lt;string&gt;\n\nextern &quot;C&quot;\nJNIEXPORT jstring JNICALL\nJava_cn_appblog_tinker_MainActivity_getInfo(JNIEnv *env, jobject instance) {\n    std::string hello = &quot;AppBlog.CN&quot;;\n    return env-&gt;NewStringUTF(hello.c_str());\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u7531\u4e8e\u516c\u53f8\u9700\u8981\uff0c\u5165\u5751Tinker\uff0c\u7ed3\u679c\u53d1\u73b0dex\u4ee5\u53ca\u8d44\u6e90\u6587\u4ef6\uff0c\u53ef\u4ee5\u66ff\u6362\u3002\u800cSo\u6587\u4ef6\uff0cLog\u65e5\u5fd7\u63d0\u793a\u66ff\u6362\u6210\u529f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[311],"tags":[465],"class_list":["post-1863","post","type-post","status-publish","format-standard","hentry","category-android-advance","tag-tinker"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1863"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1863\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}