gudzpoz / luajava

Lua for Java on Windows, Mac OS X, Linux, Android. 5.1, 5.2, 5.3, 5.4, LuaJ or LuaJIT.
https://gudzpoz.github.io/luajava/
Other
154 stars 21 forks source link

Support for Android Studio. #14

Closed leasses closed 2 years ago

leasses commented 2 years ago

It was a bit complicated. I add the dependencies to my build.gradle file, just like this:

implementation 'party.iroiro.luajava:luajava:3.0.2'
implementation 'party.iroiro.luajava:luajit:3.0.2'
implementation 'party.iroiro.luajava:luajit-platform:3.0.2:natives-armeabi-v7a'
implementation 'party.iroiro.luajava:luajit-platform:3.0.2:natives-arm64-v8a'

But the Gradle didn't add the .so files to my APK. So when I run the app on my phone, It exits and throws an Expection:

java.lang.UnsatisffiedLinkError: Unable to find natives or init.

So I try to move the .so files to jniLibs\<target API>\ directory, but it still can't work and throws the Expection.

What should I do?

gudzpoz commented 2 years ago

I added some documentation about Android configurations. Can you try again with 3.0.3-SNAPSHOT?

repositories {
    maven {
        url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
    }
}

ext {
    lua = 'luajit'
    luaJavaVersion = '3.0.3-SNAPSHOT'
}
gudzpoz commented 2 years ago

Are you using version 3.0.3-SNAPSHOT or 3.0.2? Indeed, native binaries for version 3.0.2 lead to segment fault due to misconfigured build scripts, which hopefully has been fixed by 3.0.3-SNAPSHOT.

leasses commented 2 years ago

Thanks so much for helping. It works! And I give you an advice, you can use the .aar file to package it so that the Gradle can package the .so files to the APK instead of using the gradle scripts, and the configuration for Android can be shorter. Of coures you can continue using .jar file, and its size is smaller than .aar file.

By the way, sorry for my poor English because I am Chinese. If you can understand Chinese, please tell me.

gudzpoz commented 2 years ago

Thanks for the suggestion! With #16, you can now include the native binaries with:

implementation 'party.iroiro.luajava:luajit:3.0.3-SNAPSHOT'
runtimeOnly "party.iroiro.luajava:android:3.0.3-SNAPSHOT:luajit@aar"
leasses commented 2 years ago

Thank you!