NimHelloJNI icon indicating copy to clipboard operation
NimHelloJNI copied to clipboard

run android fails

Open moeinrahimi opened this issue 4 years ago • 3 comments

I get below error when trying to run project

F:\projects\sample_code\NimHelloJNI\app\src\main\cpp\x86\stdlib_os.nim.c:120:51: error: unexpected type name 'tySequence__sM4lkSb7zS6F7OVMvW9cffQ': expected expression

image

moeinrahimi avatar Sep 10 '21 11:09 moeinrahimi

@moeinrahimi:

This project was a Proof Of Concept (POC) to show that it is easy to write most of the code for an Android app in Nim using the Java Native Interface (JNI) but as you can see I haven't touched it in over a year.

I will follow this up, but suspect that the problem may very well be due to updated versions over just about everything, as even Nim may have been pre-version 1.0 then and we are up to 1.4.8 now - going on to version 1.6.0, Android Studio has changed, the C compiler no doubt has updated etc.

As the error message refers to a problem with the Seq type, which isn't actually used, the problem may be related to that the included wrapper libraries have implementations for Seq which trigger the error or that String is actually used for the "Hello" message and in Nim String is a specialized Seq of Char. The whole idea of how String's/Seq's structures work has been changed in newer versions of Nim, which may be what causes the conflict. It could well be that the JNI Wrappers no longer reflect the true structure of these for newer versions.

That said, this project should really be updated anyway as Nim is moving toward not using Garbage Collection (GC) but rather automatic Reference Counting with "ARC/ORC" --gc:arc (specialized reference counting GC) or --gc:orc (cycle breaking reference counting GC) and these are what should really be used here as it avoids the problem of having to run the conventional Mark-and-Sweep Nim GC in conjunction with the Java/Android GC. When I look into this I'll be moving to using these. This issue also probably applies to my other Android repo's here as in the JNI callback ones and the Sieve of Eratosthenes benchmark one, which embodies this technique turned into a benchmark application. I'll apply whatever fixes are discovered here to those repo's as well.

It may take me a few days to weeks get onto looking into this, but in the meantime, your issue details aren't very complete, lacking the versions of everything you are using and the machine and OS on which you are running. Could you please fill in some more of these details?

GordonBGood avatar Sep 10 '21 20:09 GordonBGood

@moeinrahimi, I think I've gotten this working, as follows:

  1. The main problem was that the Nim "nimbase.h" file included in the repo wasn't compatible with later Nim compiler versions, I've updated the current repo version to the Nim compiler version 1.6.2, but for future (or earlier) Nim compiler version you may need to change this file (and if you do, you should really change the "copying.txt" file to match.
  2. The "app/src/main/AndroidManifext.xml" file needs to be changed to be compatible with the latest build system.
  3. I updated the "build.gradle" file inside the "app" subfolder for current Android versions...
  4. I updated the "buld.gradle" file in the main directory to eliminate warnings to do with future Gradle plug-in verssions...
  5. The README.md file has been updated to reflect all changes, including the new Android Studio UI...

If this works (and it should as I tested it, although on Linux and not on Windows, although the original repo was built on Windows), my other repositories to do with using Nim to build Android apps will also need to be updated in the same way..

Please let me know here if it now works and we can close this issue...

GordonBGood avatar Jan 06 '22 07:01 GordonBGood