Recent

Author Topic: Android Module Wizard  (Read 707700 times)

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
Re: Android Module Wizard
« Reply #300 on: February 25, 2015, 12:42:18 am »
Hi @rx3,

I  will try implement yours suggestions!

Thank you!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
Re: Android Module Wizard
« Reply #301 on: February 25, 2015, 02:27:42 am »
Hi @Stephano,

Quote
...let's say somebody sends me a libcontrols1.so (produced using lawm) and I want to use it either with lawm (or some other tool). My question is how to use it with lawm ....

Quote
a- the java code make the calls to libcontrols1.so
b- the pascal code make the calls to libcontrols1.so ...

After some tests, I can share/show my findings:

1. As case study [simplification!] I make use of a very simple "libMyLib.so" 
[Ok, it was made by pure NDK using "C"]

You can get from here: https://jmpessoa.opendrive.com/files?Ml83NzE5Mjk1NV95QmRpUw 

The produce project [.rar] is here: https://jmpessoa.opendrive.com/files?Ml83NzE5MzU4OV9MTFZjMg

Why not a ".so" made by Lamw? Only because at the moment [as is] Lamw can not do a very very "raw" .so  [TODO list!] --- but everything written here works with a ".so"produced by Pascal/Lamw!

2. Here is the "MyLib.java" code:

Code: [Select]
package jmpessoa.ndktest;

public class MyLib {

   static {
        System.loadLibrary("MyLib");
    }

    public native int add(int x, int y);
    public native String getHello();
}

And here is the JNI "C" export  signature : [by libMyLib.so]
Code: [Select]
JNIEXPORT jint JNICALL Java_jmpessoa_ndktest_MyLib_add(JNIEnv *, jobject, jint, jint);
JNIEXPORT jstring JNICALL Java_jmpessoa_ndktest_MyLib_getHello(JNIEnv *, jobject);

And here is the JNI "Pascal/Lamw" equivalent exports signature:
Code: [Select]
function Java_jmpessoa_ndktest_MyLib_add(PEnv: PJNIEnv; this: JObject;  x:jInt, y:jInt): jInt;
function Java_jmpessoa_ndktest_MyLib_getHello(PEnv: PJNIEnv; this: JObject): jString;

Yes, this method name format is mandatory for JNI "Java_pagckagename_classname_methodname"

Question b [SOLVED!!!]: the Pascal/Lamw code can make calls to "libMyLib.so" !!

b.1 - Prepare to Linker [-Fl]

In my system I  Copied the "libMyLib.so" to C:\adt32\ndk10\platforms\android-13\arch-arm\usr\lib\

b.2 - Prepare to Apk

Copy "libMyLib.so"   to  "..\libs" yes, together with "libcontrols.so"

b.3 - Declare the library and methods in your Pascal/Lamw code:

Quote
const NATIVE_LIB = 'libMyLib.so';

function Add(PEnv: PJNIEnv; this: jObject; x: jInt; y:jInt): jInt; cdecl; external NATIVE_LIB name 'Java_jmpessoa_ndktest_MyLib_add';

function GetHello(PEnv: PJNIEnv; this: jObject): jString; cdecl; external NATIVE_LIB name 'Java_jmpessoa_ndktest_MyLib_getHello';

b.3 - Use it!

Code: [Select]
procedure TAndroidModule1.jButton1Click(Sender: TObject);
var
  sum: integer;
  hello: string;
begin
   sum:= Add(gApp.Jni.jEnv,gApp.Jni.jThis,10,20);
   ShowMessage(IntTostr(sum));
   
   hello:= Get_pString( GetHello(gApp.Jni.jEnv,gApp.Jni.jThis) );
   ShowMessage(hello);

   //Get_pString <--> convert java string to pascal string   
end;

Yes!! Pascal/Lamw can use it!!

Considerations: in fact Pacal/Lamw no matter how the function name/signature was "designate" [exports],  so we can use any ".so" compiled to android/arm/x86 etc... even more complex made by Lamw!

Question a:  the java code make the calls to libMyLib.so

a.1 In the same/"natural" package [ no problem ....] just copy it to "...\libs"    and use it!

Code: [Select]
package jmpessoa.ndktest;

public class MainActivity extends Activity {

       //From JNI
       MyLib mylib = new MyLib();       
   
    String helloFromC = mylib.getHello();
    int sum = mylib.add(2,5);

    ...........................
}

a.2 In the "strange" package: NOT!!!

why? the original exported name JNI preface: "Java_jmpessoa_ndktest_"  need match!

Code: [Select]
package strange.test;

public class MyLib {

   static {
        System.loadLibrary("MyLib");
    }

    public native int add(int x, int y);
    public native String getHello();
}

Fail! Native method not found!
because: "Java_strange_test_MyLib_add"  and "Java_strange_test_MyLib_getHello" was expected but "Java_jmpessoa_ndktest_*" was found!

[workaround] You can force and design [your new project]  package "preface.name" as expected, that is: "jmpessoa.ndktest"!

