Sign in Join
Wiki copytemporary

Android tutorial: what changed

Revision 1 to 2. 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-` Target OS -T android`\
108-` Target CPU -P arm`\
109-` Target processor default`
107+```
108+ Target OS -T android
109+ Target CPU -P arm
110+ Target processor default
111+```
110112
111113Linking :
112114
113-` Enable strip symbols (-Xs)`
115+```
116+ Enable strip symbols (-Xs)
117+```
114118
115119Other : -dANDROID -Xd -CpARMV6 -FLlibdl.so
116120
117121Ide macro values : macro name : LCLWidgetType macro value : customdrawn
118122
119123Now Run \> Compile this will generate this library : C:\Android\Projects\androidlcl\android\libs\armeabi\liblclapp.so \[5.073 kb\]
120124
121125## Deployment
122126
123127- Edit with a text editor
124128
125129C:\Android\Projects\androidlcl\android\generate_debug_key.bat
126130
127131Modify the first 6 lines like this :
128132
129133```dos
130134REM Adjust these paths to yours
131135SET 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
132136SET APP_NAME=lcltest
133137SET ANDROID_HOME=C:\Android\android-sdk
134138SET APK_SDK_PLATFORM=C:\Android\android-sdk\platforms\android-8
135139SET APK_PROJECT_PATH=C:\Android\Projects\androidlcl\android
136140```
137141
138142Run "generate_debug_key.bat"
139143
140144Use as password : "senhas"
141145
142146This will produce the file :
143147
144148C:\Android\Projects\androidlcl\android\bin\LCLDebugKey.keystore
145149
146150- Edit with a text editor
147151
148152C:\Android\Projects\androidlcl\android\build_debug_apk.bat
149153
150154Modify the first 6 lines like this :
151155
152156```dos
153157REM Adjust these paths to yours
154158SET 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
155159SET APP_NAME=lcltest
156160SET ANDROID_HOME=C:\Android\android-sdk
157161SET APK_SDK_PLATFORM=C:\Android\android-sdk\platforms\android-8
158162SET APK_PROJECT_PATH=C:\Android\Projects\androidlcl\android
159163```
160164
161165I had to change mine to this on sdk version 22:
162166
163167```dos
164168SET APK_BUILD_TOOLS=C:\development\android-sdk\build-tools\22.0.1
165169SET PATH=C:\development\android-sdk\tools;C:\development\android-sdk\platform-tools\;C:\Program Files\Java\jdk1.7.0_79\bin;%APK_BUILD_TOOLS%
166170SET APP_NAME=androidlcl
167171SET ANDROID_HOME=C:\development\android-sdk
168172SET APK_SDK_PLATFORM=C:\development\android-sdk\platforms\android-22
169173SET APK_PROJECT_PATH=C:\Android\Projects\androidlcl\android
170174
171175and these lines:
172176
173177REM Convert the java bytecode to dalvik bytecode
174178::REM For older SDKs: call dx --dex --verbose --output=%APK_PROJECT_PATH%\bin\classes.dex %APK_PROJECT_PATH%\bin\classes
175179::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
176180call 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
177181```
178182
179183run "build_debug_apk.bat" answer at the questions and give the password "senhas" when asked
180184
181185This will generate
182186
183187C:\Android\Projects\androidlcl\android\bin\lcltest.apk \[1.549 kb\]
184188
185189- Create an Android Virtual Device
186190
187191START \> AVD Manager
188192
189193New \> AVD name \> give a name
190194
191195Device 5.1 WVGA
192196
193197Target Android 4 API 14
194198
195199Hit OK
196200
197201Once created select the virtual device and hit "start" \> "Launch" wait a couple of minutes.
198202
199203- Edit with a text editor
200204
201205C:\Android\Projects\androidlcl\android\adb_install.bat
202206
203207Modify like this :
204208
205209```dos
206210REM Adjust these paths to yours
207211SET 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
208212
209213adb uninstall com.pascal.lcltest
210214adb install bin\lcltest.apk
211215
212216pause
213217```
214218
215219Run "adb_install.bat" . This will install the "LCL Test" into your Virtual device
216220
217221- Debugging
218222
219223Edit with a text editor the file
220224
221225C:\Android\Projects\androidlcl\android\adb_install.bat
222226
223227like this :
224228
225229```dos
226230REM Adjust these paths to yours
227231SET 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
228232
229233adb logcat > std.txt
230234
231235pause
232236```
233237
234238By running this you will get a debug file here :
235239
236240C:\Android\Projects\androidlcl\android\std.txt
237241
238242Enjoy !
239243
240244## Links
241245
242246- \[<http://forum.lazarus.freepascal.org/index.php/topic,22414.msg141964.html>? Original forum topic\]
243247- [Lazarus and Android PDF tutorial with images](http://sourceforge.net/projects/laztoapk/files/Lazarus%20and%20Android.pdf/download)
244248
245249# Linux
246250
247251> **Note:** Work in progress...
248252
249253This is a quick tutorial on how to create android apps with Lazarus.
250254
251255In 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
252256
253257## Prepare folder
254258
255259Create directory ~\Android
256260
257261## Install OpenJDK
258262
259263``` bash
260264sudo apt-get install openjdk-7-jdk
261265```
262266
263267## Install SDK
264268
265269Go to <http://developer.android.com/sdk/index.html>
266270
267271DOWNLOAD FOR OTHER PLATFORMS \> SDK Tools Only
268272
269273android-sdk_r22.6.2-linux.tgz (Recommended)
270274
271275Extract SDK () into ~\Android\android-sdk
272276
273277``` bash
274278tar -zxvf android-sdk_r22.6.2-linux.tgz
275279```
276280
277281Now update the SDK (Start ~\Android\android-sdk\tools\android)
278282
279283add android 4.0 (API 14)
280284
281285add android 2.2 (API 8\]
282286
283287Install packages.
284288
285289## Install NDK
286290
287291<http://developer.android.com/tools/sdk/ndk/index.html>
288292
289293Download only the file android-ndk-r9d-linux-x86.tar.bz2
290294
291295Extract android-ndk-r9d-linux-x86.tar.bz2 into ~\Android\android-ndk-r9
292296
293297``` bash
294298tar -jxvf android-ndk-r9d-linux-x86.tar.bz2
295299```
296300
297301## Build FPC 2.7.1
298302
299303Install latest FPC distribution package:
300304
301305``` bash
302306sudo apt-get install fpc
303307```
304308
305309Download latest FPC trunk from SVN:
306310
307311``` bash
308312svn co http://svn.freepascal.org/svn/fpc/trunk/ ~/Android/fpcsrc
309313```
310314
311315Build FPC trunk for ARM to ~/Android/fpc:
312316
313317``` bash
314318make crossinstall CPU_TARGET=arm OS_TARGET=linux \
315319CROSSBINDIR=~/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
316320```
317321
318322## Rebuild Lazarus IDE
319323
320324Run ~\Android\lazarus
321325
322326Select "Start IDE"
323327
324328select "Package" "Install/Uninstall Packages"
325329
326330select customdrawn 0.0 \> install selection and hit save and rebuild IDE , continue
327331
328332## Links
329333
330334- [Android Programming with Lazarus through Custom Drawn Interface](http://pascalgeek.blogspot.cz/2013/10/android-programming-with-lazarus.html)
331335
332336---
333337*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).*
334338Category: Android
335339Category: Tutorials

Back to history