Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Redesign #171

Merged
merged 23 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/build-natives.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
- name: Test (Desktop)
run: |
export NDK_HOME=$ANDROID_NDK_LATEST_HOME
./gradlew :example:test :jsr223:test
./gradlew :example:test :jsr223:test :jpms-example:run
- name: Jacoco Test Report
run: |
export NDK_HOME=$ANDROID_NDK_LATEST_HOME
Expand Down Expand Up @@ -199,18 +199,18 @@ jobs:
./gradlew jniGen
- name: Test
run: |
./gradlew :example:test :jsr223:test
./gradlew :example:test :jsr223:test :jpms-example:run
android-testing:
runs-on: ubuntu-latest
strategy:
matrix:
api-level: [ 21, 24 ]
api-level: [ 21 ]
android-arch: [ 'x86_64', 'x86' ]
include:
- api-level: 24
android-arch: 'x86'
- api-level: 27
android-arch: 'x86_64'
- api-level: 30
android-arch: 'x86_64'
- api-level: 33
android-arch: 'x86_64'
needs:
Expand Down
13 changes: 13 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,16 @@ After compiling, things should work fine (including tests and bundling or whatso
The tests lie in [`example/suite`](./example/suite) and [`example/src/test`](./example/src/test).
The former one is bundled into the example JAR to allow easier testing on different platforms.
However, to run the tests, try `./gradlew :example:test` or start tests in the latter from an IDE.

## Coding Caveats

### Java 8 Feature Usages

The major obstacle against using Java 8 features in the codebase is Android compatibility.
Theoretically, however, with Java 8 desugaring in Android SDK,
one can use such features as default methods in interfaces or lambda functions.
But requiring the user to set up desugaring only to use this library is just too much.
Therefore, for now:
- We just disallow using any Java 8 features in the codebase.
- For tests, since we have control over the testing environment (and build config),
using Java 8 lambdas, default functions, etc. are acceptable to some degree.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,15 @@ since this library is more or less just a thin wrapper and requires some basic u

<div style="display:flex;justify-content:center">

| Lua 5.1 | Lua 5.2 | Lua 5.3 | Lua 5.4 | LuaJIT | LuaJ |
|:-------:|:-------:|:-------:|:-------:|:-----------:|:--------:|
| 5.1.5 | 5.2.4 | 5.3.6 | 5.4.6 | [`0d313b2`] | [A fork] |
| Lua 5.1 | Lua 5.2 | Lua 5.3 | Lua 5.4 | LuaJIT | LuaJ |
|:-------:|:-------:|:-------:|:-------:|:-----------:|:-----------:|
| 5.1.5 | 5.2.4 | 5.3.6 | 5.4.6 | [`0d313b2`] | [LuaJ fork] |

</div>

[`0d313b2`]: https://github.com/LuaJIT/LuaJIT/commits/0d313b243194a0b8d2399d8b549ca5a0ff234db5

[A fork]: https://github.com/wagyourtail/luaj

Supported Lua versions: Lua 5.1, Lua 5.2, Lua 5.3, Lua 5.4, LuaJ and LuaJIT.
[LuaJ fork]: https://github.com/wagyourtail/luaj

Supported platforms: **Windows**, **Linux**, **MacOS** and **Android**. Compiled against both ARM and x32/x64. Binaries are not yet tested for iOS.

Expand All @@ -79,7 +77,7 @@ Optionally, you may include `party.iroiro.luajava:jsr223` to provide JSR 223 fun
[The `java` module](https://gudzpoz.github.io/luajava/api.html#java-module) provides these functions:

- `array`: Create a Java array.
- `catched`: Return the latest captured Java `Throwable`
- `caught`: Return the latest captured Java `Throwable`
- `detach`: Detach the sub-thread from registry to allow for GC
- `import`: Import classes from Java
- `loadlib`: Load a Java method, similar to `package.loadlib`
Expand Down
23 changes: 12 additions & 11 deletions android/android-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ lint.enabled = false
android {
namespace = project(':').group

compileSdkVersion 30

defaultConfig {
minSdk 21
targetSdk 21
targetSdk 34
compileSdk 33
versionCode 1
versionName '3.1'
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
Expand All @@ -55,20 +54,22 @@ android {
}

compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
androidTestImplementation project(':luajava')
androidTestImplementation project(':lua51')
androidTestImplementation project(':lua52')
androidTestImplementation project(':lua53')
androidTestImplementation project(':lua54')
androidTestImplementation project(':luajit')
androidTestImplementation project(':luaj')
androidTestImplementation project(':example:suite')
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
implementation project(':luajava')
implementation project(':lua51')
implementation project(':lua52')
implementation project(':lua53')
implementation project(':lua54')
implementation project(':luajit')
implementation project(':luaj')
implementation project(':example:suite')
androidTestImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:core:1.5.0'
androidTestImplementation 'androidx.test:rules:1.5.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package party.iroiro.luajava;

import android.util.Log;
import org.junit.Test;
import party.iroiro.luajava.lua51.Lua51;
import party.iroiro.luajava.lua52.Lua52;
Expand Down Expand Up @@ -40,15 +39,15 @@ public void lua54Test() {
@Test
public void luaJitTest() {
try (LuaJit L = new LuaJit()) {
new LuaScriptSuite<>(L, s -> Log.i("test", s)).test();
new LuaScriptSuite<>(L).test();
}
}

@Test
public void luaJTest() {
org.junit.Assume.assumeTrue(android.os.Build.VERSION.SDK_INT >= 30);
try (AbstractLua L = AndroidLuaTest.getLuaJ()) {
new LuaScriptSuite<>(L, s -> Log.i("test", s)).test();
new LuaScriptSuite<>(L).test();
}
}

Expand Down
5 changes: 1 addition & 4 deletions android/android-test/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="party.iroiro.luajava">

<manifest>
</manifest>
30 changes: 16 additions & 14 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,31 @@ ext {
android {
namespace = project(':').group

compileSdk 33
buildToolsVersion '30.0.3'

defaultConfig {
minSdk 21
targetSdk 31
targetSdk 34
compileSdk 33
versionCode 1
versionName '3.1'
}

sourceSets { container ->
luaVersions.forEach { ver ->
luaVersions.each { v ->
String ver = v
container.create(ver) {
namespace "${project(':').group}.${ver}"
manifest.srcFile 'AndroidManifest.xml'
jniLibs.srcDirs = ["${ver}-libs"]
}
}
}

flavorDimensions 'lua'
flavorDimensions += 'lua'

productFlavors { container ->
luaVersions.forEach { ver ->
container.create(ver) {
luaVersions.each { ver ->
String v = ver
container.create(v) {
dimension 'lua'
}
}
Expand All @@ -53,7 +54,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
matchingFallbacks = 'release'
matchingFallbacks ['release']
}
}

Expand All @@ -63,7 +64,7 @@ android {
}
}

task copyAndroidNatives {
tasks.register('copyAndroidNatives') {
doFirst {
List<String> platforms = ['armeabi-v7a', 'arm64-v8a', 'x86_64', 'x86']
luaVersions.forEach { ver ->
Expand All @@ -82,7 +83,7 @@ task copyAndroidNatives {
}
}

tasks.whenTaskAdded { packageTask ->
tasks.configureEach { packageTask ->
if (packageTask.name.contains("merge") && packageTask.name.contains("JniLibFolders")) {
packageTask.dependsOn 'copyAndroidNatives'
}
Expand All @@ -102,9 +103,10 @@ afterEvaluate {

publishing {
publications {
'default'(MavenPublication) { container ->
create('default', MavenPublication) { container ->
setPom(pom, '')
luaVersions.forEach { ver ->
luaVersions.each { v ->
String ver = v
String path = "${buildDir}/outputs/aar/android-${ver}-release.aar"
file(path).getParentFile().mkdirs()
file(path).createNewFile()
Expand Down Expand Up @@ -140,7 +142,7 @@ afterEvaluate {
}
}

tasks.whenTaskAdded { packageTask ->
tasks.configureEach { packageTask ->
if (packageTask.name.toLowerCase().contains("maven")) {
packageTask.dependsOn 'assemble'
}
Expand Down
6 changes: 2 additions & 4 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="party.iroiro.luajava">
</manifest>
<manifest>
</manifest>
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'com.android.tools.build:gradle:7.4.1'
}
}

Expand Down Expand Up @@ -41,7 +41,7 @@ ext {
apply from: 'publish.gradle'
apply from: 'jacoco.gradle'

task allJavadoc(type: Javadoc) {
tasks.register('allJavadoc', Javadoc) {
Set<String> projects = [
'lua51',
'lua52',
Expand Down
Loading