GF icon indicating copy to clipboard operation
GF copied to clipboard

How to create android specific .pgf_c binary ?

Open androidsparkling opened this issue 7 years ago • 9 comments

I am able to make .pgf file using the make command. But unable to find the tutorial/doc for creating .pgf_c binary from .pgf file.

androidsparkling avatar Apr 18 '18 12:04 androidsparkling

I have no experience in GF with Android, but is there anything useful in this directory? https://github.com/GrammaticalFramework/GF/tree/master/src/ui/android

Maybe @krangelov or @johnjcamilleri could help?

inariksit avatar Apr 18 '18 13:04 inariksit

Yes. I have seen the application in Playstore and saw the android sources in this repository. I have successfully built the JNI and android source. But when reading the source I found that .pgf_c binary needed for each language. So I installed GF 3.9 and successfully build gfo and pgf files, but I nowhere found any documentation for making .pgf_c binary from .pgf binaries.

String name = mLanguage.getConcrete()+".pgf_c" in = mContext.getAssets().open(name);

@krangelov or @aarneranta or @johnjcamilleri any help ?

androidsparkling avatar Apr 18 '18 16:04 androidsparkling

@androidsparkling I found it; you need to use the --split-pgf flag.

Here is an example:

$ gf -make --split-pgf LangDut.gfo LangSwe.gfo
linking ... OK
Writing Lang.pgf...
Writing LangDut.pgf_c...
Writing LangSwe.pgf_c...

inariksit avatar Apr 18 '18 18:04 inariksit

I added a few lines to hopefully make the documentation clearer; you can see the changes here. If you have suggestions how to make it even clearer, or in which other place(s) this information should be available, just let me know and I can add it!

inariksit avatar Apr 18 '18 18:04 inariksit

Great !. Thanks for your help. I can able to build .pgf_c files now. Let me explain what I have done first,

  1. I have converted .gf files from the directory 'GF/examples/app/' using make command.

  2. After 'make' command executed I could see that there is a new folder 'gfo', the folder contains .gfo files corresponding to the languages. Also, there are pgf files generated inside the folder 'GF/examples/app/'. Even though some languages failed to generate the .pgf files.

  3. I have used --split-pgf command to generate .pgf_c file from the .pgf files and succeeded.

  4. So I have copied App.pgf, AppEng.pgf_c, and AppHin.pgf_c into assets folder and successfully build and installed on a device.

But I got an error when loading AppHin.pgf. (Tried Bulgarian, Chinese also but same error). See the logs on an Android device,

Translator: App.pgf loaded (618 ms) Translator: Trying to load AppEng.pgf_c Timeline: Timeline: Activity_idle id: android.os.BinderProxy@183341d3 time:26465724 Translator: AppEng.pgf_c loaded (2252 ms) Translator: Trying to load AppHin.pgf_c

        --------- beginning of crash

AndroidRuntime: FATAL EXCEPTION: Thread-3934 Process: org.grammaticalframework.ui.android, PID: 30884 java.lang.NullPointerException: Attempt to invoke virtual method 'void ``org.grammaticalframework.pgf.Concr.load(java.io.InputStream)' on a null object reference at org.grammaticalframework.ui.android.Translator$ConcrLoader.run(Translator.java:720)

When I tried Catalan I got the following native error.

D/Translator: Trying to load AppCat.pgf_c org.grammaticalframework.ui.android A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 15249 (Thread-14094) org.grammaticalframework.ui.android W/libc: Security Level: (1), Debug inforamtion is controlled by the DUMPABLE flag.

androidsparkling avatar Apr 19 '18 11:04 androidsparkling

I've never done anything with Android, but could you try some more basic debugging?

  • Is there anything you can do with PGFs that does work? For instance, try the getLanguages() method on the PGF (not .pgf_c).
  • Can you try with another grammar? Something really simple, like a Foods grammar with just a single concrete syntax.
  • When did you install the C runtime and the Java bindings? There have been quite recent bugfixes, you could check that you have the most up-to-date version.

If you don't get answers here, you could post your problem to the gf-dev mailing list. I'm not sure how much @krangelov , @Thomas-H etc. follow GitHub issues.

