LAMW “Use/Import C stuff" needs improvements lazarus / 43-Android ---------------------------------------------------------------------- neuro · 2022-03-14 13:07 LAMW allows to use and integrate C code into LAMW Android app in the form of the shared library (.so). This is very powerful feature which allows to use vast resources of already available C program code. However, Tools -> [LAMW] Module Wizard -> Use/Import C stuff needs improvements and bug fixes. Current version of “Use/Import C” form is attached. When “Use/Import C stuff” form is used, it creates two files: 1) libmycstuff1-builder.bat (in project folder), 2) Android.mk (in “jni” subfolder). Both these created files have problems, which need to be solved. #1 problem File “libmycstuff1-builder.bat” is supposed to compile C code project into shared library (.so). Yes, “libmycstuff1-builder.bat” does successfully compile C code project into shared library (.so), however when app is launched on Android device, the app instantly crashes on launch. Currently you need to use menu “Tools -> [LAMW] Module Wizard -> Use/Import C stuff” to build shared library (.so) – this way the app does not crash when launched on Android device, it works correctly. This bug needs to be solved. Manual execution of “libmycstuff1-builder.bat” should produce correct app which does not crash. Currently I use “libmycstuff1-builder.bat” for testing C code project files for compilation errors – it stops compilation on the first errors encountered and you can clearly see location of errors in terminal window, and thus you can fix errors in C code. However if you run “Tools -> [LAMW] Module Wizard -> Use/Import C stuff”, then C compilation behaves differently – compilation does not stop if errors are encountered in some C files, and you cannot see and fix errors in C files, which is very inconvenient. #2 problem The second problem is with generated “Android.mk” file (in “jni” subfolder). It works ok when C project is very small and contains only several C files. However if C project is big and contains hundreds of C files with many subdirectories and project needs options like “LOCAL_C_INCLUDES”, then generated “Android.mk” fails completely. As a workaround solution I have solved this problem in the following way. 1. Packages -> Install/Uninstall Packages -> amw_ide_tools 0.0 -> Uninstall selection 2. Modify file C:\fpcupdeluxe\ccr\lamw\ide_tools\amw_ide_menu_items.pas with patched code Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if FileExis tsUTF8(pathToProject+'jni'+DirectorySeparator+'Android_neuro.mk') then CopyFile(pathToProject+'jni'+DirectorySeparator+'Android_neuro.mk', pathToProject+'jni'+DirectorySeparator+'Android.mk') else auxList.Save ToFile(pathToProject+'jni'+DirectorySeparator+'Android.mk'); 3. Package -> Open Package File (.lpk) -> C:\fpcupdeluxe\ccr\lamw\ide_tools\amw_ide_tools.lpk -> Install The patched code works in the following way. If file “Android_neuro.mk” is found, then this file is copied “Android.mk”. Else if file “Android_neuro.mk” is not found, then new file “Android.mk” is created by LAMW. This is my workaround solution how to use my own manually created “Android.mk” for complex huge C project compilation. We need more elegant solution for this problem. I think we need to add a checkbox to “Use/Import C stuff” form which says something like “do not created Android.mk file, use my own manually created Android.mk”. And when this checkbox is checked, then “Use/Import C stuff” skips generation of “Android.mk” file. Also we need to fix one word in “Use/Import C stuff” form – at the bottom there is a “Warning” which contains one error – instead of word “nedd” it should be “needs”. #3 problem H2PAS (free Pascal C header to Pascal unit translator) incorrectly produces *.pp files, as for example field ‘name’ of some functions are missing, some data types are converted incorrectly, and as a result, produced *.pp files need manual fixing. #4 problem “Use/Import C stuff” copies all *.c and *.h files from selected directory into “mycstuff1” subdirectory (of the project) and then tries to compile C code. This is incorrect approach. Complex C project can also contain files with other file extensions besides *c. and *.h and also many subdirectories, and these files are not copied, and compilation fails. Another inconvenience is that “Use/Import C stuff” duplicates *c. and *.h files and makes a mess in project files (you need time to figure out which copy of “file.c” to edit/backup/etc) – that is incorrect approach. Currently my workaround solution is the following. I place all C project files (hundreds of files) into “mycstuff1” subdirectory, then I put just one(1) “file.c” into “input directory” to force “Use/Import C stuff” to compile the project using my own “Android.mk” (which was described in “#2 problem” solved by patch of “amw_ide_menu_items.pas”). If none *.c file is present in “input directory”, then “Use/Import C stuff” fails to compile project. You need to put at least one “file.c” inside “input directory” to force “Use/Import C stuff” to compile the project. This is incorrect approach. “Use/Import C stuff” form should simply choose “mycstuff1” subdirectory as based on “mycstuff1” lib name, and it should not make duplicate copies of *.c and *.h files to some other directories. Also “Use/Import C stuff” should not forcibly create “Android.mk” file and should allow manual input of my own “Android.mk” file. #5 problem “Use/Import C stuff” form should save it’s settings in *.ini file in project’s “jni” subdirectory, because it is very annoying when you need to recompile “mycstuff1” shared library and every time you need to enter data anew into “Use/Import C stuff” form. After these updates will be implemented, “Use/Import C stuff” will become great tool to use. jmpessoa, can you make such an updates of “Use/Import C stuff” form? I can do a submit of "pull request" for such changes in github, but I’ll do that a little later. ---------------------------------------------------------------------- jmpessoa · 2022-03-14 19:25 QuoteI can do a submit of "pull request" for such changes in github, but I’ll do that a little later. Nice! We can wait until there! Thank you! ---------------------------------------------------------------------- neuro · 2022-03-17 13:02 I have made three "pull requests" for changes in github for three updated files. The update for “Use/Import C stuff” plugin: 1) Originally “Use/Import C stuff” plugin was able to compile C code only for armeabi-v7a. Now it compiles for all platforms: armeabi-v7a, arm64-v8a, x86, x86_64. 2) “Use/Import C stuff” now saves current project’s settings in file “.\jni\ImportCStuff.ini “. 3) Added options for disabling “Android.mk” and “*.pp” file generation. The update is in 3 files: amw_ide_menu_items.pas uimportcstuff.pas uimportcstuff.lfm The screenshot  of updated “Use/Import C stuff” Form is attached. ---------------------------------------------------------------------- jmpessoa · 2022-03-17 17:13 QuoteI have made three "pull requests" for changes in github for three updated files. Done!!!! Thank You!