love2d / love-android

Android build setup for LÖVE.
https://love2d.org
Other
211 stars 73 forks source link

Initialize the LUA_CPATH environment variable to getCRequirePath(). #225

Closed mansourmoufid closed 2 years ago

mansourmoufid commented 2 years ago

In would like to drop foo.so into the applicationInfo.nativeLibraryDir directory (app/src/main/jniLibs/arm64-v8a/) and do ffi.load("foo"). A few years ago this worked fine, but now fails with the error:

main.lua:6: dlopen failed: library "libfoo.so" not found

When I set the environment variable LUA_CPATH to include getCRequirePath(), LuaJIT is able to find libfoo in package.cpath, and load it properly.

Before:

package.cpath = ./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so

After:

package.cpath = ./?.so;/data/app/~~bA-o3tblNjxoXGxEegyvlQ==/org.love2d.android-B3nOyZj457IR_fUb49FRSw==/lib/arm64/?.so
MikuAuahDark commented 2 years ago

Rename libfoo.so to foo.so. This has been implemented through LOVE's own require paths since 11.4.

https://github.com/love2d/love/commit/b79b99bbaa60fb283d160782e5b31f953b43760c

Pada tanggal Sel, 15 Feb 2022 04.31, Mansour Moufid < @.***> menulis:

In would like to drop foo.so into the applicationInfo.nativeLibraryDir directory (app/src/main/jniLibs/arm64-v8a/) and do ffi.load("foo"). A few years ago this worked fine, but now fails with the error:

main.lua:6: dlopen failed: library "libfoo.so" not found

When I set the environment variable LUA_CPATH to include getCRequirePath(), LuaJIT is able to find libfoo in package.cpath, and load it properly.

Before:

package.cpath = ./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so

After:

package.cpath = ./?.so;/data/app/~~bA-o3tblNjxoXGxEegyvlQ==/org.love2d.android-B3nOyZj457IR_fUb49FRSw==/lib/arm64/?.so


You can view, comment on, or merge this pull request online at:

https://github.com/love2d/love-android/pull/225 Commit Summary

File Changes

(1 file https://github.com/love2d/love-android/pull/225/files)

Patch Links:

— Reply to this email directly, view it on GitHub https://github.com/love2d/love-android/pull/225, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZHFFTFVW4742NYGFK5I5LU3FRDNANCNFSM5OMQKSRA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

MikuAuahDark commented 2 years ago

If it still doesn't work then it can be a bug. Please fill bug report instead.

mansourmoufid commented 2 years ago

Rename libfoo.so to foo.so.

Oops! 😅 Nevermind.

MikuAuahDark commented 2 years ago

Also for future reference why this Pull Request is not 100% correct is because 2 things:

  1. android.system.Os only works in Android 5.0 or later. LOVE 11.x branch must still support Android version down to 4.2 so you need to use SDLActivity.nativeSetEnv instead.
  2. LuaJIT checks the file existence before opening the file. This doesn't work with uncompressed native libs (where the native libs stays inside the APK and loaded directly).

love2d/love@b79b99bbaa60fb283d160782e5b31f953b43760c solves both problems.