Recent

Author Topic: Android Module Wizard  (Read 705412 times)

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #30 on: December 14, 2013, 07:57:19 pm »
Hi,

I Add new infos in Readme.txt,

About Package, Components and LCL  and NDK libs(.so) dependency on laz4android1.1-41139 IDE cross compiler...

1. Package creation: just LCLBase is permitted! not "LCL"!
   
   - You will nedd  LCLBase Required Package for register procedure.
   - yes, other No GUI stuff is permitted.

2. Component creation
   
    2.1. If you will use custom icon then you will need two files: the first to compoment(s) code
        and the second for Register procedure code.

        example:

    2.1.1. File 1 - "foo.pas" - component code - here no LCL dependency at all!

Code: [Select]
unit foo;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils;

type

TFoo = class(TComponent)
  private
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
end;


implementation

 
end.
       
  2.1.2. File 2 - "regtfoo.pas" - register code -  here you will need LCLBase for LResources unit

Code: [Select]
        unit regtfoo;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources{ here is the LCLBase dependency!};

Procedure Register;

implementation

Procedure Register;
begin

  {$I tfoo_icon.lrs}  //you custom icon

  RegisterComponents('Android Bridges',[TFoo);

end;

initialization

end.   

3. NDK libs (.so) dependency on laz4android1.1-41139 IDE cross compiler
     

3.1.  You will need two files: the first to NDK *.so lib interface and the second for you component/unit code.

   Example:


   3.1.1. File 1 - "And_log_h.pas" the header interface file
 
Code: [Select]
unit And_log_h;

{$mode delphi}

interface

const libname='liblog.so';

  ANDROID_LOG_UNKNOWN=0;
      ANDROID_LOG_DEFAULT=1;
      ANDROID_LOG_VERBOSE=2;
      ANDROID_LOG_DEBUG=3;
      ANDROID_LOG_INFO=4;
      ANDROID_LOG_WARN=5;
      ANDROID_LOG_ERROR=6;
      ANDROID_LOG_FATAL=7;
      ANDROID_LOG_SILENT=8;

type

  android_LogPriority=integer;

  function __android_log_write(prio:longint; tag,text: pchar):longint; cdecl; external libname name '__android_log_write';

  function LOGI(prio:longint;tag,text:pchar):longint; cdecl; varargs; external libname name '__android_log_print';


implementation

end.

   
      3.1.2. File 2 - "And_log.pas" component/unit code

Code: [Select]
unit And_log;

interface

uses
   And_log_h;  // <-- here is the link to NDK lib

procedure log(msg: pchar);

implementation

procedure log(msg: pchar);
begin
          __android_log_write(ANDROID_LOG_FATAL,'crap',msg);
end;

end.

Thank you.
« Last Edit: December 15, 2013, 05:36:11 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Android Module Wizard
« Reply #31 on: December 15, 2013, 05:03:07 am »
Quote
Linux?

I haven't gone that far too...  :D :(  :-[
I don't think this should be locked to certain platform, if it could work on Windows, it should work on any other supported OS.
Quote
1. At the moment "lazandroidwizardpack.lpk" has a simple Windows dependency

the '/'  separator! I will fix this! (Edit: Directory Separator was Fix! )
Simple, isn't it? The cross platform constants are in the System unit ;)
Quote
2. The  "tfpandroidbridge_pack.lpk" I don't remember, I will see. (Edit: No problem found!)

What *.lpk  is you trying?
Both.
lazandroidmodulewizard has implicit dependencies on jnigraphics in androidwizard_intf due to its dependency on Android_jni_bridge via Laz_And_Controls unit. While tfpandroidbridge has dependencies on all of those .so (GLESv2, GLESv1_CM, jnigraphics, log).

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #32 on: December 15, 2013, 05:30:21 am »
@Leledumbo

Yes,

I have this problem too on windows and laz4android1.1-41139 cross compile... my solution was that I wrote in my post  up ;D 

Code: [Select]
About Package, Components and LCL  and NDK libs(.so) dependency on laz4android1.1-41139 IDE cross compiler...

And with this strategies it was resolved on windows!

But I learned something else ... before installing a package I close my cross compile project and open a "dummy" windows project....

And so things are working... but on linux it seems that the behavior is another ...

 :'(

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

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Android Module Wizard
« Reply #33 on: December 15, 2013, 06:20:39 am »
I'm going to check what laz4android does so that the IDE can link to those .so

EDIT: it doesn't seem to have anything to do with laz4android, so it's purely tfpandroidbridge problem. On Windows, shared library doesn't have to exist upon linking. While on *nix, it's a must. I need to find a workaround for this.
« Last Edit: December 15, 2013, 07:37:10 am by Leledumbo »

zariq

  • Full Member
  • ***
  • Posts: 109
Re: Android Module Wizard
« Reply #34 on: December 15, 2013, 04:54:09 pm »
Hi.

Copied appdemo1 onto phone, looks nice. Must have taken a lot of work, jni is very laborious. Just a few of minor points.

I couldn't get the back key to work from the main (menu) form.  I had to press the home key, which leaves it paused in the background or kill it from task manager.

Pressing the return key in edittext inserts a line but also hides the keynoard. That should only happen if it's a "done" or "go".

Just incase you forget imageview needs scaletype implementing. FIT_XY distorts the image if the imageview is larger but wrong scale.

Thanks.

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #35 on: December 15, 2013, 04:56:56 pm »
@Leledumbo,
 
Yes, After many experimentations, I  found a workaround for Windows just as posted up: ;D

Quote
About Package, Components and LCL  and NDK libs(.so) dependency on laz4android1.1-41139 IDE cross compiler...

Thank you.

« Last Edit: December 15, 2013, 04:59:30 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #36 on: December 15, 2013, 05:12:07 pm »
@zariq,

Thank you for the experimentation...

Yes, and our work is just beginning ... I am learning
yet!  surely every collaboration is welcome! JNI is hard and our task is build a RAD environment for android too, Lazarus is about it!

About:
Quote
I couldn't get the back key to work from the main (menu) form.

I will try a solution.

Best regards.



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

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #37 on: December 16, 2013, 11:41:48 pm »
Hi All,

Yes, Ant support almost ready!

I got:

1. Compile/Build ---> I got the Apk!
2. Install in Emulator
3. Uninstall from Emulator

But when I run App from Emulator I got:
Quote
E/AndroidRuntime(  913):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime(  913):        at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  913): Caused by: java.lang.NoClassDefFoundError: Controls

