Difference between revisions of "Android tutorial"

From Free Pascal wiki
(Created page with "=Windows= I have made a quick tutorial on how to create android apps with Lazarus. In this tutorial i am using JDK 1.6u45 + SDK 22.2.1 + ndk-r9 + Laz4Android1.1-41139-FPC2.7....")
 
Line 1: Line 1:
 
=Windows=
 
=Windows=
  
I have made a quick tutorial on how to create android apps with Lazarus.
+
This is a quick tutorial on how to create android apps with Lazarus.
In this tutorial i am using JDK 1.6u45 + SDK 22.2.1 + ndk-r9 + Laz4Android1.1-41139-FPC2.7.1
 
  
1)Create on C:\ a folder called "Android"
+
In this tutorial assume used versions JDK 1.6u45 + SDK 22.2.1 + ndk-r9 + Laz4Android1.1-41139-FPC2.7.1
 +
 
 +
==Prepare folder==
 +
Create on C:\ a folder called "Android"
 +
 
 +
==Install JDK==
 +
1.6u45 (i have installed jdk-6u45-windows-x64.exe)
  
2)Install JDK 1.6u45 (i have installed jdk-6u45-windows-x64.exe)
 
 
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html#jdk-6u45-oth-JPR
 
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html#jdk-6u45-oth-JPR
 +
 
It will be installed in to C:\Program Files\Java\.
 
It will be installed in to C:\Program Files\Java\.
  
3) Installing SDK ...
+
==Installing SDK==
 
Go to http://developer.android.com/sdk/index.html
 
Go to http://developer.android.com/sdk/index.html
 +
 
DOWNLOAD FOR OTHER PLATFORMS > SDK Tools Only
 
DOWNLOAD FOR OTHER PLATFORMS > SDK Tools Only
 +
 
installer_r22.2.1-windows.exe (Recommended)
 
installer_r22.2.1-windows.exe (Recommended)
 +
 
Install sdk (installer_r22.2.1-windows) into C:\Android\android-sdk
 
Install sdk (installer_r22.2.1-windows) into C:\Android\android-sdk
 +
 
Copy at "C:\Android\android-sdk\tools" the file "apkbuilder.bat" (can be found here
 
Copy at "C:\Android\android-sdk\tools" the file "apkbuilder.bat" (can be found here
 +
 
https://github.com/ACSOP/android_sdk/raw/master/apkbuilder/etc/apkbuilder.bat )
 
https://github.com/ACSOP/android_sdk/raw/master/apkbuilder/etc/apkbuilder.bat )
  
 
Now update the SDK [WIN START > SDK Manager ]
 
Now update the SDK [WIN START > SDK Manager ]
 +
 
add android 4.0 (API 14)
 
add android 4.0 (API 14)
 +
 
add android 2.2 (API 8]
 
add android 2.2 (API 8]
 +
 
Install packages.
 
Install packages.
  
4) Installing NDK ...
+
==Installing NDK==
 
http://developer.android.com/tools/sdk/ndk/index.html
 
http://developer.android.com/tools/sdk/ndk/index.html
 +
 
Download only the file android-ndk-r9-windows-x86.zip
 
Download only the file android-ndk-r9-windows-x86.zip
 +
 
Unzip android-ndk-r9-windows-x86.zip into C:\Android\android-ndk-r9
 
Unzip android-ndk-r9-windows-x86.zip into C:\Android\android-ndk-r9
  
5) Installing Laz4Android1.1-41139-FPC2.7.1.7z ...
+
 
 +
==Installing Laz4Android1.1-41139-FPC2.7.1.7z==
 
Download it from https://skydrive.live.com/?cid=89ae6b50650182c6&id=89AE6B50650182C6!149
 
Download it from https://skydrive.live.com/?cid=89ae6b50650182c6&id=89AE6B50650182C6!149
 +
 
Unzip Laz4Android1.1-41139-FPC2.7.1.7z into C:\Android\laz4android
 
Unzip Laz4Android1.1-41139-FPC2.7.1.7z into C:\Android\laz4android
 +
 
