Sign in Join
Wiki copytemporary

Android tutorial: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11*(Android only)*
22
33# Windows
44
55This is a quick tutorial on how to create android apps with Lazarus.
66
77In this tutorial assume used versions JDK 1.6u45 + SDK 22.2.1 + ndk-r9 + Laz4Android1.1-41139-FPC2.7.1
88
99## Prepare folder
1010
1111Create on C:\\ a folder called "Android"
1212
1313## Install JDK
1414
15151.6u45 (i have installed jdk-6u45-windows-x64.exe) arm-linux-androideabi/bin <http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html#jdk-6u45-oth-JPR>
1616
1717It will be installed in to C:\Program Files\Java\\.
1818
1919## Install SDK
2020
2121For Laz4Android3.2 install Android Studio.
2222
2323Go to <http://developer.android.com/sdk/index.html>
2424
2525DOWNLOAD FOR OTHER PLATFORMS \> SDK Tools Only
2626
2727installer_r22.2.1-windows.exe (Recommended)
2828
2929Install sdk (installer_r22.2.1-windows) into C:\Android\android-sdk
3030
3131Copy at "C:\Android\android-sdk\tools" the file "apkbuilder.bat" (can be found here
3232
3333<https://github.com/ACSOP/android_sdk/raw/master/apkbuilder/etc/apkbuilder.bat> )
3434
3535Now update the SDK \[WIN START \> SDK Manager \]
3636
3737add android 4.0 (API 14)
3838
3939add android 2.2 (API 8\]
4040
4141Install packages.
4242
4343## Install NDK
4444
4545For Laz4Android3.2 NDK is in Android Studio with cmake.
4646
4747<http://developer.android.com/tools/sdk/ndk/index.html>
4848
4949Download only the file android-ndk-r9-windows-x86.zip
5050
5151Unzip android-ndk-r9-windows-x86.zip into C:\Android\android-ndk-r9
5252
5353## Install Laz4Android
5454
5555Download it from <https://skydrive.live.com/?cid=89ae6b50650182c6&id=89AE6B50650182C6!149>
5656
5757New version can download from here:[1](http://sourceforge.net/projects/laz4android/)
5858
5959Unzip Laz4Android1.1-41139-FPC2.7.1.7z into C:\Android\laz4android
6060
6161Copy
6262
6363C:\Android\android-ndk-r9\toolchains\arm-linux-androideabi-4.6\prebuilt\windows\bin\arm-linux-androideabi-*.exe
6464
6565to
6666
6767C:\Android\laz4android\fpc\2.7.1\bin\i386-win32\\*
6868
6969Edit the file C:\Android\laz4android\build.bat like this :
7070
7171```dos
7272SET FPC_BIN_PATH=C:\Android\laz4android
7373```
7474
7575Run build.bat (doubleclick) -\> It will compile & build lazarus.
7676
7777## Rebuild Laz4Android IDE
7878
7979Run C:\Android\laz4android\lazarus.exe
8080
8181Select "Start IDE"
8282
8383select "Package" "Install/Uninstall Packages"
8484
8585select customdrawn 0.0 \> install selection and hit save and rebuild IDE , continue
8686
8787## Compile the demo "androidlcl"
8888
8989Copy C:\Android\laz4android\examples\androidlcl at C:\Android\Projects\androidlcl
9090
9191Run "C:\Android\laz4android\lazarus.exe"
9292
9393File \> open "C:\Android\Projects\androidlcl\androidlcltest.lpr"
9494
9595Project \> project options
9696
9797Compiler options \> select "Release TAndroid"
9898
9999Paths \>
100100
101101Libraries -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
102102
103103Target file name : android\libs\armeabi\liblclapp.so
104104
105105Code generation
106106
107-```
107+```text
108108 Target OS -T android
109109 Target CPU -P arm
110110 Target processor default
111111```
112112
113113Linking :
114114
115-```
115+```text
116116 Enable strip symbols (-Xs)
117117```
118118
119119Other : -dANDROID -Xd -CpARMV6 -FLlibdl.so
120120
121121Ide macro values : macro name : LCLWidgetType macro value : customdrawn
122122
123123Now Run \> Compile this will generate this library : C:\Android\Projects\androidlcl\android\libs\armeabi\liblclapp.so \[5.073 kb\]
124124
125125## Deployment
126126
127127- Edit with a text editor
128128
129129C:\Android\Projects\androidlcl\android\generate_debug_key.bat
130130
131131Modify the first 6 lines like this :
132132
133133```dos
134134REM Adjust these paths to yours
135135SET 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
136136SET APP_NAME=lcltest
137137SET ANDROID_HOME=C:\Android\android-sdk
138138SET APK_SDK_PLATFORM=C:\Android\android-sdk\platforms\android-8
139139SET APK_PROJECT_PATH=C:\Android\Projects\androidlcl\android
140140```
141141
142142Run "generate_debug_key.bat"
143143
144144Use as password : "senhas"
145145
146146This will produce the file :
147147
148148C:\Android\Projects\androidlcl\android\bin\LCLDebugKey.keystore
149149
150150- Edit with a text editor
151151
152152C:\Android\Projects\androidlcl\android\build_debug_apk.bat
153153
154154Modify the first 6 lines like this :
155155
156156```dos
157157REM Adjust these paths to yours
158158SET 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
159159SET APP_NAME=lcltest
160160SET ANDROID_HOME=C:\Android\android-sdk
161161SET APK_SDK_PLATFORM=C:\Android\android-sdk\platforms\android-8
162162SET APK_PROJECT_PATH=C:\Android\Projects\androidlcl\android
163163```
164164
165165I had to change mine to this on sdk version 22:
166166
167167```dos
168168SET APK_BUILD_TOOLS=C:\development\android-sdk\build-tools\22.0.1
169169SET PATH=C:\development\android-sdk\tools;C:\development\android-sdk\platform-tools\;C:\Program Files\Java\jdk1.7.0_79\bin;%APK_BUILD_TOOLS%
170170SET APP_NAME=androidlcl
171171SET ANDROID_HOME=C:\development\android-sdk
172172SET APK_SDK_PLATFORM=C:\development\android-sdk\platforms\android-22
173173SET APK_PROJECT_PATH=C:\Android\Projects\androidlcl\android
174174
175175and these lines:
176176
177177REM Convert the java bytecode to dalvik bytecode
178178::REM For older SDKs: call dx --dex --verbose --output=%APK_PROJECT_PATH%\bin\classes.dex %APK_PROJECT_PATH%\bin\classes
179179::REM For older SDKs: call java -Djava.ext.dirs=%ANDROID_HOME%\platform-tools\lib\ -jar %ANDROID_HOME%\platform-tools\lib\dx.jar --dex --verbose --output=%APK_PROJECT_PATH%\bin\classes.dex %APK_PROJECT_PATH%\bin\classes
180180call java -Djava.ext.dirs=%ANDROID_HOME%\platform-tools\lib\;%APK_BUILD_TOOLS%\lib\ -jar %APK_BUILD_TOOLS%\lib\dx.jar --dex --verbose --output=%APK_PROJECT_PATH%\bin\classes.dex %APK_PROJECT_PATH%\bin\classes
181181```
182182
183183run "build_debug_apk.bat" answer at the questions and give the password "senhas" when asked
184184
185185This will generate
186186
187187C:\Android\Projects\androidlcl\android\bin\lcltest.apk \[1.549 kb\]
188188
189189- Create an Android Virtual Device
190190
191191START \> AVD Manager
192192
193193New \> AVD name \> give a name
194194
195195Device 5.1 WVGA
196196
197197Target Android 4 API 14
198198
199199Hit OK
200200
201201Once created select the virtual device and hit "start" \> "Launch" wait a couple of minutes.
202202
203203- Edit with a text editor
204204
205205C:\Android\Projects\androidlcl\android\adb_install.bat
206206
207207Modify like this :
208208
209209```dos
210210REM Adjust these paths to yours
211211SET 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
212212
213213adb uninstall com.pascal.lcltest
214214adb install bin\lcltest.apk
215215
216216pause
217217```
218218
219219Run "adb_install.bat" . This will install the "LCL Test" into your Virtual device
220220
221221- Debugging
222222
223223Edit with a text editor the file
224224
225225C:\Android\Projects\androidlcl\android\adb_install.bat
226226
227227like this :
228228
229229```dos
230230REM Adjust these paths to yours
231231SET 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
232232
233233adb logcat > std.txt
234234
235235pause
236236```
237237
238238By running this you will get a debug file here :
239239
240240C:\Android\Projects\androidlcl\android\std.txt
241241
242242Enjoy !
243243
244244## Links
245245
246246- \[<http://forum.lazarus.freepascal.org/index.php/topic,22414.msg141964.html>? Original forum topic\]
247247- [Lazarus and Android PDF tutorial with images](http://sourceforge.net/projects/laztoapk/files/Lazarus%20and%20Android.pdf/download)
248248
249249# Linux
250250
251251> **Note:** Work in progress...
252252
253253This is a quick tutorial on how to create android apps with Lazarus.
254254
255255In this tutorial assume used versions are Ubuntu 13.10, OpenJDK 1.7.0_51, SDK 22.2.1, ndk-r9, Laz4Android1.1-41139-FPC2.7.1
256256
257257## Prepare folder
258258
259259Create directory ~\Android
260260
261261## Install OpenJDK
262262
263263``` bash
264264sudo apt-get install openjdk-7-jdk
265265```
266266
267267## Install SDK
268268
269269Go to <http://developer.android.com/sdk/index.html>
270270
271271DOWNLOAD FOR OTHER PLATFORMS \> SDK Tools Only
272272
273273android-sdk_r22.6.2-linux.tgz (Recommended)
274274
275275Extract SDK () into ~\Android\android-sdk
276276
277277``` bash
278278tar -zxvf android-sdk_r22.6.2-linux.tgz
279279```
280280
281281Now update the SDK (Start ~\Android\android-sdk\tools\android)
282282
283283add android 4.0 (API 14)
284284
285285add android 2.2 (API 8\]
286286
287287Install packages.
288288
289289## Install NDK
290290
291291<http://developer.android.com/tools/sdk/ndk/index.html>
292292
293293Download only the file android-ndk-r9d-linux-x86.tar.bz2
294294
295295Extract android-ndk-r9d-linux-x86.tar.bz2 into ~\Android\android-ndk-r9
296296
297297``` bash
298298tar -jxvf android-ndk-r9d-linux-x86.tar.bz2
299299```
300300
301301## Build FPC 2.7.1
302302
303303Install latest FPC distribution package:
304304
305305``` bash
306306sudo apt-get install fpc
307307```
308308
309309Download latest FPC trunk from SVN:
310310
311311``` bash
312312svn co http://svn.freepascal.org/svn/fpc/trunk/ ~/Android/fpcsrc
313313```
314314
315315Build FPC trunk for ARM to ~/Android/fpc:
316316
317317``` bash
318318make crossinstall CPU_TARGET=arm OS_TARGET=linux \
319319CROSSBINDIR=~/Android/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/arm-linux-androideabi/bin OPT=-dFPC_ARMEL INSTALL_PREFIX=~/Android/fpc
320320```
321321
322322## Rebuild Lazarus IDE
323323
324324Run ~\Android\lazarus
325325
326326Select "Start IDE"
327327
328328select "Package" "Install/Uninstall Packages"
329329
330330select customdrawn 0.0 \> install selection and hit save and rebuild IDE , continue
331331
332332## Links
333333
334334- [Android Programming with Lazarus through Custom Drawn Interface](http://pascalgeek.blogspot.cz/2013/10/android-programming-with-lazarus.html)
335335
336336---
337337*From the Free Pascal wiki, page "Android tutorial", as it stood on 2024-05-21 after a change by Matthius, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
338338Category: Android
339339Category: Tutorials

Back to history