Difference between revisions of "LAMW"

From Free Pascal wiki
Jump to navigationJump to search
Line 1: Line 1:
 
{{Platform only|Android|Android|Android}}
 
{{Platform only|Android|Android|Android}}
== Note ==
 
This page comes from the previous tutorial HOW_TO_INSTALL_by_Dieselnutjob.pdf (for Windows)
 
  
Now it is a Wiki you are welcome to update it when you are sure it works and/or helps.
+
[[Note|This page comes from the previous tutorial HOW_TO_INSTALL_by_Dieselnutjob.pdf (for Windows). Now it is a Wiki you are welcome to update it when you are sure it works and/or helps. Installation for Linux will be added later, for now you can checkout https://github.com/jmpessoa/lazandroidmodulewizard and read linux/new_how_to_install_by_renabor.txt.}}
  
Installation for Linux will be added later, for now you can checkout https://github.com/jmpessoa/lazandroidmodulewizard and read linux/new_how_to_install_by_renabor.txt.
+
'''LAMW''' is a set of ''Lazarus wizards'' you will launch from menus Build and Tools.
 
 
== What is LAMW ==
 
 
 
This is a set of ''Lazarus wizards'' you will launch from menus Build and Tools.
 
  
 
It helps to set parameters, organize libraries and to run the tools required to make APK files, used to install applications on '''Android'''.
 
It helps to set parameters, organize libraries and to run the tools required to make APK files, used to install applications on '''Android'''.
Line 16: Line 10:
  
 
== How to install on Windows ==
 
== How to install on Windows ==
 
 
This is working on Windows 8 and 10 Home Edition 64 bits.
 
This is working on Windows 8 and 10 Home Edition 64 bits.
  
Line 24: Line 17:
  
 
Download these files in the folder C:\lamw :
 
Download these files in the folder C:\lamw :
 
+
* [http://dl.google.com/android/android-sdk_r24.4.1-windows.zip SDK 24.4.1]
[http://dl.google.com/android/android-sdk_r24.4.1-windows.zip SDK 24.4.1]
+
* [http://dl.google.com/android/repository/android-ndk-r10e-windows-x86.zip NDK r10e]
 
+
* [http://archive.apache.org/dist/ant/binaries/apache-ant-1.9.6-bin.zip Ant 1.9.6]
[http://dl.google.com/android/repository/android-ndk-r10e-windows-x86.zip NDK r10e]
+
* [http://download.oracle.com/otn-pub/java/jdk/8u65-b14/jdk-8u65-windows-i586.exe jdk-8u65-windows-i586.exe Jdk 8u65]
 
+
* [https://sourceforge.net/projects/laz4android/files/laz4android1.5-50093-FPC3.1.1.7z/download Laz4Android 1.5-50093-FPC3.1.1]
[http://archive.apache.org/dist/ant/binaries/apache-ant-1.9.6-bin.zip Ant 1.9.6]
 
 
 
[http://download.oracle.com/otn-pub/java/jdk/8u65-b14/jdk-8u65-windows-i586.exe jdk-8u65-windows-i586.exe Jdk 8u65]
 
 
 
[https://sourceforge.net/projects/laz4android/files/laz4android1.5-50093-FPC3.1.1.7z/download Laz4Android 1.5-50093-FPC3.1.1]
 
  
 
[[File:lamw_download.png]]
 
[[File:lamw_download.png]]
Line 48: Line 36:
  
 
=== Get sources ===
 
=== Get sources ===
 
 
You must get LAMW sources using one of the 3 methods listed below. They contain the wizards and the 3 packages.
 
You must get LAMW sources using one of the 3 methods listed below. They contain the wizards and the 3 packages.
  
 
==== Checkout with a git client ====
 
==== Checkout with a git client ====
 
 
This is the preferred method. We use here Git Gui, but you can use other easier tools like Tortoise GIT.
 
This is the preferred method. We use here Git Gui, but you can use other easier tools like Tortoise GIT.
 
+
# create a folder C:\lamw\lazandroidmodulewizard
1) create a folder C:\lamw\lazandroidmodulewizard
+
# click right on this folder
 
+
# click "GIT Gui here"
2) click right on this folder
+
# click "Clone existing repository" and enter https://github.com/jmpessoa/lazandroidmodulewizard in the source location.
 
+
# select the folder C:\lamw\lazandroidmodulewizard
3) click "GIT Gui here"
 
 
 
4) click "Clone existing repository" and enter https://github.com/jmpessoa/lazandroidmodulewizard in the source location.
 
 
 
5) select the folder C:\lamw\lazandroidmodulewizard
 
  
 
[[File:lamw_git_checkout.png]]
 
[[File:lamw_git_checkout.png]]
  
 
==== Checkout with a svn client ====
 
==== Checkout with a svn client ====
 
 
Not sure this is still working...
 
Not sure this is still working...
  
 
With Tortoise SVN
 
With Tortoise SVN
 
+
: https://github.com/jmpessoa/lazandroidmodulewizard to C:\lamw\lazandroidmodulewizard
https://github.com/jmpessoa/lazandroidmodulewizard to C:\lamw\lazandroidmodulewizard
 
  
 
[[File:lamw_svn_checkout_1.png]]
 
[[File:lamw_svn_checkout_1.png]]
Line 80: Line 59:
  
 
==== Extract zip ====
 
==== Extract zip ====
 
 
An alternate method is to download [https://github.com/jmpessoa/lazandroidmodulewizard/archive/master.zip this zip file] in c:\lamw and to extract into the (default) folder C:\lamw\lazandroidmodulewizard
 
An alternate method is to download [https://github.com/jmpessoa/lazandroidmodulewizard/archive/master.zip this zip file] in c:\lamw and to extract into the (default) folder C:\lamw\lazandroidmodulewizard
  
Line 86: Line 64:
  
 
===Installations===
 
===Installations===
 
 
Extract android-sdk_r24.4.1-windows.zip in c:\lamw\android-sdk-windows
 
Extract android-sdk_r24.4.1-windows.zip in c:\lamw\android-sdk-windows
  
Line 99: Line 76:
 
[[file:lamw_java_sdk_install.png]]
 
[[file:lamw_java_sdk_install.png]]
  
'''Notes :'''
+
{{Notes|Depending on the tool you use to extract zip or 7z, be sure to have not the first folder twice. Something like c:\lamw\android-ndk-r10e-windows-x86\android-ndk-r10e-windows-x86 will lead to errors in the subsequent steps...}}
 
 
Depending on the tool you use to extract zip or 7z, be sure to have not the first folder twice.
 
 
 
Something like c:\lamw\android-ndk-r10e-windows-x86\android-ndk-r10e-windows-x86 will lead to errors in the subsequent steps...
 
  
 
===Update Java development kits ===
 
===Update Java development kits ===
  
 
run C:\lamw\android-sdk-windows\SDK Manager.exe
 
run C:\lamw\android-sdk-windows\SDK Manager.exe
 
 
# deselect Android N (API 23 N Preview)
 
# deselect Android N (API 23 N Preview)
 
# deselect Android 6.0 (API 23)
 
# deselect Android 6.0 (API 23)
Line 120: Line 92:
 
# Exit SDK Manager
 
# Exit SDK Manager
 
[[file:lamw_sdk_manager_1.png]]
 
[[file:lamw_sdk_manager_1.png]]
 
  
 
Run C:\lamw\android-sdk-windows\SDK Manager.exe again
 
Run C:\lamw\android-sdk-windows\SDK Manager.exe again
Line 136: Line 107:
  
 
===Build and prepare Laz4Android===
 
===Build and prepare Laz4Android===
 
 
Laz4Android is simply an instance of Lazarus.
 
Laz4Android is simply an instance of Lazarus.
  
Line 193: Line 163:
  
 
===Path settings===
 
===Path settings===
 
+
In Laz4Android:
In Laz4Android :
 
  
 
Tools -> [LAMW] Android Module Wizard -> Path settings
 
Tools -> [LAMW] Android Module Wizard -> Path settings
 
+
:Path to Java JDK: C:\Program Files (x86)\Java\jdk1.8.0_65
Path to Java JDK: C:\Program Files (x86)\Java\jdk1.8.0_65
+
:Path to Ant bin: C:\lamw\apache-ant-1.9.6\bin
Path to Ant bin: C:\lamw\apache-ant-1.9.6\bin
+
:Path to Android SDK: c:\lamw\android-sdk_r24.4.1-windows
Path to Android SDK: c:\lamw\android-sdk_r24.4.1-windows
+
:Path to Android NDK: C:\lamw\android-ndk-r10e
Path to Android NDK: C:\lamw\android-ndk-r10e
+
:NDK version: 10e
NDK version: 10e
+
:Path to Simonsay's templates: C:\lamw\lazandroidmodulewizard\trunk\java
Path to Simonsay's templates: C:\lamw\lazandroidmodulewizard\trunk\java
 
  
 
[[File:lamw_path_settings.png]]
 
[[File:lamw_path_settings.png]]
Line 212: Line 180:
  
 
===Create your first project===
 
===Create your first project===
 
 
In Laz4Android :
 
In Laz4Android :
  
Line 225: Line 192:
 
[[file:lamw_create_new_project.png]]
 
[[file:lamw_create_new_project.png]]
  
Path to Workspace [Projects Folder]: C:\lamw\projects
+
:Path to Workspace [Projects Folder]: C:\lamw\projects
New Project Name: LamwGUIProject1
+
:New Project Name: LamwGUIProject1
Default Package Name: org.lamw
+
:Default Package Name: org.lamw
Include "android-support-v4.jar": no
+
:Include "android-support-v4.jar": no
NDKPlatfom: 17
+
:NDKPlatfom: 17
MinSdkAPI: 17
+
:MinSdkAPI: 17
TargetSdkApi: 17
+
:TargetSdkApi: 17
Instruction: ARMv7a
+
:Instruction: ARMv7a
ARM Fpu: Soft
+
:ARM Fpu: Soft
Android Theme: DeviceDefault
+
:Android Theme: DeviceDefault
  
 
[[File:lamw_configure_project.png]]
 
[[File:lamw_configure_project.png]]
Line 251: Line 218:
  
 
Events OnClick, double click and add :
 
Events OnClick, double click and add :
 
+
<syntaxhighlight>
procedure TAndroidModule1.jButton1Click(Sender: TObject);
+
procedure TAndroidModule1.jButton1Click( Sender: TObject );
begin
+
begin
ShowMessage('Hello World');
+
  ShowMessage('Hello World');
end;
+
end;
 +
</syntaxhighlight>
  
 
File -> Save All
 
File -> Save All
Line 276: Line 244:
  
 
==Other demos==
 
==Other demos==
 
 
In C:\lamw\trunk\demos\Eclipse, you will find a lot of projects to help you with the available functionalities.
 
In C:\lamw\trunk\demos\Eclipse, you will find a lot of projects to help you with the available functionalities.
  
 
You have to :
 
You have to :
 
 
# Open the project file <project_name>/jni/controls.lpi
 
# Open the project file <project_name>/jni/controls.lpi
 
# Goto project options and change NDK paths according your installation  
 
# Goto project options and change NDK paths according your installation  

Revision as of 14:03, 7 August 2016

Android robot.svg

This article applies to Android only.

See also: Multiplatform Programming Guide

[[Note|This page comes from the previous tutorial HOW_TO_INSTALL_by_Dieselnutjob.pdf (for Windows). Now it is a Wiki you are welcome to update it when you are sure it works and/or helps. Installation for Linux will be added later, for now you can checkout https://github.com/jmpessoa/lazandroidmodulewizard and read linux/new_how_to_install_by_renabor.txt.}}

LAMW is a set of Lazarus wizards you will launch from menus Build and Tools.

It helps to set parameters, organize libraries and to run the tools required to make APK files, used to install applications on Android.

This installation includes several packages containing components useful to develop Android Programs with Lazarus, using JNI.

How to install on Windows

This is working on Windows 8 and 10 Home Edition 64 bits.

Downloads

Create folders C:\lamw and C:\lamw\projects

Download these files in the folder C:\lamw :

lamw download.png

Important Notes :

Versions specified here are currently working, although some of them are old and even hidden by their creator/publisher.

But the latest stable versions are not always compatible with the tool (NDK at least).

If a more recent stable version is found working well, please update the Wiki.

You may have already the kits installed somewhere else on your computer. It might lead to problems if you try to re-use them. The safer is to make new downloads in c:\lamw. Be aware to use the corresponding versions and do not use shortcuts previously installed with other versions.

Get sources

You must get LAMW sources using one of the 3 methods listed below. They contain the wizards and the 3 packages.

Checkout with a git client

This is the preferred method. We use here Git Gui, but you can use other easier tools like Tortoise GIT.

  1. create a folder C:\lamw\lazandroidmodulewizard
  2. click right on this folder
  3. click "GIT Gui here"
  4. click "Clone existing repository" and enter https://github.com/jmpessoa/lazandroidmodulewizard in the source location.
  5. select the folder C:\lamw\lazandroidmodulewizard

lamw git checkout.png

Checkout with a svn client

Not sure this is still working...

With Tortoise SVN

https://github.com/jmpessoa/lazandroidmodulewizard to C:\lamw\lazandroidmodulewizard

lamw svn checkout 1.png

lamw svn checkout 2.png

Extract zip

An alternate method is to download this zip file in c:\lamw and to extract into the (default) folder C:\lamw\lazandroidmodulewizard

You will have to do this often, because there are often LAMW updates, and you will not have any source manager functionalities to check quickly updates or to be involved into the project.

Installations

Extract android-sdk_r24.4.1-windows.zip in c:\lamw\android-sdk-windows

Extract android-ndk-r10e-windows-x86.zip in c:\lamw\android-ndk-r10e-windows-x86

Extract apache-ant-1.9.6-bin.zip in c:\lamw\apache-ant-1.9.6

Extract laz4android1.5-50093-FPC3.1.1.7z to C:\lamw\Laz4Android

Execute jdk-8u65-windows-i586.exe . It will install the JDK to C:\Program Files (x86)\Java\jdk1.8.0_65\

lamw java sdk install.png

Template:Notes

Update Java development kits

run C:\lamw\android-sdk-windows\SDK Manager.exe

  1. deselect Android N (API 23 N Preview)
  2. deselect Android 6.0 (API 23)
  3. select Android SDK Platform-tools
  4. select Android SDK Build-tools
  5. select Extras/Android Support Library [if found...]
  6. select Extras/Google USB Driver
  7. click Install 4 packages [3 packages if Android Support Library not found]
  8. Accept license and click Install
  9. wait for downloads to finish
  10. Exit SDK Manager

lamw sdk manager 1.png

Run C:\lamw\android-sdk-windows\SDK Manager.exe again

  1. deselect Android N (API 23 N Preview)
  2. deselect Android 6.0 (API 23)
  3. expand Android 4.2.2 (API 17)
  4. select SDK Platfrom
  5. select ARM EABI v7a System Image
  6. click Install 2 packages
  7. Accept license and click Install
  8. wait for downloads to finish
  9. Exit SDK manager

lamw sdk manager 2.png

Build and prepare Laz4Android

Laz4Android is simply an instance of Lazarus.

From Windows, run cmd, then :

cd \lamw\Laz4Android build.bat

lamw cmd laz4android 1.png

lamw cmd laz4android 2.png

When finished, exit cmd mode

Create a shortcut on your desktop for C:\lamw\laz4android\startlazarus.exe

Execute it

Start IDE

Package -> Open package file (.lpk)

select C:\lamw\lazandroidmodulewizard\trunk\tfpandroidbridge_pack.lpk

Compile

Use>> Install

Do you want to rebuid Lazarus now? Yes

Laz4Android will restart

Package -> Open package file (.lpk)

select C:\lamw\lazandroidmodulewizard\trunk\lazandroidwizardpack.lpk

Compile

Use>> Install

Do you want to rebuid Lazarus now? Yes

Laz4Android will restart

Package -> Open package file (.lpk)

select C:\lamw\lazandroidmodulewizard\trunk\ide_tools\amw_ide_tools.lpk

Compile

Use>> Install

Do you want to rebuid Lazarus now? Yes

Laz4Android will restart

Path settings

In Laz4Android:

Tools -> [LAMW] Android Module Wizard -> Path settings

Path to Java JDK: C:\Program Files (x86)\Java\jdk1.8.0_65
Path to Ant bin: C:\lamw\apache-ant-1.9.6\bin
Path to Android SDK: c:\lamw\android-sdk_r24.4.1-windows
Path to Android NDK: C:\lamw\android-ndk-r10e
NDK version: 10e
Path to Simonsay's templates: C:\lamw\lazandroidmodulewizard\trunk\java

lamw path settings.png

OK.

File -> Restart

Create your first project

In Laz4Android :

Project -> Close project [if necessary]

Project Wizard -> New project

Select JNI Android Module [Lamw GUI]

Click OK

lamw create new project.png

Path to Workspace [Projects Folder]: C:\lamw\projects
New Project Name: LamwGUIProject1
Default Package Name: org.lamw
Include "android-support-v4.jar": no
NDKPlatfom: 17
MinSdkAPI: 17
TargetSdkApi: 17
Instruction: ARMv7a
ARM Fpu: Soft
Android Theme: DeviceDefault

lamw configure project.png

Save unit1.pas

Click Save

Now, if you hover the mouse over any unit in uses clause, IDE will show an error message.

File -> Restart

After restart, if you hover the mouse over any unit in uses clause, IDE does not show error message anymore

Drag from Android Bridge a jButton onto form

Events OnClick, double click and add :

procedure TAndroidModule1.jButton1Click( Sender: TObject );
begin
  ShowMessage('Hello World');
end;

File -> Save All

Run -> Build

Target: C:\lamw\projects\LamwGUIProject1\libs\armeabi\libcontrol.so: Success

Note 1 : this Build step is not required, because it will be executed by the next one. However it can help to diagnose an issue.

Note 2 : Before next step, check your Android device is connected to the PC with an USB cable.

Run -> [Lamw] Build APK and run

Building APK...: Success

if ADB is working with your phone, the APK will then be copied, installed and run automatically !

Otherwise, copy C:\lamw\projects\LamwGUIProject1\bin\LamwGUIProject1-debug.apk to some folder of the Android device, and install this file using the device file manager.

Other demos

In C:\lamw\trunk\demos\Eclipse, you will find a lot of projects to help you with the available functionalities.

You have to :

  1. Open the project file <project_name>/jni/controls.lpi
  2. Goto project options and change NDK paths according your installation
  3. Project, Options, LAMW Project configuration and check the Target SDK API which must be the same as installed above.
  4. Run, Build the project. As the "Hello World" above, it should copy, install and run the application on the Android device.
  5. Try it !

If you get the message "Application has stopped", it can be useful to goto Tools, [LAMW] Android Module Wizard, Upgrade Code templates

Select the directory containing examples and a project and click "OK".

Then build again, and it should work !