{"id":53454,"date":"2024-04-16T17:49:22","date_gmt":"2024-04-16T09:49:22","guid":{"rendered":"https:\/\/www.yimenapp.com\/kb-yimen\/?p=53454"},"modified":"2024-04-16T17:49:22","modified_gmt":"2024-04-16T09:49:22","slug":"ndk%e6%89%93%e5%8c%85apk%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e7%9a%84","status":"publish","type":"post","link":"https:\/\/www.yimenapp.com\/kb-yimen\/53454\/","title":{"rendered":"ndk\u6253\u5305apk\u5982\u4f55\u5b9e\u73b0\u7684?"},"content":{"rendered":"<p>NDK\uff08Native Development Kit\uff09\u662fAndroid SDK\u7684\u4e00\u90e8\u5206\uff0c\u5b83\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u4f7f\u7528C\u6216C++\u7b49\u672c\u5730\u8bed\u8a00\u7f16\u5199<span class=\"wpcom_tag_link\"><a href=\"https:\/\/www.yimenapp.com\/kb-yimen\/tag\/%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f\/\" title=\"\u5e94\u7528\u7a0b\u5e8f\" target=\"_blank\">\u5e94\u7528\u7a0b\u5e8f<\/a><\/span>\u7684\u4e00\u5957\u5de5\u5177\u3002NDK\u53ef\u4ee5\u5c06\u672c\u5730\u5e93\u6253\u5305\u5230APK\u4e2d\uff0c\u4ee5\u4fbf\u5728\u8bbe\u5907\u4e0a\u8fd0\u884c\u65f6\u4f7f\u7528\u3002\u672c\u6587\u5c06\u4ecb\u7ecdNDK\u6253\u5305APK\u7684\u539f\u7406\u548c\u8be6\u7ec6\u6b65\u9aa4\u3002<\/p>\n<p>\u4e00\u3001NDK\u6253\u5305APK\u7684\u539f\u7406<\/p>\n<p>NDK\u6253\u5305APK\u7684\u539f\u7406\u662f\u5c06\u672c\u5730\u5e93<span class=\"wpcom_tag_link\"><a href=\"https:\/\/www.yimenapp.com\/kb-yimen\/tag\/%e6%96%87%e4%bb%b6\/\" title=\"\u6587\u4ef6\" target=\"_blank\">\u6587\u4ef6<\/a><\/span>\u6253\u5305\u5230APK\u4e2d\uff0c\u4ee5\u4fbf\u5728\u8bbe\u5907\u4e0a\u8fd0\u884c\u65f6\u4f7f\u7528\u3002\u672c\u5730\u5e93\u662f\u4e00\u79cd\u53ef\u4ee5\u5728Android NDK\u73af\u5883\u4e0b\u7f16\u8bd1\u7684\u52a8\u6001\u94fe\u63a5\u5e93\uff08.so\u6587\u4ef6\uff09\uff0c\u5b83\u53ef\u4ee5\u7528C\u6216C++\u7b49\u672c\u5730\u8bed\u8a00\u7f16\u5199\u3002\u5f53\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u4f7f\u7528\u672c\u5730\u5e93\u65f6\uff0c\u5b83\u4f1a\u4eceAPK\u4e2d\u63d0\u53d6\u672c\u5730\u5e93\u5e76\u5c06\u5176\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u4ee5\u4fbf\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u3002<\/p>\n<p>\u4e8c\u3001NDK\u6253\u5305APK\u7684\u6b65\u9aa4<\/p>\n<p>1. \u5b89\u88c5NDK<\/p>\n<p>\u9996\u5148\uff0c\u9700\u8981\u5b89\u88c5NDK\u3002\u53ef\u4ee5\u4eceAndroid Studio\u7684SDK\u7ba1\u7406\u5668\u4e2d\u4e0b\u8f7d\u548c\u5b89\u88c5NDK\u3002\u8981\u786e\u4fdd\u5b89\u88c5\u4e86\u4e0eAndroid Studio\u4e2d\u4f7f\u7528\u7684Gradle\u7248\u672c\u76f8\u5bf9\u5e94\u7684NDK\u7248\u672c\u3002<\/p>\n<p>2. \u914d\u7f6ebuild.gradle\u6587\u4ef6<\/p>\n<p>\u5728\u5e94\u7528\u7a0b\u5e8f\u7684build.gradle\u6587\u4ef6\u4e2d\uff0c\u9700\u8981\u6dfb\u52a0\u4ee5\u4e0b<span class=\"wpcom_tag_link\"><a href=\"https:\/\/www.yimenapp.com\/kb-yimen\/tag\/%e4%bb%a3%e7%a0%81\/\" title=\"\u4ee3\u7801\" target=\"_blank\">\u4ee3\u7801<\/a><\/span>\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>android {<\/p>\n<p>    &#8230;<\/p>\n<p>    defaultConfig {<\/p>\n<p>        &#8230;<\/p>\n<p>        ndk {<\/p>\n<p>            moduleName &#8220;native_lib&#8221;<\/p>\n<p>        }<\/p>\n<p>    }<\/p>\n<p>    &#8230;<\/p>\n<p>    sourceSets.main {<\/p>\n<p>        jni.srcDirs = [&#8216;src\/main\/jni&#8217;]<\/p>\n<p>        jniLibs.srcDirs = [&#8216;src\/main\/libs&#8217;]<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>\u8fd9\u4e2a\u4ee3\u7801\u5757\u544a\u8bc9Gradle\u5728\u6784\u5efaAPK\u65f6\u4f7f\u7528NDK\uff0c\u5e76\u5c06\u672c\u5730\u5e93\u6253\u5305\u5230APK\u4e2d\u3002moduleName\u6307\u5b9a\u672c\u5730\u5e93\u7684\u540d\u79f0\uff0cjni.srcDirs\u6307\u5b9a\u672c\u5730\u5e93\u6587\u4ef6\u7684\u4f4d\u7f6e\uff0cjniLibs.srcDirs\u6307\u5b9a\u672c\u5730\u5e93\u4f9d\u8d56\u7684\u7b2c\u4e09\u65b9\u5e93\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>3. \u521b\u5efa\u672c\u5730\u5e93<\/p>\n<p>\u521b\u5efa\u672c\u5730\u5e93\u9700\u8981\u5728\u9879\u76ee\u4e2d\u521b\u5efa\u4e00\u4e2ajni\u76ee\u5f55\u3002\u5728jni\u76ee\u5f55\u4e0b\uff0c\u521b\u5efa\u4e00\u4e2aC\u6216C++\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u547d\u540d\u4e3anative_lib.c\u6216native_lib.cpp\u3002<\/p>\n<p>4. \u7f16\u5199C\u6216C++\u4ee3\u7801<\/p>\n<p><a href=\"https:\/\/appdabao.yimenapp.com\/jiage-710.html\">\u624b\u673aapp\u6253\u5305\u5236\u4f5c<\/a><\/p>\n<p>\u5728native_lib.c\u6216native_lib.cpp\u6587\u4ef6\u4e2d\uff0c\u7f16\u5199C\u6216C++\u4ee3<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.yimenyun.net\/2023-03\/22\/10\/19268579606.jpg\" \/><\/figure><\/p>\n<p>\u7801\u3002\u7f16\u5199\u7684\u4ee3\u7801\u9700\u8981\u4f7f\u7528NDK\u63d0\u4f9b\u7684\u5934\u6587\u4ef6\u548c\u5e93\u6587\u4ef6\u3002<\/p>\n<p>5. \u7f16\u5199Andro<a href=\"https:\/\/appdabao.yimenapp.com\/jiage-1795.html\">app\u6253\u5305\u7b7e\u8bc1<\/a>id.mk\u6587\u4ef6<\/p>\n<p>\u5728jni\u76ee\u5f55\u4e0b\uff0c\u521b\u5efa\u4e00\u4e2aAndroid.mk\u6587\u4ef6\u3002Android.mk\u6587\u4ef6\u662f\u4e00\u4e2aMakefile\u683c\u5f0f\u7684\u6587\u4ef6\uff0c\u5b83\u7528\u4e8e\u63cf\u8ff0\u672c\u5730\u5e93\u7684\u7f16\u8bd1\u548c\u94fe\u63a5\u89c4\u5219\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2aAndroid.mk\u6587\u4ef6\u7684\u793a\u4f8b\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>LOCAL_PATH := $(call my-dir)<\/p>\n<p>include $(CLEAR_VARS)<\/p>\n<p>LOCAL_MODULE    := native_lib<\/p>\n<p>LOCAL_SRC_FILES := native_lib.c<\/p>\n<p>include $(BUILD_SHARED_LIBRARY)<\/p>\n<p>&#8220;`<\/p>\n<p>6. \u7f16\u8bd1\u672c\u5730\u5e93<\/p>\n<p>\u4f7f\u7528NDK\u63d0\u4f9b\u7684ndk-build\u547d\u4ee4\u7f16\u8bd1\u672c\u5730\u5e93\u3002\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u6253\u5f00\u7ec8\u7aef\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>$ .\/gradlew clean<\/p>\n<p>$ .\/gradlew assembleDebug<\/p>\n<p>&#8220;`<\/p>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u5c06\u7f16\u8bd1\u672c\u5730\u5e93\uff0c\u5e76\u5c06\u5176\u6253\u5305\u5230APK\u4e2d\u3002<\/p>\n<p>7. \u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f<\/p>\n<p>\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e94\u7528\u7a0b\u5e8f\u5c06\u4eceAPK\u4e2d\u63d0\u53d6\u672c\u5730\u5e93\u5e76\u5c06\u5176\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u4ee5\u4fbf\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u3002<\/p>\n<p>\u603b\u7ed3<\/p>\n<p>NDK\u6253\u5305APK\u662f\u4e00\u79cd\u5c06\u672c\u5730\u5e93\u6253\u5305\u5230APK\u4e2d\u7684\u65b9\u6cd5\uff0c\u4ee5\u4fbf\u5728\u8bbe\u5907\u4e0a\u8fd0\u884c\u65f6\u4f7f\u7528\u3002\u5b83\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u4f7f\u7528C\u6216C++\u7b49\u672c\u5730\u8bed\u8a00\u7f16\u5199\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u672c\u5730\u5e93\u3002NDK\u6253\u5305APK\u7684\u6b65\u9aa4\u5305\u62ec\u5b89\u88c5NDK\u3001\u914d\u7f6ebuild.gradle\u6587\u4ef6\u3001\u521b\u5efa\u672c\u5730\u5e93\u3001\u7f16\u5199C\u6216C++\u4ee3\u7801\u3001\u7f16\u5199Android.mk\u6587\u4ef6\u3001\u7f16\u8bd1\u672c\u5730\u5e93\u548c\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>NDK\uff08Native Development Kit\uff09\u662fAndroid SDK\u7684\u4e00\u90e8\u5206\uff0c\u5b83\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u4f7f\u7528C\u6216C++\u7b49\u672c\u5730\u8bed\u8a00\u7f16\u5199\u5e94\u7528\u7a0b\u5e8f\u7684\u4e00\u5957\u5de5\u5177\u3002NDK\u53ef\u4ee5\u5c06\u672c\u5730\u5e93\u6253\u5305\u5230APK\u4e2d\uff0c\u4ee5\u4fbf\u5728\u8bbe\u5907\u4e0a\u8fd0<\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[94],"tags":[41843,1870,33445,2445,2708],"special":[],"attr":[],"class_list":["post-53454","post","type-post","status-publish","format-standard","hentry","category-appjc","tag-ipa","tag-1870","tag-app","tag-2445","tag-2708","entry"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts\/53454","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/comments?post=53454"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts\/53454\/revisions"}],"predecessor-version":[{"id":53655,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts\/53454\/revisions\/53655"}],"wp:attachment":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/media?parent=53454"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/categories?post=53454"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/tags?post=53454"},{"taxonomy":"special","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/special?post=53454"},{"taxonomy":"attr","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/attr?post=53454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}