conclusion: native Pascal/Lamw can do! java? need a workaround...

Thank you!

« Last Edit: February 25, 2015, 03:00:36 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

truetom

  • Jr. Member
  • **
  • Posts: 73
    • http://sourceforge.net/projects/laz4android/
Re: Android Module Wizard
« Reply #302 on: February 25, 2015, 03:16:57 pm »
Thank you jmpessoa, this is a great job!

Hello all,

I have updated laz4android to new version.

You can download from here:
http://sourceforge.net/projects/laz4android/

Laz4Android is a Lazarus for Android Package.
Thanks the FreePascal team and the Lazarus team.
Now Laz4Android is only run Windows.Sorry for this!

-------------------------------------------------------------------------------------
Last update:2015-02-25
FPC: 3.1.1 trunk svn 29987 win32/arm-android/i386-android/jvm-android
Lazarus:1.5 trunk svn 47987
Android NDK: r10c (arm-linux-androideabi-4.6 + x86-4.6)

===============================================
Update history:
2014-04-05:
1.Fixed Android application crash problem,thanks DelphiFreak and Leslie.
-------------------------------------------------------------------------------------
2014-10-18:
FPC: 2.7.1 trunk svn 28863 win32/arm-android/i386-android/jvm-android
Lazarus:1.3 trunk svn 46592
Android NDK: r10c (arm-linux-androideabi-4.6 + x86-4.6)
1.Fixed examples\androidlcl,now it can compatible with this version.
2.Compatible with Jmpessoa's LazAndroidModuleWizard,thanks Jmpessoa and Simonsays,links:
  https://github.com/jmpessoa/lazandroidmodulewizard
  http://forum.lazarus.freepascal.org/index.php/topic,21919.0.html
-------------------------------------------------------------------------------------
2015-02-25:
FPC: 3.1.1 trunk svn 29987 win32/arm-android/i386-android/jvm-android
Lazarus:1.5 trunk svn 47987
Android NDK: r10c (arm-linux-androideabi-4.6 + x86-4.6)
1.Fixed examples\androidlcl\build_debug_apk.bat,now it can use JDK1.7 or JDK1.8 to Signing the APK.

===============================================
How to install Laz4Android?

1.You can download a installer file from here:
http://sourceforge.net/projects/laz4android/files/?source=navbar
- Double click the installer file
- Next , Next to finished.

-------------------------------------------------------------------------------------
2.You can download a 7z compressed file from here:
http://sourceforge.net/projects/laz4android/files/?source=navbar
- Unzip 7z file to e.g.  c:\laz4android
- Edit the file c:\laz4android\build.bat like this:

  SET FPC_BIN_PATH=c:\laz4android

Please run build.bat (double click it), it will compile and build lazarus.
===============================================

Thanks and best regards!
laz4android : a Lazarus for Android Package.
http://sourceforge.net/projects/laz4android/

rx3.fireproof

  • New Member
  • *
  • Posts: 49
Re: Android Module Wizard
« Reply #303 on: February 27, 2015, 11:27:10 am »
@truetom

Thank you very much!
 
Everything works on old projects.

There is one problem. Can't create a new project Lamw. Returned version 1.3

With Respect

rx3.fireproof
« Last Edit: March 10, 2015, 09:53:58 am by rx3.fireproof »

Stephano

  • New Member
  • *
  • Posts: 32
Re: Android Module Wizard
« Reply #304 on: February 27, 2015, 08:01:46 pm »
@jmpessoa,
What do you mean by very very raw .so that Lawm cannot produce?
1- A pure Pascal library?
2- A pure Pascal library that makes jni calls?
3- A library that makes pascal code and jni calls and includes java code (for overriding methods)?

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
Re: Android Module Wizard
« Reply #305 on: February 27, 2015, 10:53:55 pm »
@Stephano,

Nothing like that ....I want to say:

As is,  the  minimalistic libray code produced by Lamw include:

TCustomApplication
TDataModule

as posted in  February 22, 2015, 04:05:46 pm explication ....

When, in fact,  in some cases, minimalistic code like below, could be enough [TODO list!]:  [basically to reuse and/or modularization]

Code: [Select]
library jhelloadder;  //[by LazAndroidWizard: 2/22/2015 4:52:05]

{$mode delphi}

uses
  Classes, SysUtils, jni;

function Add(PEnv: PJNIEnv; this: JObject; _a: JInt; _b: JInt): JInt; cdecl;
begin
  {your code....}
  Result:= _a + _b;
end;

function StringUpperCase(PEnv: PJNIEnv; this: JObject; _str: JString): JString; cdecl;
var
  _jboolean: jBoolean;
  pascalStr: string;
begin
  {your code....}
  case _str = nil of
    True : pascalStr:= '';
    False: begin
          _jboolean := JNI_False;
           pascalStr:= string(  PEnv^.GetStringUTFChars(PEnv,_str,_jboolean));
         end;
  end;
  Result:= PEnv^.NewStringUTF(PEnv, PChar(Uppercase(pascalStr)));  ;
