Getting Started
You may try things first with an interactive console.
Getting It
TIP
Go to Initializer to get the required dependencies for your build system.
The library consists of two parts:
- The Java interface
- The compiled native binaries
So you will need both to get LuaJava to work correctly. Basically, using Maven Central:
- The
groupId
isparty.iroiro.luajava
. - The Java interface is
party.iroiro.luajava:luajava
. - The Lua specific bridging artifacts are
lua5N
(lua51
lua52
...) orluajit
orluaj
. - The natives has
artifactId
likelua5N-platform
(lua51
lua52
...) orluajit-platform
. (No need for LuaJ.) - LuaJ bindings need the JitPack repository.
However, there are different native artifacts for different platforms, each with a different classifier
:
- For desktop platforms, including Linux, Windows and macOS, on x64 or x32 or ARM(32/64), we provide an integrated artifact with classifier
natives-desktop
. - For mobile devices:
- iOS: An artifact with classifier
natives-ios
. - Android: Since there are different architectures for Android, you can choose from the following four according to your target devices. (I recommend you to just include all the four though.)
- Artifact with classifier
natives-armeabi-v7a
. - Artifact with classifier
natives-arm64-v8a
. - Artifact with classifier
natives-x86
. - Artifact with classifier
natives-x86_64
.
- Artifact with classifier
- iOS: An artifact with classifier
Initializer
You may get the required dependencies for your build system using the following simple form.
For mobile platforms, e.g. iOS and Android, you might need some more configuration to get things work.
implementation 'party.iroiro.luajava:luajava:4.0.2'
implementation 'party.iroiro.luajava:lua51:4.0.2'
runtimeOnly 'party.iroiro.luajava:lua51-platform:4.0.2:natives-desktop'
iOS
(Work in progress.)
Android
You can choose between the following two configurations. The former one uses a pre-bundled AAR archive while the latter might give a little more flexibility.
For LuaJ bindings, you don't need a binary artifact. However, the LuaJ library uses some Java 8 API unsupported by older Android API levels, and you might need to configure Android Java 8+ API Desugaring in your application.
Using bundled AAR files
The AAR archive bundles native binaries for armeabi-v7a
arm64-v8a
x86
and x86_64
.
ext {
// You may replace `luajit` with `lua51` or other Lua versions
lua = 'luajit'
luaJavaVersion = '4.0.2'
}
dependencies {
// other dependencies
implementation "party.iroiro.luajava:${lua}:${luaJavaVersion}"
runtimeOnly "party.iroiro.luajava:android:${luaJavaVersion}:${lua}@aar"
}
2
3
4
5
6
7
8
9
10
11
Using a really lengthy configuration
android {
// other configurations
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
}
ext {
// You may replace `lua51` with `luajit` or other Lua versions
lua = 'lua51'
luajavaVersion = '4.0.2'
}
configurations { natives }
dependencies {
// other dependencies
implementation "party.iroiro.luajava:luajava:${luajavaVersion}"
implementation "party.iroiro.luajava:${lua}:${luajavaVersion}"
natives "party.iroiro.luajava:${lua}-platform:${luajavaVersion}:natives-armeabi-v7a"
natives "party.iroiro.luajava:${lua}-platform:${luajavaVersion}:natives-arm64-v8a"
natives "party.iroiro.luajava:${lua}-platform:${luajavaVersion}:natives-x86"
natives "party.iroiro.luajava:${lua}-platform:${luajavaVersion}:natives-x86_64"
}
// Generated by gdx-setup:
// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives {
doFirst {
file("libs/armeabi-v7a/").mkdirs()
file("libs/arm64-v8a/").mkdirs()
file("libs/x86_64/").mkdirs()
file("libs/x86/").mkdirs()
configurations.natives.copy().files.each { jar ->
def outputDir = null
if (jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
if (jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
if(jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
if(outputDir != null) {
copy {
from zipTree(jar)
into outputDir
include "*.so"
}
}
}
}
}
tasks.whenTaskAdded { packageTask ->
if (packageTask.name.contains("merge") && packageTask.name.contains("JniLibFolders")) {
packageTask.dependsOn 'copyAndroidNatives'
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Using It
After setting up the dependencies or downloading the an interactive console, check out the Lua-side java
API and the Java-side API to start coding!