inariksit avatar Apr 19 '18 15:04 inariksit

I’m not sure if this has reached Krasimir, so let us add his usual mail address.

Inari, you are right that gf-dev would be a good idea, too.

Aarne.

On 19 Apr 2018, at 17:01, Inari Listenmaa <[email protected]mailto:[email protected]> wrote:

I've never done anything with Android, but could you try some more basic debugging?

  • Is there anything you can do with PGFs that does work? For instance, try the getLanguages() method on the PGF (not .pgf_c).
  • Can you try with another grammar? Something really simple, like a Foods grammarhttps://github.com/GrammaticalFramework/gf-contrib/blob/master/foods/FoodsEng.gf with just a single concrete syntax.
  • When did you install the C runtime and the Java bindings? There have been quite recent bugfixes, you could check that you have the most up-to-date version.

If you don't get answers here, you could post your problem to the gf-dev mailing listhttps://groups.google.com/forum/#!forum/gf-dev. I'm not sure how much @krangelovhttps://github.com/krangelov , @Thomas-Hhttps://github.com/Thomas-H etc. follow GitHub issues.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/GrammaticalFramework/GF/issues/33#issuecomment-382769321, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACwYXZxq-S9FfqhdyceiA6yoDdiJ_5I_ks5tqKaygaJpZM4TaAng.

aarneranta avatar Apr 19 '18 15:04 aarneranta

The error means that the grammar that you are trying to load doesn't have these concrete syntaxes.

You can check which languages are available like:

(with the Haskell binding)

$ ghci

:m +PGF2 gr <- readPGF "App.pgf" languages gr

(with the Python binding)

$ python

import pgf gr = pgf.readPGF("App.pgf") gr.languages

On 19 April 2018 at 13:38, androidsparkling [email protected] wrote:

Great !. Thanks for your help. I can able to build .pgf_c files now. Let me explain what I have done first,

I have converted .gf files from the directory 'GF/examples/app/' using make command. 2.

After 'make' command executed I could see that there is a new folder 'gfo', the folder contains .gfo files corresponding to the languages. Also, there are pgf files generated inside the folder 'GF/examples/app/'. Even though some languages failed to generate the .pgf files. 3.

I have used --split-pgf command to generate .pgf_c file from the .pgf files and succeeded. 4.

So I have copied App.pgf, AppEng.pgf_c, and AppHin.pgf_c into assets folder and successfully build and installed on a device.

But I got an error when loading AppHin.pgf. (Tried Bulgarian, Chinese also but same error). See the logs on an Android device,

Translator: App.pgf loaded (618 ms) Translator: Trying to load AppEng.pgf_c Timeline: Timeline: Activity_idle id: android.os.BinderProxy@183341d3 time:26465724 Translator: AppEng.pgf_c loaded (2252 ms) Translator: Trying to load AppHin.pgf_c

    --------- beginning of crash

AndroidRuntime: FATAL EXCEPTION: Thread-3934 Process: org.grammaticalframework.ui.android, PID: 30884 java.lang.NullPointerException: Attempt to invoke virtual method 'void ``org.grammaticalframework.pgf.Concr.load(java.io.InputStream)' on a null object reference at org.grammaticalframework.ui.android.Translator$ ConcrLoader.run(Translator.java:720)

When I tried Catalan I got the following native error.

D/Translator: Trying to load AppCat.pgf_c org.grammaticalframework.ui.android A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 15249 (Thread-14094) org.grammaticalframework.ui.android W/libc: Security Level: (1), Debug inforamtion is controlled by the DUMPABLE flag.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GrammaticalFramework/GF/issues/33#issuecomment-382703478, or mute the thread https://github.com/notifications/unsubscribe-auth/ATBZZGG3smjj9SqIpQSjcoIdcN_Nk-Zgks5tqHdPgaJpZM4TaAng .

krangelov avatar Apr 19 '18 18:04 krangelov

@androidsparkling Did you get it to work? In the Java version, you can use getLanguages() method to check which languages are available.

inariksit avatar Apr 22 '18 07:04 inariksit