end;

function JNI_OnLoad(VM: PJavaVM; reserved: pointer): JInt; cdecl;
var
 PEnv: PPointer;
begin
  PEnv:= nil;
  Result:= JNI_VERSION_1_6;
  (VM^).GetEnv(VM, @PEnv, Result);
end;

procedure JNI_OnUnload(VM: PJavaVM; reserved: pointer); cdecl;
begin
   //
end;

exports
  JNI_OnLoad name 'JNI_OnLoad',
  JNI_OnUnload name 'JNI_OnUnload',
  Add name 'Add',
  StringUpperCase name 'StringUpperCase';

begin
  //
end.   

At the moment to achieve this minimalistic code we need to strip the Lamw generated code...
But, again: everything written there/previous  ;D  works with any ".so" produced by Pascal/Lamw! Although they are more complex ...
« Last Edit: February 28, 2015, 07:24:49 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

simonsayz

  • New Member
  • *
  • Posts: 27
Re: Android Module Wizard
« Reply #306 on: March 01, 2015, 03:19:48 pm »
@jmpessoa
Really thanks for reply last year. :)
It's very helpful for me. and very sorry for the not supporting the Android Module Wizard' project.

I am starting to rewrite the base library.

Ref. http://blog.naver.com/simonsayz 
And_Controls_v0.26.zip (4.6MB)
- And_Controls : Conceptual Version (minimal, how to works)
- And_Controls : Modified Version
- Specification Doc (pptx)
- Sample App's Apk

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
Re: Android Module Wizard
« Reply #307 on: March 01, 2015, 05:00:04 pm »
Hi simonsayz!

Congratulations!!! Great Work!

I will try merge/adapt the news from  "And_controls_v0.26" and the news Demos to
Lamw/Android Module Wizard.

Thank you very much!
« Last Edit: March 01, 2015, 05:08:40 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

simonsayz

  • New Member
  • *
  • Posts: 27
Re: Android Module Wizard
« Reply #308 on: March 02, 2015, 03:10:36 am »
@jmpessoa

Thanks you. and sorry for the beta version always.
I will merge to your updated controls too.

iOS 64bit FPC Compiler was released by Jonas Maebe in last week.
So, My Plan is making the general mobile framework for FPC,Delphi

Maybe ... :)
And_Controls + iOS_Controls = XCL_Controls

Best Regards
Simon,Choi
« Last Edit: March 02, 2015, 03:12:20 am by simonsayz »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Android Module Wizard
« Reply #309 on: March 02, 2015, 05:25:25 am »
And_Controls + iOS_Controls = XCL_Controls
If you can create LCL backends with them too, we can have single source codebase for these platforms shared with desktop ones ;)

simonsayz

  • New Member
  • *
  • Posts: 27
Re: Android Module Wizard
« Reply #310 on: March 02, 2015, 08:23:34 am »
@Leledumbo

Verry Sorry and Thanks.

I'am just programmer with Free Pascal Compiler related "How it's works".
and, Prof jmpessoa has being released and updated the every version in last year.

And so, me and Jang want to remain the man on the supporter of Android module wizard.

But we (simon and jang) are working for the foward.

Thanks.
Simon and Jang
« Last Edit: March 02, 2015, 08:26:49 am by simonsayz »

rx3.fireproof

  • New Member
  • *
  • Posts: 49
Re: Android Module Wizard
« Reply #311 on: March 02, 2015, 11:16:39 am »
Thanks for jIntentManager. Intents very easy to use.

With Respect

rx3.fireproof
« Last Edit: March 02, 2015, 11:19:34 am by rx3.fireproof »

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
Re: Android Module Wizard
« Reply #312 on: March 09, 2015, 07:41:50 pm »
Hi All!

I updated Lamw: Lazarus Android Module Wizard [MINOR CHANGES]

Version 0.6 - rev. 19 - 09 March 2015 -
   
   NEWS
      jControl: Added Method: AttachCurrentThread

      jHttpClient: Added Methods: PostNameValueData   

      jEditText: Added Methods:   
            SetAcceptSuggestion
            CopyToClipboard
            PasteFromClipboard
            Clear
      
   NEW! Demo AppAsyncTaskDemo1   [Eclipse Compatible Project]   
   NEW! Demo AppHttpClientDemo1   [Eclipse Compatible Project]   

   FIXs:   
           jAsyncTask
      jHttpClient

Thank to All!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

A.S.

  • Jr. Member
  • **
  • Posts: 76
Re: Android Module Wizard
« Reply #313 on: March 10, 2015, 07:24:06 pm »
Hello to all!
Is it possible to simulate (by program) hardware "back" button pressing?

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
Re: Android Module Wizard
« Reply #314 on: March 10, 2015, 11:51:47 pm »

In some cases you can try just:

Code: [Select]
  gApp.Finish;    //gApp --> global android App --> MainActivity


Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

 

TinyPortal © 2005-2018