Copy
 
Copy
 +
 
C:\Android\android-ndk-r9\toolchains\arm-linux-androideabi-4.6\prebuilt\windows\bin\arm-linux-androideabi-*.exe
 
C:\Android\android-ndk-r9\toolchains\arm-linux-androideabi-4.6\prebuilt\windows\bin\arm-linux-androideabi-*.exe
 +
 
to
 
to
 +
 
C:\Android\laz4android\fpc\2.7.1\bin\i386-win32\*
 
C:\Android\laz4android\fpc\2.7.1\bin\i386-win32\*
  
 
Edit the file C:\Android\laz4android\build.bat like this :
 
Edit the file C:\Android\laz4android\build.bat like this :
 +
 +
<syntaxhighlight lang="dos">
 
SET FPC_BIN_PATH=C:\Android\laz4android
 
SET FPC_BIN_PATH=C:\Android\laz4android
 +
</syntaxhighlight>
 +
 
Run build.bat (doubleclick) ->  It will compile & bulid lazarus.
 
Run build.bat (doubleclick) ->  It will compile & bulid lazarus.
  
6) Rebuilding Laz4Android IDE ...
+
 
 +
==Rebuilding Laz4Android IDE==
 
Run C:\Android\laz4android\lazarus.exe
 
Run C:\Android\laz4android\lazarus.exe
 +
 
Select "Start IDE"
 
Select "Start IDE"
 +
 
select "Package" "Install/Uninstall Packages"
 
select "Package" "Install/Uninstall Packages"
 +
 
select customdrawn 0.0 > install selection and hit save and rebuild IDE , continue
 
select customdrawn 0.0 > install selection and hit save and rebuild IDE , continue
  
7) Compiling the demo "androidlcl"
+
 
 +
==Compiling the demo "androidlcl"==
 
Copy C:\Android\laz4android\examples\androidlcl at D:\Projects\android\androidlcl
 
Copy C:\Android\laz4android\examples\androidlcl at D:\Projects\android\androidlcl
 +
 
Run "C:\Android\laz4android\lazarus.exe"
 
Run "C:\Android\laz4android\lazarus.exe"
 +
 
File > open "D:\Projects\android\androidlcl\androidlcltest.lpr"
 
File > open "D:\Projects\android\androidlcl\androidlcltest.lpr"
 +
 
Project > project options
 
Project > project options
  
Line 80: Line 113:
 
D:\Projects\android\androidlcl\android\libs\armeabi\liblclapp.so [5.073 kb]
 
D:\Projects\android\androidlcl\android\libs\armeabi\liblclapp.so [5.073 kb]
  
8] Deployment ...
+
 
a) Edit with a text editor
+
==Deployment==
 +
 
 +
* Edit with a text editor
 
D:\Projects\android\androidlcl\android\generate_debug_key.bat
 
D:\Projects\android\androidlcl\android\generate_debug_key.bat
 +
 
Modify the first 6 lines like this :
 
Modify the first 6 lines like this :
Code: [Select]
 
  
 +
<syntaxhighlight lang="dos">
 
REM Adjust these paths to yours
 
REM Adjust these paths to yours
 
SET PATH=C:\Android\android-sdk\tools;C:\Android\android-sdk\build-tools\17.0.0;C:\Android\android-sdk\platform-tools\;C:\Progra~1\Java\jdk1.6.0_45\bin
 
SET PATH=C:\Android\android-sdk\tools;C:\Android\android-sdk\build-tools\17.0.0;C:\Android\android-sdk\platform-tools\;C:\Progra~1\Java\jdk1.6.0_45\bin
Line 92: Line 128:
 
SET APK_SDK_PLATFORM=C:\Android\android-sdk\platforms\android-8
 
SET APK_SDK_PLATFORM=C:\Android\android-sdk\platforms\android-8
 
SET APK_PROJECT_PATH=D:\Projects\android\androidlcl\android
 
SET APK_PROJECT_PATH=D:\Projects\android\androidlcl\android
 +