E/AndroidRuntime(  913):        at java.lang.Runtime.nativeLoad(Native Method)
E/AndroidRuntime(  913):        at java.lang.Runtime.loadLibrary(Runtime.java:369)
E/AndroidRuntime(  913):        at java.lang.System.loadLibrary(System.java:535)
E/AndroidRuntime(  913):        at lazarus.org.appantdemo1.Controls.<clinit>(Controls.java:3948)
E/AndroidRuntime(  913):        ... 15 more
E/AndroidRuntime(  913): Caused by: java.lang.ClassNotFoundException: Didn't find class "Controls" on path: /data/app/lazarus.org.appantdemo1-1.apk

E/AndroidRuntime(  913):        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
E/AndroidRuntime(  913):        at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
E/AndroidRuntime(  913):        at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
E/AndroidRuntime(  913):        ... 19 more

My build.xml is simply:
Code: [Select]
<?xml version="1.0" encoding="UTF-8"?>
  <project name="AppAntDemo1" default="help">
  <property name="sdk.dir" location = "C:\adt32\sdk"/>
  <property name="target"  value="android-17"/>
  <property file="ant.properties"/>
  <fail message="sdk.dir is missing." unless="sdk.dir"/>
  <import file="${sdk.dir}\tools\ant\build.xml"/>
</project>

Something was forgotten to bind  my native "libcontrols.so" on Apk?

Thank You.

Edit: I found this:
Quote
  It turns out that this was a bug in the Android SDK. The release notes of r18 say:

  "Fixed Ant issues where some jar libraries in the libs/ folder are not picked up in some cases."

  Since updating from r17 to r19 fixed the problem for me, this was very likely the cause of the problem.

Ref. http://stackoverflow.com/questions/9944698/why-is-the-android-support-library-not-added-to-my-apk

I will update my SDK r17 for r19 too, and try again!

Edit2: While I wait for my SDK update, I ran:

aapt.exe list AppAntDemo1-debug.apk, and for my surprise:
Quote
res/layout/activity_app.xml
AndroidManifest.xml
resources.arsc
res/drawable-hdpi/ic_launcher.png
res/drawable-ldpi/ic_launcher.png
res/drawable-mdpi/ic_launcher.png
res/drawable-xhdpi/ic_launcher.png
res/drawable-xxhdpi/ic_launcher.png
classes.dex
lib/armeabi/libcontrols.so    <<----------- yes !
META-INF/MANIFEST.MF
META-INF/CERT.SF
META-INF/CERT.RSA

My libcontrols.ao is there! Then, what is incorrect  in my apk?
« Last Edit: December 17, 2013, 07:35:51 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

zariq

  • Full Member
  • ***
  • Posts: 109
