{"id":18034,"date":"2024-03-11T15:08:26","date_gmt":"2024-03-11T07:08:26","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=18034"},"modified":"2024-03-11T15:08:26","modified_gmt":"2024-03-11T07:08:26","slug":"androlua%e5%b0%81%e8%a3%85apk%e6%93%8d%e4%bd%9c%e5%8a%9e%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/18034\/","title":{"rendered":"androlua\u5c01\u88c5apk\u64cd\u4f5c\u529e\u6cd5"},"content":{"rendered":"

AndroLua\u662f\u4e00\u79cd\u57fa\u4e8eLua\u8bed\u8a00\u7684Android\u5f00\u53d1\u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u5c06Lua\u811a\u672c\u5c01\u88c5\u6210APK\u6587\u4ef6\uff0c\u4f7f\u5f97\u5f00\u53d1\u8005\u53ef\u4ee5\u66f4\u52a0\u65b9\u4fbf\u5730\u4f7f\u7528Lua\u8bed\u8a00\u8fdb\u884cAndroid\u5e94\u7528\u7684\u5f00\u53d1\u3002\u672c\u6587\u5c06\u4ecb\u7ecdAndroLua\u5c01\u88c5APK\u7684\u539f\u7406\u548c\u8be6\u7ec6\u6b65\u9aa4\u3002<\/p>\n

\u4e00\u3001AndroLua\u5c01\u88c5APK\u7684\u539f\u7406<\/p>\n

AndroLua\u5c06Lua\u811a\u672c\u5c01\u88c5\u6210APK\u7684\u539f\u7406\u662f\u901a\u8fc7\u5c06Lua\u811a\u672c\u548c\u76f8\u5173\u7684\u8d44\u6e90\u6587\u4ef6\u6253\u5305\u6210\u4e00\u4e2aAPK\u6587\u4ef6\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e2aJava\u7684\u5165\u53e3\u7c7b\u6765\u542f\u52a8Lua\u811a\u672c\u3002\u5728\u8fd0\u884c\u65f6\uff0cAndroid\u7cfb\u7edf\u4f1a\u52a0\u8f7dAPK\u6587\u4ef6\uff0c\u5e76\u6839\u636e\u5165\u53e3\u7c7b\u7684\u6307\u793a\u542f\u52a8Lua\u811a\u672c\uff0c\u5e76\u5c06Lua\u811a\u672c\u4e0eAndroid\u7cfb\u7edf\u8fdb\u884c\u4ea4\u4e92\u3002<\/p>\n

\u5177\u4f53\u6765\u8bf4\uff0cAndroLua\u5c01\u88c5APK\u7684\u8fc7\u7a0b\u5305\u62ec\u4ee5\u6253\u5305apk\u5b89\u88c5\u5305<\/a>\u4e0b\u6b65\u9aa4\uff1a<\/p>\n

1. \u521b\u5efa\u4e00\u4e2aAndroid\u5de5\u7a0b\uff0c\u5e76\u6dfb\u52a0AndroLua\u6846\u67b6\u7684\u76f8\u5173\u4f9d\u8d56\u5e93\uff1b<\/p>\n

2. \u5c06Lua\u811a\u672c\u548c\u76f8\u5173\u7684\u8d44\u6e90\u6587\u4ef6\u653e\u7f6e\u5728\u5de5\u7a0b\u76ee\u5f55\u4e0b\u7684\u6307\u5b9a\u4f4d\u7f6e\uff1b<\/p>\n

3. \u5728\u5165\u53e3\u7c7b\u4e2d\u52a0\u8f7dLua\u811a\u672c\uff0c\u5e76\u6267\u884c\u76f8\u5e94\u7684Lua\u51fd\u6570\uff1b<\/p>\n

4. \u5c06APK\u6587\u4ef6\u6253\u5305\u5e76\u5728Android\u8bbe\u5907\u4e0a\u5b89\u88c5\u8fd0\u884c\u3002<\/p>\n

\u4e8c\u3001AndroLua\u5c01\u88c5APK\u7684\u8be6\u7ec6\u6b65\u9aa4<\/p>\n

\u4ee5\u4e0b\u662f\u4f7f\u7528AndroLua\u5c01\u88c5APK\u7684\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n

1. \u521b\u5efa\u4e00\u4e2aAndroid\u5de5\u7a0b<\/p>\n

\u4f7f\u7528Android Studio\u6216\u5176\u4ed6\u7684\u5f00\u53d1\u5de5\u5177\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Android\u5de5\u7a0b\u3002<\/p>\n

2. \u6dfb\u52a0AndroLua\u6846\u67b6\u4f9d\u8d56\u5e93<\/p>\n

\u5728\u5de5\u7a0b\u7684build.gradle\u6587\u4ef6\u4e2d\u6dfb\u52a0AndroLua\u6846\u67b6\u7684\u4f9d\u8d56\u5e93\uff0c\u4f8b\u5982\uff1a<\/p>\n

“`<\/p>\n

dependencies {<\/p>\n

implementation ‘com.androlua:androlua:x.x.x’<\/p>\n

}<\/p>\n

“`<\/p>\n

3. \u5c06Lua\u811a\u672c\u548c\u76f8\u5173\u8d44\u6e90\u6587\u4ef6\u653e\u7f6e\u5728\u5de5\u7a0b\u76ee\u5f55<\/p>\n

\u5c06Lua<\/p>\n

<\/figure>\n<\/p>\n

\u811a\u672c\u6587\u4ef6\uff08\u901a\u5e38\u5177\u6709.lua\u6269\u5c55\u540d\uff09\u548c\u76f8\u5173\u7684\u8d44\u6e90\u6587\u4ef6\uff08\u5982\u56fe\u7247\u3001\u5e03\u5c40\u6587\u4ef6\u7b49\uff09\u653e\u7f6e\u5728\u5de5\u7a0b\u76ee\u5f55\u7684assets\u76ee\u5f55\u4e0b\u6216\u5176\u4ed6\u6307\u5b9a\u7684\u4f4d\u7f6e\u3002<\/p>\n

4. \u521b\u5efa\u5165\u53e3\u7c7b<\/p>\n

\u521b\u5efa\u4e00\u4e2aJava\u7c7b\u4f5c\u4e3a\u5165\u53e3\u7c7b\uff0c\u8be5\u7c7b\u5c06\u88ab\u7528\u4e8e\u52a0\u8f7dLua\u811a\u672c\u5e76\u6267\u884c\u76f8\u5e94\u7684\u51fd\u6570\u3002<\/p>\n

“`java<\/p>\n

public class EntryPointActivity extends Activity {<\/p>\n

private LuaContext mLuaContext;<\/p>\n<\/p>\n

@Override<\/p>\n

protected void onCreate(Bundle savedInstanceState) {<\/p>\n

super.onCreate(savedInstanceState);<\/p>\n

setContentView(R.layout.activity_main);<\/p>\n

mLuaContext = LuaContext.create(getApplicationContext());<\/p>\n

\/\/ \u52a0\u8f7dLua\u811a\u672c<\/p>\n

String luaScriptPath = “main.lua”;<\/p>\n

mLuaContext.getLuaState().doFile(luaScriptPath);<\/p>\n<\/p>\n

\/\/ \u6267\u884cLua\u51fd\u6570<\/p>\n

mLuaContext.callLuaFunction(“onCreate”, savedInstanceState);<\/p>\n

}<\/p>\n

}<\/p>\n

“`<\/p>\n

5. \u6253\u5305APK\u5e76\u5b89\u88c5\u8fd0\u884c<\/p>\n

\u4f7f\u7528Android\u5f00\u53d1\u5de5\u5177\u5c06\u5de5\u7a0b\u6253\u5305\u6210APK\u6587\u4ef6\uff0c\u5e76\u5c06APK\u6587\u4ef6\u5b89\u88c5\u5230Android\u8bbe\u5907\u4e0a\u3002<\/p>\n

\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u5c31\u53ef\u4ee5\u5c06Lua\u811a\u672c\u5c01\u88c5\u6210APK\u6587\u4ef6\uff0c\u5e76\u5728Android\u8bbe\u5907\u4e0a\u8fd0\u884c\u3002<\/p>\n

\u603b\u7ed3\uff1a<\/p>\n

AndroLua\u662f\u4e00\u79cd\u57fa\u4e8eLua\u8bed\u8a00\u7684Android\u5f00\u53d1\u6846\u67b6\uff0c\u901a\u8fc7\u5c06Lua\u811a\u672c\u548c\u76f8\u5173\u8d44\u6e90\u6587\u4ef6\u5c01\u88c5\u6210APK\u6587\u4ef6\uff0c\u4f7f\u5f97\u5f00\u53d1\u8005\u53ef\u4ee5\u66f4\u52a0\u65b9\u4fbf\u5730\u4f7f\u7528Lua\u8bed\u8a00\u8fdb\u884cAndroid\u5e94\u7528\u7684\u5f00\u53d1\u3002\u4f7f\u7528Aautojs\u6253\u5305apk \u65e0\u54cd\u5e94<\/a>ndroLua\u5c01\u88c5APK\u7684\u6b65\u9aa4\u5305\u62ec\u521b\u5efaAndroid\u5de5\u7a0b\u3001\u6dfb\u52a0AndroLua\u6846\u67b6\u4f9d\u8d56\u5e93\u3001\u5c06Lua\u811a\u672c\u548c\u8d44\u6e90\u6587\u4ef6\u653e\u7f6e\u5230\u5de5\u7a0b\u4e2d\u3001\u521b\u5efa\u5165\u53e3\u7c7b\u4ee5\u53ca\u6253\u5305APK\u5e76\u5b89\u88c5\u8fd0\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

AndroLua\u662f\u4e00\u79cd\u57fa\u4e8eLua\u8bed\u8a00\u7684Android\u5f00\u53d1\u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u5c06Lua\u811a\u672c\u5c01\u88c5\u6210APK\u6587\u4ef6\uff0c\u4f7f\u5f97\u5f00\u53d1\u8005\u53ef\u4ee5\u66f4\u52a0\u65b9\u4fbf\u5730\u4f7f\u7528Lua\u8bed\u8a00\u8fdb\u884cAndroid\u5e94\u7528\u7684\u5f00\u53d1\u3002\u672c\u6587\u5c06\u4ecb\u7ecdAndroLua\u5c01\u88c5A<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[20886,20887,3275,16,408],"topic":[],"class_list":["post-18034","post","type-post","status-publish","format-standard","hentry","category-appkf","tag-apk","tag-pythonapk","tag-3275","tag-16","tag-408"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/18034","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=18034"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/18034\/revisions"}],"predecessor-version":[{"id":18072,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/18034\/revisions\/18072"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=18034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=18034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=18034"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=18034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}