android Studio 配置LUA 开发环境

android Studio 配置 LUA 开发环境

关于Android LUA资料

android如何调用lua?
Android lua 教程
Lua官网
lua语言解释
Lua 5.1 参考手册
Android Lua热修复

  1. 引诉大牛的原话:

Android 调用 Lua /Lua 调用 Android 代码

在Android项目中使用Lua,需要两个步骤:

1、加载Lua脚本解析引擎。
2、以Native API方式调用引擎接口

直接以JNI方式调用Lua解析引擎的接口十分麻烦,开源项目
LuaJava)对这些JNI接口进行了很好的封装,它是一个包含了LuaJava的Android平台的Lua解析器,它提供一系列映射到Lua C实现函数的Java接口。

1.获取LuaJava 工程,引入到你的Android Studio中,并将其设为Library工程

2.将Lua解析器相关的C代码和 LuaJava的C代码打包成so文件

一. 将androLua 以moudle方式引入到Android studio 的Project工作区中

此时需要保证你的Android studio 的NDK开发环境已经配置完成,关于如何配置NDK,教程请移步MAC NDK环境配置

二. 修改自动生成的androLua 的build.gradle文件配置如下 主要将 apply plugin: ‘com.android.application’ 替换为 apply plugin: ‘com.android.library’
屏幕快照 2015-12-25 上午12.15.20这里写图片描述

如果编译 报错:请修改jni/luajava/luajava.c文件 :将导入头文件的路径修改如下

    #include <jni.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include "../lua/lua.h"
    #include "../lua/lualib.h"
    #include "../lua/lauxlib.h"
    #include "../lua/lstate.h"
    #include "../lua/lauxlib.h"
    #include "../lua/lualib.h"

为了照顾全平台的兼容性建议在jni目录下新建Application.mk文件 写入内容为:

APP_ABI := all

三.我的版本下我需要将 androLua的AndroidMainfest文件的

    <?xml version="1.0" encoding="utf-8"?>
<manifest android:versionCode="1" android:versionName="1.0" package="sk.kottman.androlua" xmlns:android="http://schemas.android.com/apk/res/android">
  <uses-sdk android:minSdkVersion="4" />
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
  <uses-permission android:name="android.permission.BLUETOOTH"/>
  <uses-permission android:name="android.permission.CAMERA"/>
  <uses-permission android:name="android.permission.VIBRATE"/>
  <uses-permission android:name="android.permission.READ_SMS"/>
  //屏蔽掉入口,只作为lib引入
  <!--<application android:icon="@drawable/icon" android:label="@string/app_name">-->
    <!--<activity android:label="@string/app_name" android:name=".Main">-->
      <!--<intent-filter>-->
        <!--<action android:name="android.intent.action.MAIN"/>-->
        <!--<category android:name="android.intent.category.LAUNCHER"/>-->
      <!--</intent-filter>-->
    <!--</activity>-->
  <!--</application>-->
</manifest>

四. 在你的App的模块的引入处修改你的build.gradle文件
主要是增加 : compile project(‘:androLua’)

    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile project(':androLua')
}

不要急着编译 ,检查一下你的工程的build.gradle
五:使用com.android.tools.build:gradle:1.3.1

我本来是用2.0.3支持Android studio 的Fast RUN功能 ,当时编译这个Lua一直无法通过 ,如果你也遇到这种问题,请将插件版本换为1.3.1

六. 基本上配置已经完成了:
试着在你的项目中引入LuaState吧。
七:Android studio 的NDK编译生成的.so文件目录路径为:app/build/intermediates/ndk

原文地址:https://www.cnblogs.com/allencoder/p/5327199.html