[Solved] [LAMW] How can Pascal Functions be used in Android Studio? lazarus / 43-Android ---------------------------------------------------------------------- loaded · 2021-01-30 12:18 Hi All, Functions prepared on Lazarus with LAMW support, For example the attached simple function; 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 unit Unit2;{$mode delphi}interfaceuses  Classes, SysUtils;  function F_Test_Function(a,b:integer):string;implementation function F_Test_Function(a, b: integer): string;  begin  Result:=inttostr(a+b);  end; end.  In a different project on Android studio In the sample java 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 package com.example.myapplication;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.TextView;public class MainActivity extends AppCompatActivity {    public TextView text;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        text=findViewById(R.id.txt);    }    public void buttonClick(View view) {        text.setText(F_Test_Function(2021,01));  //<<<<<-----------Here I want to call and use the function    }}  can it be used If yes, what are the steps to be taken and the actions to be taken. If someone shows the way, it will be very appreciated. Respects. ---------------------------------------------------------------------- jmpessoa · 2021-01-30 13:57 (0) Look For java "JNI"  + Pascal (1) https://wiki.freepascal.org/pas2jni (2) LAMW: "Project"  --> "New Project"   --> "LAMW [NoGUI]" Android Module" the demo is here: C:\Users\DELL\Documents\GitHub\lazandroidmodulewizard\demos\NoGUI (3) LAMW: https://github.com/jmpessoa/lazandroidmodulewizard/blob/master/docs/ho w_to_create_new_components.txt ---------------------------------------------------------------------- loaded · 2021-01-30 14:18 Thank you for the answer jmpessoa, Apparently, it seemed a long way to me.  Also ; It's hard not to be surprised, Pascal is truly a monster. ---------------------------------------------------------------------- loaded · 2021-01-31 17:59 I translated the jnihello project in the NoGUI folder with jni2pas. pas folder with java codes in it was created. I was waiting for binary files to be created. I wonder if I made a mistake somewhere? ---------------------------------------------------------------------- jmpessoa · 2021-01-31 19:57 QuoteI translated the jnihello project in the NoGUI folder with jni2pas. No! the jnihello project is already completed!!! And you only use as "model"  to produce your own projects! Use "Run"  --> "Build"  to produce "libjnihello.so"  in project folder ".....\libs\armeabi" And this is ALL!!! PS. At the moment ...the project need be open using a java IDE {Eclipse?} to produce a new Apk.... ---------------------------------------------------------------------- jmpessoa · 2021-02-01 05:55 Done! Updated "AppNoGUIDemo1" Updated "LAMW [NoGUI] Android Module" Now you can: "Run"  --> "Build"   to produce the "*.so" library and "Run" --> "[LAMW] Build Android Apk and Run"  to get and install your Apk!!! But study the generated   "App.java" , "AppNoGUIDemo1.java" and   "appnoguidemo1.lpr"  to understand the overall design...  in  "appnoguidemo1.lpr"  we need complete the code generated: 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 { Class:   org_lamw_appnoguidemo1_AppNoGUIDemo1  Method:    getString  Signature: (I)Ljava/lang/String; }function getString(PEnv: PJNIEnv; this: JObject; flag: JInt): JString; cdecl;begin  {your code....}    if flag = 1  then      Result:= (PEnv^).NewStringUTF(PEnv, '1.New message from JNI Pascal')    else      Result:= (PEnv^).NewStringUTF(PEnv, '2.New message from JNI Pascal');end; { Class:     org_lamw_appnoguidemo1_AppNoGUIDemo1  Method:    getSum  Signature: (II)I }function getSum(PEnv: PJNIEnv; this: JObject; x: JInt; y: JInt): JInt; cdecl;begin  {your code....}  Result:= x + y;end;  Hint1: "How_to_open_LAMW_project_with_AndroidStudio" ref. https://github.com/jmpessoa/lazandroidmodulewizard/blob/master/docs/Ho w_to_open_LAMW_project_with_AndroidStudio.txt ---------------------------------------------------------------------- loaded · 2021-02-01 15:10 jmpessoa, may god be pleased with you The topic started to sit in my head. It is a difficult subject for me to grasp, I have to do some trial and error. ---------------------------------------------------------------------- jmpessoa · 2021-02-01 16:22 QuoteIt is a difficult subject for me to grasp.... Yes, but the code in "demo" generated  by LAMW can help you... ---------------------------------------------------------------------- loaded · 2021-02-01 16:40 If it weren't for the demo you wrote. It would be a dream to get to the current level. I learned a lot thanks to you. Thank you so much ---------------------------------------------------------------------- loaded · 2021-02-03 18:26 Yes, I have come a long way on the subject, even though I was struggling. (Thanks to you) Normally the File that occurs when the project is compiled; "AppNoGUIDemo1 \ libs \ armeabi-v7a \ libappnoguidemo1.so" The project works just fine. But; [LAMW] Android Project Options, If I make any changes on the part After that the resulting file "AppNoGUIDemo1 \ libs \ armeabi-v7a \ libcontrols.so" Then the application crashes. This filename issue has been a challenge for me, I realized quite late. What can I do about the solution. ---------------------------------------------------------------------- jmpessoa · 2021-02-03 20:08 Quote[LAMW] Android Project Options, If I make any changes on the part What change? If you change the chip architecture "Run"  ---- "Clean up and Build" before "Run"  --> "[LAMW] Build Android Apk and Run" ---------------------------------------------------------------------- loaded · 2021-02-03 20:26 Any changes in the SDk version or Chipset, the project breaks. Clean up and Build process does not fix the problem. ---------------------------------------------------------------------- jmpessoa · 2021-02-03 20:50 QuoteNormally the File that occurs when the project is compiled; "AppNoGUIDemo1 \ libs \ armeabi-v7a \ libappnoguidemo1.so" The project works just fine. But; [LAMW] Android Project Options, If I make any changes on the part After that the resulting file "AppNoGUIDemo1 \ libs \ armeabi-v7a \ libcontrols.so" There is some bug here: "AppNoGUIDemo1 \ libs \ armeabi-v7a \ libcontrols.so" we need "AppNoGUIDemo1 \ libs \ armeabi-v7a \ libappnoguidemo1.so"    !!! I will fix it! So, Just don't change anything in "[LAMW] Android Project Options"  and continue your learning !!! ---------------------------------------------------------------------- loaded · 2021-02-04 06:34 Quote from: jmpessoa on February 03, 2021, 09:50:01 pmSo, Just don't change anything in "[LAMW] Android Project Options"  and continue your learning !!! understood, thanks ---------------------------------------------------------------------- yuriy_sydorov · 2021-02-05 12:18 Just use the pas2jni utility. https://wiki.freepascal.org/pas2jni ---------------------------------------------------------------------- jmpessoa · 2021-02-05 16:17 @yuriy_sydorov QuoteJust use the pas2jni utility. Can you post a simple [but functional]  example? Using Android Studio or LAMW] ---------------------------------------------------------------------- loaded · 2021-02-05 20:51 Thanks for the answer yuriy_sydorov Quote from: yuriy_sydorov on February 05, 2021, 01:18:06 pmJust use the pas2jni utility. https://wiki.freepascal.org/pas2jni When the goal is to perform the desired action, the solution should be the shortest path. I tried pas2jni and its use seems to be detailed. No hard work, things have gotten much easier now at LAMW. I also prepared a video about the use of the .so file I created with LAMW in a project created from scratch in Android Studio and published it on youtube. https://youtu.be/SCAOeAN3eU4 Let's put it here, maybe it will help someone. I performed the transaction I wanted with your support. Thank you very, very much. Regards. ---------------------------------------------------------------------- jmpessoa · 2021-02-05 21:39 QuoteI also prepared a video about the use of the .so file I created with LAMW in a project created from scratch in Android Studio and published it on youtube. https://youtu.be/SCAOeAN3eU4 Let's put it here, maybe it will help someone. Good Video! Alternatively you can open the LAMW project using "Android Studio" and continue your development.... ref. https://github.com/jmpessoa/lazandroidmodulewizard/blob/master/docs/Ho w_to_open_LAMW_project_with_AndroidStudio.txt ---------------------------------------------------------------------- loaded · 2021-02-06 06:37 I also examined that document. Health to your hands. Yes, LAMW projects are now very easy to use Androd Studio (thanks to you), you just need to do import projects. In fact, this convenience is thanks to your efforts.That you are very valuable and essential people, I understand. But in a project created and used in android studio, I just tried to explain the .so file, how to include and use it in the project. Regards.