</syntaxhighlight>
  
 
Run "generate_debug_key.bat"
 
Run "generate_debug_key.bat"
 +
 
Use as password : "senhas"
 
Use as password : "senhas"
 +
 
This will produce the file :
 
This will produce the file :
 +
 
D:\Projects\android\androidlcl\android\bin\LCLDebugKey.keystore
 
D:\Projects\android\androidlcl\android\bin\LCLDebugKey.keystore
  
b) Edit with a text editor
+
 
 +
* Edit with a text editor
 
D:\Projects\android\androidlcl\android\build_debug_apk.bat
 
D:\Projects\android\androidlcl\android\build_debug_apk.bat
 +
 
Modify the first 6 lines like this :
 
Modify the first 6 lines like this :
Code: [Select]
+
<syntaxhighlight lang="dos">
 
 
 
REM Adjust these paths to yours
 
REM Adjust these paths to yours
 
SET PATH=C:\Android\android-sdk\tools;C:\Android\android-sdk\build-tools\17.0.0;C:\Android\android-sdk\platform-tools\;C:\Progra~1\Java\jdk1.6.0_45\bin
 
SET PATH=C:\Android\android-sdk\tools;C:\Android\android-sdk\build-tools\17.0.0;C:\Android\android-sdk\platform-tools\;C:\Progra~1\Java\jdk1.6.0_45\bin
Line 109: Line 150:
 
SET APK_SDK_PLATFORM=C:\Android\android-sdk\platforms\android-8
 
SET APK_SDK_PLATFORM=C:\Android\android-sdk\platforms\android-8
 
SET APK_PROJECT_PATH=D:\Projects\android\androidlcl\android
 
SET APK_PROJECT_PATH=D:\Projects\android\androidlcl\android
 +
</syntaxhighlight>
  
 
run "build_debug_apk.bat" answer at the questions and give the password "senhas" when asked
 
run "build_debug_apk.bat" answer at the questions and give the password "senhas" when asked
 +
 
This will generate
 
This will generate
 +
 
D:\Projects\android\androidlcl\android\bin\lcltest.apk [1.549 kb]
 
D:\Projects\android\androidlcl\android\bin\lcltest.apk [1.549 kb]
  
c) Create an Android Virtual Device
+
 
 +
* Create an Android Virtual Device
 
START >  AVD Manager
 
START >  AVD Manager
 +
 
New > AVD name > give a name
 
New > AVD name > give a name
 +
 
Device 5.1 WVGA
 
Device 5.1 WVGA
 +
 
Target Android 4 API 14
 
Target Android 4 API 14
 +
 
Hit OK
 
Hit OK
 +
 
Once created select the virtual device and hit "start" > "Launch" wait a couple of minutes.
 
Once created select the virtual device and hit "start" > "Launch" wait a couple of minutes.
 
   
 
   
  
d) Edit with a text editor
+
* Edit with a text editor
 
D:\Projects\android\androidlcl\android\adb_install.bat
 
D:\Projects\android\androidlcl\android\adb_install.bat
 +
 
Modify  like this :  
 
Modify  like this :  
Code: [Select]
+
<syntaxhighlight lang="dos">
 
 
 
REM Adjust these paths to yours
 
REM Adjust these paths to yours
 
SET PATH=C:\Android\android-sdk\tools;C:\Android\android-sdk\build-tools\17.0.0;C:\Android\android-sdk\platform-tools\;C:\Progra~1\Java\jdk1.6.0_45\bin
 
SET PATH=C:\Android\android-sdk\tools;C:\Android\android-sdk\build-tools\17.0.0;C:\Android\android-sdk\platform-tools\;C:\Progra~1\Java\jdk1.6.0_45\bin
Line 135: Line 185:
  
 
pause
 
pause
 +
</syntaxhighlight>
  
 
Run "adb_install.bat" . This will install the "LCL Test" into your Virtual device
 
Run "adb_install.bat" . This will install the "LCL Test" into your Virtual device
  
