I've recently tried porting an engine I've been working on to Android and have ran into some problems when trying to use "require" or "dofile" within a lua script.
(quick note: this is written in C++11, using ndk-build and ant to compile on windows 7)
Compiling Lua (Version 5.3) was pretty simple and I used the following article to get access to the internal assets directory:
50ply blog post on loading compressed android assets
I added an output in the replaced fopen function to help debug this issue and when I run:
luaL_dofile(LuaS, "scripts/test.lua");
I get:
>> scripts/test.lua , read
Which is perfect for me and runs the file in the assets/scripts folder, but when I try to run the following line in the lua script:
local derp = require("scripts.noop")
I get:
>> /usr/local/lib/lua/5.3/scripts/noop.so , read
After looking through the Lua source code, this path seems to be the "LUA_CDIR" as defined in "luaconf.h", which also explains why it looks for *.so files instead of *.lua... So I'm not sure why it's looking for the LUA_CPATH instead of the LUA_PATH or how to fix this.
If anyone could point me in the right direction, that would be great and if I could do this by overwriting the search path/settings outside of the Lua source, it would be even better.
Sorry if this question is not well written, if any further information is required, I will provide it. I'm in a bit of a rush right now.
Thanks for reading.
Require checks both LUA_PATH and LUA_CPATH with many different combinations found within package.path and package.cpath. Environment variables LUA_PATH and LUA_CPATH can be found merged into package actually, as preparation goes.
Psuedo-c/c++-example:
lua_getglobal(L, "package");
lua_getfield(L, -1, "path");
lua_getfield(L, -2, "cpath");
const char* cpath = lua_tostring(L, -1);
const char* path = lua_tostring(L, -2);
lua_pop(L, 3); // field 2, field 1, package table
printf("cpath: `%s`\n", cpath);
printf("path: `%s`\n", path);
Which is almost equivalent to, minus the print calls:
>print(package.cpath)
.\?.dll;C:\Program Files\LuaConsole\bin\?.dll;C:\Program Files\LuaConsole\bin\loadall.dll
>print(package.path)
.\?.lua;C:\Program Files\LuaConsole\bin\lua\?.lua;C:\Program Files\LuaConsole\bin\lua\?\init.lua;
Here is an example of require working:
>require("abc")
(Runtime) | Stack Top: 0 | [string "require("abc")"]:1: module 'abc' not found:
no field package.preload['abc']
no file '.\abc.lua'
no file 'C:\Program Files\LuaConsole\bin\lua\abc.lua'
no file 'C:\Program Files\LuaConsole\bin\lua\abc\init.lua'
no file '.\abc.dll'
no file 'C:\Program Files\LuaConsole\bin\abc.dll'
no file 'C:\Program Files\LuaConsole\bin\loadall.dll'
--
stack traceback:
[C]: in function 'require'
[string "require("abc")"]:1: in main chunk
[C]: at 0x00401c80
The solution of your problem is to have your assets directory fall into a directory found within package.cpath or package.path. As #GabeSechan suggested in the comments, "You'll probably have an easier time of things if you copy the files from assets to the actual filesystem. Assets is not a directory on the device, so anything looking for a file won't find it." So if you are able to get this situated, go for it!
Related
I have battled this issue for sometime now and i seem to be going nowhere, I am using file_picker flutter plugin, its working on devices with android v7, now am running the app on emulator with android v9 and the filepicker creates symlink, here is a log:
I/FilePickerUtils( 7999): File loaded and cached at:/data/user/0/com.lulliezy.videostatus/cache/file_picker/KHALIGRAPH JONES x SARKODIE - WAVY (OFFICIAL VIDEO).webm
I/FilePickerDelegate( 7999): Absolute file path:/data/user/0/com.lulliezy.videostatus/cache/file_picker/KHALIGRAPH JONES x SARKODIE - WAVY (OFFICIAL VIDEO).webm
Now my understanding bt the word cached is a symlink is created, now how do i disable this feature or rather, get the original file name with this code:
await FilePicker.getFile(
type: FileType.custom,
allowedExtensions: ['mp4', 'webm'],
);
Thanks in advance.
EDIT
I should clarify, am using flutter ffmpeg so it complains with file does not exists.
I actually found a workaround for this, I copied the picked file to another temporary directory and used that new path after which when am done, I delete the copied file.
I'm trying to compile AOSP with a custom bootanimation, but with no success. And I just have run out of approaches... To change bootanimation, I've already done:
created a .zip file with the following structure:
bootanimation.zip {
desc.txt
part0 {
000.png, 001.png, ... ..., 010.png
}
part1 {
011.png, 012.png, ... ..., 021.png
}
}
edited permissions on system/core/include/private/android_filesystem_config.h
placed the bootanimation.zip file in /system/media/
However, when Android boots up, it just shows the Google trademark, skipping the boot animation. Can someone point what I'm missing?
PS: I'm successfully compiling AOSP. It boots up with all features ok. My problem is only with bootanimation customization on the compiled project.
Ok. I've solved my problem.
The issue was that besides all the things I've done, the bootanimation.zip file MUST be compressed with store method.
#mthama writes:
Ok. I've solved my problem. The issue was that besides all the things I've done, the bootanimation.zip file MUST be compressed with store method.
The solution is to not use any compression when packing the archive. This can be achieved on Linux with the following command:
zip -0r bootanimation.zip desc.txt part0 part1
The -0 option says to not use any compression and the -r option says to include contents of part0 and part1 recursively.
There are also ways doing this with a graphical interface, e.g. with 7-Zip as shown in this answer: https://superuser.com/a/337087/295453
I have installed QPython in my Android mobile.
I written a statement in the QEdit to read a text file from the below path
/storage/emulated/0/com.hipipal.qpyplus/script3/File1.txt
I used the below statement
fob=open('/storage/emulated/0/com.hipipal.qpyplus/script3/File1.txt','r')
fob.read()
If I run the statement, it is throwing error as:
IOError:[Errno 2] No such file or directory: '/storage/emulated/0/com.hipipal.qpyplus/script3/File1.txt'
1|uo_a116#cancro:/ $
Is the above statement correct?
fob=open('File1.txt','r')
Is not working in version 1.0.4.
fout=open('File2.txt','w')
Was working on version 0.9.6, but is not working in 1.0.4.
The "error" is Read only file system.
It looks like restrictions in the (new 1.0.4) file system library. I post a mail to the editor, but no answer at this time.
For testing, try to write absolute path to your files pointing, for example, to sdcard (/sdcard/out.txt).
I had problems on this versions (>=1.0.4) because launch process of script changes and execution directory is not the same as script directory.
I had to change my scripts to point to absolute paths.
It was tested with qpython developer.
Check this link:
https://github.com/qpython-android/qpython.org/issues/48
You can also try as simple as:
fob=open('File1.txt','r')
fob.read()
Just if the script is in the same folder of the file.
You can change the current working directory to path with script before read file:
import os
os.chdir(os.path.dirname(os.path.abspath(__file__)))
This code works in the simulator but not on my Android device:
local path = system.pathForFile("chinese_rules.db")
print("PATH:: " .. tostring( path ) )
When I run this code on my Galaxy S4 path returns nil.
My first thought was that it was some typo (case sensitivity) but I can't find any typo:
http://i59.tinypic.com/wlpu14.png
I can't find any reason why it should receive nil. This causes a problem as I can't load my database.
I have also tried this with the same result:
local path = system.pathForFile("chinese_rules.db", system.ResourceDirectory)
I have been able to load a path and load databases like this before.
Corona Build: 2013.2100 (2013.12.7)
Further reading the documentation I don't see that .db is a restricted file type:
Corona allows direct loading of images and audio files using the
appropriate APIs, but it has limited access to resource files on
Android using the file I/O APIs. Specifically, the following types can
not be read from the resources directory: .html, .htm., .3gp, .m4v,
.mp4,.png, .jpg, and .ttf.
http://docs.coronalabs.com/api/library/system/pathForFile.html
I found out the reason for the problem:
We are two that are working on this project and he had setup to use expansion files so two files was created (the main APK and the OBB expansion file) which I didn't notice and I only loaded the main APK file and I guess the database is in the OBB file. After setting not to use an expansion file the app works.
usesExpansionFile = false
Currently I am trying to get tesseract android tools
http://code.google.com/p/tesseract-android-tools/
to work for me on Android. I have been going at this for about a week to no avail.
I am running Win 7 64 bit with cygwin.
I followed the instructions in the readme file and made many changes to the Android.mk files. Basically it was appending a slash to the path, so I had to manually hard code the paths of the individual files, or move to location of the files within the 3 packages to get it to build. However at the end of the build, I did not recieve a "Build Sucessful" notice, but the .so files were generated.
I ported it to eclipse as is and used the following code to get the extracted text.
private static final String TESSBASE_PATH = "/mnt/sdcard/";
Bitmap imageFile = BitmapFactory.decodeFile(image.getAbsolutePath());
TessBaseAPI baseApi = new TessBaseAPI();
if(baseApi.init(TESSBASE_PATH, "eng")){
System.out.println("Tessbase initialized");
baseApi.setDebug(true);
baseApi.setImage(bmp);
String recognizedText = baseApi.getUTF8Text();
System.out.println("---------------------output-------------------");
System.out.println("recognizedText<"+recognizedText+">");
}
else{
System.out.println("Tessbase initialization failure.");
}
At first I was getting an error saying
"Bitmap functions not available; library must be compiled under android-8 NDK"
After taking a look at the tessbaseapi.cpp file I realized that it needed a specific compiler flag to compile the correct function. This flag was -DHAS_JNIGRAPHICS. What I think this means is that the JNI Graphics library must be present.
Yet the program still wouldn't compile because the memcpy() function in the newly compiled method could not be found. I fixed this by changing the actual C++ code to include
Finally the program compiled fully (still wasn't getting a BUILD SUCCESSFUL notice though) and when I ran it, I did not get any output at all. This could be a problem with the eng.traineddata file, or could be a problem in the actual code.
Is there anything I have done wrong? Can someone link me to and eng.traineddata file that they know works and image that works with it?
Thanks in advance!
It's been a few months since you posted this question, however if you're still looking for answers I would seriously recommend that you have a look at the tess-two project on github.
Whilst this won't solve the error that you've posted, its a tactical work around/alternate solution.
It's a fork of tesseract-android-tools and is incredibly easy to use, you'll have it up and running within the hour.
If you're getting poor results, make sure that traineddata file is there, use DDMS file explorer to check its there and not 0 bytes (that happened to me a few times).
Also, make sure you set the whitelist and blacklist characters, this will improve results very well.
Good luck