Re: Android Module Wizard
« Reply #38 on: December 18, 2013, 02:36:12 am »
 Didn't find class "Controls"

In the version I downloaded you had controls with a small c.

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #39 on: December 18, 2013, 04:21:05 am »
@Zarik,

thank you for replay.

I have a file  "Controls.java" and a class "Controls":
Code: [Select]
//------------------------------------------------------------------------------
//Javas/Pascal Interface Class
//------------------------------------------------------------------------------
//!!!! classcontrols 
//
public  class Controls {
//
public   Activity       activity;            // Activity
public   RelativeLayout appLayout;           // Base Layout
public   int            screenStyle = 0;     // Screen Style [Dev:0 , Portrait: 1, Landscape : 2]

// Jave -> Pascal Function ( Pascal Side = Event )
public  native int  pAppOnScreenStyle();
public  native void pAppOnCreate     (Context context,RelativeLayout layout);
public  native void pAppOnNewIntent  ();
public  native void pAppOnDestroy    ();
public  native void pAppOnPause      ();
public  native void pAppOnRestart    ();
public  native void pAppOnResume     ();
public  native void pAppOnActive     ();
public  native void pAppOnStop       ();
public  native void pAppOnBackPressed();
public  native int  pAppOnRotate     (int rotate);
public  native void pAppOnConfigurationChanged();
public  native void pAppOnActivityResult(int requestCode, int resultCode, Intent data);
//
public  native void pOnClick     (int pasobj, int value);
public  native void pOnChange    (int pasobj, int EventType);
public  native void pOnEnter     (int pasobj);
public  native void pOnTimer     (int pasobj);
//
public  native void pOnDraw      (int pasobj, Canvas canvas);
public  native void pOnTouch     (int pasobj, int act, int cnt,float x1, float y1,float x2, float y2);
public  native void pOnGLRenderer(int pasobj, int EventType, int w, int h);
//
public  native void pOnClose     (int actform);
//
public  native int  pOnWebViewStatus (int pasobj, int EventType, String url);
public  native void pOnAsyncEvent    (int pasobj, int EventType, int progress);

// Load Pascal Library
static {
    Log.i("JNI_Java", "1.load libcontrols.so");
    System.loadLibrary("controls");
    Log.i("JNI_Java", "2.load libcontrols.so");
   
}

Yes, there is a small "control" in System.loadLibrary("controls").....

And more, in my /bin/classes I got the compiled  "Controls.class"!  %)
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #40 on: December 19, 2013, 07:49:32 pm »
Yes,  after a complete cleanup in my Android SDK, the problem was solved! 8-)

The support for Ant project is on the way!

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

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Android Module Wizard
« Reply #41 on: December 20, 2013, 07:31:20 am »
I'm still struggling to make the package installable on Linux. It's kinda weird actually since, for example, the And_Bitmap_h functions called links to libjnigraphics.so which is part of the TARGET (Android), the HOST (Linux) shouldn't need it. Even if it should, which libjnigraphics.so should the IDE link to? x86? arm? Neither is right, since the .so is not meant for the HOST.

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #42 on: December 22, 2013, 08:12:44 am »
Hi All,

Android Module Wizard Ver. 0.3 -  Introduces Support to Ant Project!

Now you can manage the entire cycle of application development just
using Lazarus  and native tools:  jdk, ant, sdk and ndk.

You can get here:

         http://wwww.github.com/jmpessoa

For a complete description, please, read the updated "readme.txt"

Attached below the new entry form for project and paths configuration...

Thank to all!

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

Sergionn

  • New member
  • *
  • Posts: 8
Re: Android Module Wizard
« Reply #43 on: December 22, 2013, 08:36:47 am »
Jmpessoa, yor are good for strugging for pascal's future by doing this. Thank you!
But give you you little advice:
1) Simplify all STEPS to do to archive the result, it should be like this:
 a) install packadge
 b) load project
 c) build it
 - thats it, until this it will be more easy to make android apps in andoid studio or eclipse or whatever
 and even to study java not such commplicated quest compared by following all instructions in readme file of your project........
 and please remove eclipse projects and any dependency about it for simpify

« Last Edit: December 22, 2013, 08:42:51 am by Sergionn »

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #44 on: December 22, 2013, 03:42:21 pm »
@Sergionn, thaks for your advice:

I will, split "readme.txt": one for Eclipse users and other for Ant users.... I hope  so things will be less complicated... the fact is that there is still a java background in development (Simon's "Control.java" + "App.java") and so support the eclipse help much ...

Thank you!




 
« Last Edit: December 22, 2013, 03:44:44 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

 

TinyPortal © 2005-2018