e) Debugging
+
 
 +
* Debugging
 
Edit with a text editor the file  
 
Edit with a text editor the file  
 +
 
D:\Projects\android\androidlcl\android\adb_install.bat
 
D:\Projects\android\androidlcl\android\adb_install.bat
 +
 
like this :
 
like this :
Code: [Select]
+
<syntaxhighlight lang="dos">
 
 
 
REM Adjust these paths to yours
 
REM Adjust these paths to yours
 
SET PATH=C:\Android\android-sdk\tools;C:\Android\android-sdk\build-tools\17.0.0;C:\Android\android-sdk\platform-tools\;C:\Progra~1\Java\jdk1.6.0_45\bin
 
SET PATH=C:\Android\android-sdk\tools;C:\Android\android-sdk\build-tools\17.0.0;C:\Android\android-sdk\platform-tools\;C:\Progra~1\Java\jdk1.6.0_45\bin
Line 150: Line 203:
  
 
pause
 
pause
 +
</syntaxhighlight>
  
 
By running this you will get a debug file here :
 
By running this you will get a debug file here :
 +
 
D:\Projects\android\androidlcl\android\std.txt
 
D:\Projects\android\androidlcl\android\std.txt
  
 
Enjoy !  
 
Enjoy !  
  
* [http://forum.lazarus.freepascal.org/index.php/topic,22414.msg141964.html? Original forum topic]
+
[http://forum.lazarus.freepascal.org/index.php/topic,22414.msg141964.html? Original forum topic]
  
 
=Linux=
 
=Linux=

Revision as of 19:39, 2 March 2014

Windows

This is a quick tutorial on how to create android apps with Lazarus.

In this tutorial assume used versions JDK 1.6u45 + SDK 22.2.1 + ndk-r9 + Laz4Android1.1-41139-FPC2.7.1

Prepare folder

Create on C:\ a folder called "Android"

Install JDK

1.6u45 (i have installed jdk-6u45-windows-x64.exe)

http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html#jdk-6u45-oth-JPR

It will be installed in to C:\Program Files\Java\.

Installing SDK

Go to http://developer.android.com/sdk/index.html

DOWNLOAD FOR OTHER PLATFORMS > SDK Tools Only

installer_r22.2.1-windows.exe (Recommended)

Install sdk (installer_r22.2.1-windows) into C:\Android\android-sdk

Copy at "C:\Android\android-sdk\tools" the file "apkbuilder.bat" (can be found here

https://github.com/ACSOP/android_sdk/raw/master/apkbuilder/etc/apkbuilder.bat )

Now update the SDK [WIN START > SDK Manager ]

add android 4.0 (API 14)

add android 2.2 (API 8]

Install packages.

Installing NDK

http://developer.android.com/tools/sdk/ndk/index.html

Download only the file android-ndk-r9-windows-x86.zip

Unzip android-ndk-r9-windows-x86.zip into C:\Android\android-ndk-r9


Installing Laz4Android1.1-41139-FPC2.7.1.7z

Download it from https://skydrive.live.com/?cid=89ae6b50650182c6&id=89AE6B50650182C6!149

Unzip Laz4Android1.1-41139-FPC2.7.1.7z into C:\Android\laz4android

Copy

C:\Android\android-ndk-r9\toolchains\arm-linux-androideabi-4.6\prebuilt\windows\bin\arm-linux-androideabi-*.exe

to

C:\Android\laz4android\fpc\2.7.1\bin\i386-win32\*

Edit the file C:\Android\laz4android\build.bat like this :

SET FPC_BIN_PATH=C:\Android\laz4android

Run build.bat (doubleclick) -> It will compile & bulid lazarus.


Rebuilding Laz4Android IDE

Run C:\Android\laz4android\lazarus.exe

Select "Start IDE"

select "Package" "Install/Uninstall Packages"

select customdrawn 0.0 > install selection and hit save and rebuild IDE , continue


Compiling the demo "androidlcl"

Copy C:\Android\laz4android\examples\androidlcl at D:\Projects\android\androidlcl

Run "C:\Android\laz4android\lazarus.exe"

File > open "D:\Projects\android\androidlcl\androidlcltest.lpr"

Project > project options

Compiler options > select "Release TAndroid"

Paths >

Libraries -Ll : C:\Android\android-ndk-r9\platforms\android-8\arch-arm\usr\lib;C:\Android\android-ndk-r9\toolchains\arm-linux-androideabi-4.6\prebuilt\windows\lib\gcc\arm-linux-androideabi\4.6

Target file name : android\libs\armeabi\liblclapp.so

Code generation

 Target OS -T android
 Target CPU -P arm
 Target processor default

Linking :

 Enable strip symbols (-Xs)

Other : -dANDROID -Xd -CpARMV6 -FLlibdl.so

Ide macro values : macro name : LCLWidgetType macro value : customdrawn

Now Run > Compile this will generate this library : D:\Projects\android\androidlcl\android\libs\armeabi\liblclapp.so [5.073 kb]


Deployment

  • Edit with a text editor

D:\Projects\android\androidlcl\android\generate_debug_key.bat

Modify the first 6 lines like this :

REM Adjust these paths to yours
SET PATH=C:\Android\android-sdk\tools;C:\Android\android-sdk\build-tools\17.0.0;C:\Android\android-sdk\platform-tools\;C:\Progra~1\Java\jdk1.6.0_45\bin
SET APP_NAME=lcltest
SET ANDROID_HOME=C:\Android\android-sdk
SET APK_SDK_PLATFORM=C:\Android\android-sdk\platforms\android-8
SET APK_PROJECT_PATH=D:\Projects\android\androidlcl\android

Run "generate_debug_key.bat"

Use as password : "senhas"

This will produce the file :

D:\Projects\android\androidlcl\android\bin\LCLDebugKey.keystore


  • Edit with a text editor

D:\Projects\android\androidlcl\android\build_debug_apk.bat

Modify the first 6 lines like this :

REM Adjust these paths to yours
SET PATH=C:\Android\android-sdk\tools;C:\Android\android-sdk\build-tools\17.0.0;C:\Android\android-sdk\platform-tools\;C:\Progra~1\Java\jdk1.6.0_45\bin
SET APP_NAME=lcltest
SET ANDROID_HOME=C:\Android\android-sdk
SET APK_SDK_PLATFORM=C:\Android\android-sdk\platforms\android-8
SET APK_PROJECT_PATH=D:\Projects\android\androidlcl\android

run "build_debug_apk.bat" answer at the questions and give the password "senhas" when asked

This will generate

D:\Projects\android\androidlcl\android\bin\lcltest.apk [1.549 kb]


  • Create an Android Virtual Device

START > AVD Manager

New > AVD name > give a name

Device 5.1 WVGA

Target Android 4 API 14

Hit OK

Once created select the virtual device and hit "start" > "Launch" wait a couple of minutes.


  • Edit with a text editor

D:\Projects\android\androidlcl\android\adb_install.bat

Modify like this :

REM Adjust these paths to yours
SET PATH=C:\Android\android-sdk\tools;C:\Android\android-sdk\build-tools\17.0.0;C:\Android\android-sdk\platform-tools\;C:\Progra~1\Java\jdk1.6.0_45\bin

adb uninstall com.pascal.lcltest
adb install bin\lcltest.apk

pause

Run "adb_install.bat" . This will install the "LCL Test" into your Virtual device


  • Debugging

Edit with a text editor the file

D:\Projects\android\androidlcl\android\adb_install.bat

like this :

REM Adjust these paths to yours
SET PATH=C:\Android\android-sdk\tools;C:\Android\android-sdk\build-tools\17.0.0;C:\Android\android-sdk\platform-tools\;C:\Progra~1\Java\jdk1.6.0_45\bin

adb logcat > std.txt

pause

By running this you will get a debug file here :

D:\Projects\android\androidlcl\android\std.txt

Enjoy !

Original forum topic

Linux