Android tutorial: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Android tutorial
| Old | New | Line | |
|---|---|---|---|
| 1 | + | *(Android only)* | |
| 2 | + | ||
| 3 | + | # Windows | |
| 4 | + | ||
| 5 | + | This is a quick tutorial on how to create android apps with Lazarus. | |
| 6 | + | ||
| 7 | + | In this tutorial assume used versions JDK 1.6u45 + SDK 22.2.1 + ndk-r9 + Laz4Android1.1-41139-FPC2.7.1 | |
| 8 | + | ||
| 9 | + | ## Prepare folder | |
| 10 | + | ||
| 11 | + | Create on C:\\ a folder called "Android" | |
| 12 | + | ||
| 13 | + | ## Install JDK | |
| 14 | + | ||
| 15 | + | 1.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> | |
| 16 | + | ||
| 17 | + | It will be installed in to C:\Program Files\Java\\. | |
| 18 | + | ||
| 19 | + | ## Install SDK | |
| 20 | + | ||
| 21 | + | For Laz4Android3.2 install Android Studio. | |
| 22 | + | ||
| 23 | + | Go to <http://developer.android.com/sdk/index.html> | |
| 24 | + | ||
| 25 | + | DOWNLOAD FOR OTHER PLATFORMS \> SDK Tools Only | |
| 26 | + | ||
| 27 | + | installer_r22.2.1-windows.exe (Recommended) | |
| 28 | + | ||
| 29 | + | Install sdk (installer_r22.2.1-windows) into C:\Android\android-sdk | |
| 30 | + | ||
| 31 | + | Copy at "C:\Android\android-sdk\tools" the file "apkbuilder.bat" (can be found here | |
| 32 | + | ||
| 33 | + | <https://github.com/ACSOP/android_sdk/raw/master/apkbuilder/etc/apkbuilder.bat> ) | |
| 34 | + | ||
| 35 | + | Now update the SDK \[WIN START \> SDK Manager \] | |
| 36 | + | ||
| 37 | + | add android 4.0 (API 14) | |
| 38 | + | ||
| 39 | + | add android 2.2 (API 8\] | |
| 40 | + | ||
| 41 | + | Install packages. | |
| 42 | + | ||
| 43 | + | ## Install NDK | |
| 44 | + | ||
| 45 | + | For Laz4Android3.2 NDK is in Android Studio with cmake. | |
| 46 | + | ||
| 47 | + | <http://developer.android.com/tools/sdk/ndk/index.html> | |
| 48 | + | ||
| 49 | + | Download only the file android-ndk-r9-windows-x86.zip | |
| 50 | + | ||
| 51 | + | Unzip android-ndk-r9-windows-x86.zip into C:\Android\android-ndk-r9 | |
| 52 | + | ||
| 53 | + | ## Install Laz4Android | |
| 54 | + | ||
| 55 | + | Download it from <https://skydrive.live.com/?cid=89ae6b50650182c6&id=89AE6B50650182C6!149> | |
| 56 | + | ||
| 57 | + | New version can download from here:[1](http://sourceforge.net/projects/laz4android/) | |
| 58 | + | ||
| 59 | + | Unzip Laz4Android1.1-41139-FPC2.7.1.7z into C:\Android\laz4android | |
| 60 | + | ||
| 61 | + | Copy | |
| 62 | + | ||
| 63 | + | C:\Android\android-ndk-r9\toolchains\arm-linux-androideabi-4.6\prebuilt\windows\bin\arm-linux-androideabi-*.exe | |
| 64 | + | ||
| 65 | + | to | |
| 66 | + | ||
| 67 | + | C:\Android\laz4android\fpc\2.7.1\bin\i386-win32\\* | |
| 68 | + | ||
| 69 | + | Edit the file C:\Android\laz4android\build.bat like this : | |
| 70 | + | ||
| 71 | + | ```dos | |
| 72 | + | SET FPC_BIN_PATH=C:\Android\laz4android | |
| 73 | + | ``` | |
| 74 | + | ||
| 75 | + | Run build.bat (doubleclick) -\> It will compile & build lazarus. | |
| 76 | + | ||
| 77 | + | ## Rebuild Laz4Android IDE | |
| 78 | + | ||
| 79 | + | Run C:\Android\laz4android\lazarus.exe | |
| 80 | + | ||
| 81 | + | Select "Start IDE" | |
| 82 | + | ||
| 83 | + | select "Package" "Install/Uninstall Packages" | |
| 84 | + | ||
| 85 | + | select customdrawn 0.0 \> install selection and hit save and rebuild IDE , continue | |
| 86 | + | ||
| 87 | + | ## Compile the demo "androidlcl" | |
| 88 | + | ||
| 89 | + | Copy C:\Android\laz4android\examples\androidlcl at C:\Android\Projects\androidlcl | |
| 90 | + | ||
| 91 | + | Run "C:\Android\laz4android\lazarus.exe" | |
| 92 | + | ||
| 93 | + | File \> open "C:\Android\Projects\androidlcl\androidlcltest.lpr" | |
| 94 | + | ||
| 95 | + | Project \> project options | |
| 96 | + | ||
| 97 | + | Compiler options \> select "Release TAndroid" | |
| 98 | + | ||
| 99 | + | Paths \> | |
| 100 | + | ||
| 101 | + | 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 | |
| 102 | + | ||
| 103 | + | Target file name : android\libs\armeabi\liblclapp.so | |
| 104 | + | ||
| 105 | + | Code generation | |
| 106 | + | ||
| 107 | + | ` Target OS -T android`\ | |
| 108 | + | ` Target CPU -P arm`\ | |
| 109 | + | ` Target processor default` | |
| 110 | + | ||
| 111 | + | Linking : | |
| 112 | + | ||
| 113 | + | ` Enable strip symbols (-Xs)` | |
| 114 | + | ||
| 115 | + | Other : -dANDROID -Xd -CpARMV6 -FLlibdl.so | |
| 116 | + | ||
| 117 | + | Ide macro values : macro name : LCLWidgetType macro value : customdrawn | |
| 118 | + | ||
| 119 | + | Now Run \> Compile this will generate this library : C:\Android\Projects\androidlcl\android\libs\armeabi\liblclapp.so \[5.073 kb\] | |
| 120 | + | ||
| 121 | + | ## Deployment | |
| 122 | + | ||
| 123 | + | - Edit with a text editor | |
| 124 | + | ||
| 125 | + | C:\Android\Projects\androidlcl\android\generate_debug_key.bat | |
| 126 | + | ||
| 127 | + | Modify the first 6 lines like this : | |
| 128 | + | ||
| 129 | + | ```dos | |
| 130 | + | REM Adjust these paths to yours | |
| 131 | + | 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 | |
| 132 | + | SET APP_NAME=lcltest | |
| 133 | + | SET ANDROID_HOME=C:\Android\android-sdk | |
| 134 | + | SET APK_SDK_PLATFORM=C:\Android\android-sdk\platforms\android-8 | |
| 135 | + | SET APK_PROJECT_PATH=C:\Android\Projects\androidlcl\android | |
| 136 | + | ``` | |
| 137 | + | ||
| 138 | + | Run "generate_debug_key.bat" | |
| 139 | + | ||
| 140 | + | Use as password : "senhas" | |
| 141 | + | ||
| 142 | + | This will produce the file : | |
| 143 | + | ||
| 144 | + | C:\Android\Projects\androidlcl\android\bin\LCLDebugKey.keystore | |
| 145 | + | ||
| 146 | + | - Edit with a text editor | |
| 147 | + | ||
| 148 | + | C:\Android\Projects\androidlcl\android\build_debug_apk.bat | |
| 149 | + | ||
| 150 | + | Modify the first 6 lines like this : | |
| 151 | + | ||
| 152 | + | ```dos | |
| 153 | + | REM Adjust these paths to yours | |
| 154 | + | 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 | |
| 155 | + | SET APP_NAME=lcltest | |
| 156 | + | SET ANDROID_HOME=C:\Android\android-sdk | |
| 157 | + | SET APK_SDK_PLATFORM=C:\Android\android-sdk\platforms\android-8 | |
| 158 | + | SET APK_PROJECT_PATH=C:\Android\Projects\androidlcl\android | |
| 159 | + | ``` | |
| 160 | + | ||
| 161 | + | I had to change mine to this on sdk version 22: | |
| 162 | + | ||
| 163 | + | ```dos | |
| 164 | + | SET APK_BUILD_TOOLS=C:\development\android-sdk\build-tools\22.0.1 | |
| 165 | + | SET PATH=C:\development\android-sdk\tools;C:\development\android-sdk\platform-tools\;C:\Program Files\Java\jdk1.7.0_79\bin;%APK_BUILD_TOOLS% | |
| 166 | + | SET APP_NAME=androidlcl | |
| 167 | + | SET ANDROID_HOME=C:\development\android-sdk | |
| 168 | + | SET APK_SDK_PLATFORM=C:\development\android-sdk\platforms\android-22 | |
| 169 | + | SET APK_PROJECT_PATH=C:\Android\Projects\androidlcl\android | |
| 170 | + | ||
| 171 | + | and these lines: | |
| 172 | + | ||
| 173 | + | REM Convert the java bytecode to dalvik bytecode | |
| 174 | + | ::REM For older SDKs: call dx --dex --verbose --output=%APK_PROJECT_PATH%\bin\classes.dex %APK_PROJECT_PATH%\bin\classes | |
| 175 | + | ::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 | |
| 176 | + | call 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 | |
| 177 | + | ``` | |
| 178 | + | ||
| 179 | + | run "build_debug_apk.bat" answer at the questions and give the password "senhas" when asked | |
| 180 | + | ||
| 181 | + | This will generate | |
| 182 | + | ||
| 183 | + | C:\Android\Projects\androidlcl\android\bin\lcltest.apk \[1.549 kb\] | |
| 184 | + | ||
| 185 | + | - Create an Android Virtual Device | |
| 186 | + | ||
| 187 | + | START \> AVD Manager | |
| 188 | + | ||
| 189 | + | New \> AVD name \> give a name | |
| 190 | + | ||
| 191 | + | Device 5.1 WVGA | |
| 192 | + | ||
| 193 | + | Target Android 4 API 14 | |
| 194 | + | ||
| 195 | + | Hit OK | |
| 196 | + | ||
| 197 | + | Once created select the virtual device and hit "start" \> "Launch" wait a couple of minutes. | |
| 198 | + | ||
| 199 | + | - Edit with a text editor | |
| 200 | + | ||
| 201 | + | C:\Android\Projects\androidlcl\android\adb_install.bat | |
| 202 | + | ||
| 203 | + | Modify like this : | |
| 204 | + | ||
| 205 | + | ```dos | |
| 206 | + | REM Adjust these paths to yours | |
| 207 | + | 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 | |
| 208 | + | ||
| 209 | + | adb uninstall com.pascal.lcltest | |
| 210 | + | adb install bin\lcltest.apk | |
| 211 | + | ||
| 212 | + | pause | |
| 213 | + | ``` | |
| 214 | + | ||
| 215 | + | Run "adb_install.bat" . This will install the "LCL Test" into your Virtual device | |
| 216 | + | ||
| 217 | + | - Debugging | |
| 218 | + | ||
| 219 | + | Edit with a text editor the file | |
| 220 | + | ||
| 221 | + | C:\Android\Projects\androidlcl\android\adb_install.bat | |
| 222 | + | ||
| 223 | + | like this : | |
| 224 | + | ||
| 225 | + | ```dos | |
| 226 | + | REM Adjust these paths to yours | |
| 227 | + | 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 | |
| 228 | + | ||
| 229 | + | adb logcat > std.txt | |
| 230 | + | ||
| 231 | + | pause | |
| 232 | + | ``` | |
| 233 | + | ||
| 234 | + | By running this you will get a debug file here : | |
| 235 | + | ||
| 236 | + | C:\Android\Projects\androidlcl\android\std.txt | |
| 237 | + | ||
| 238 | + | Enjoy ! | |
| 239 | + | ||
| 240 | + | ## Links | |
| 241 | + | ||
| 242 | + | - \[<http://forum.lazarus.freepascal.org/index.php/topic,22414.msg141964.html>? Original forum topic\] | |
| 243 | + | - [Lazarus and Android PDF tutorial with images](http://sourceforge.net/projects/laztoapk/files/Lazarus%20and%20Android.pdf/download) | |
| 244 | + | ||
| 245 | + | # Linux | |
| 246 | + | ||
| 247 | + | > **Note:** Work in progress... | |
| 248 | + | ||
| 249 | + | This is a quick tutorial on how to create android apps with Lazarus. | |
| 250 | + | ||
| 251 | + | In 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 | |
| 252 | + | ||
| 253 | + | ## Prepare folder | |
| 254 | + | ||
| 255 | + | Create directory ~\Android | |
| 256 | + | ||
| 257 | + | ## Install OpenJDK | |
| 258 | + | ||
| 259 | + | ``` bash | |
| 260 | + | sudo apt-get install openjdk-7-jdk | |
| 261 | + | ``` | |
| 262 | + | ||
| 263 | + | ## Install SDK | |
| 264 | + | ||
| 265 | + | Go to <http://developer.android.com/sdk/index.html> | |
| 266 | + | ||
| 267 | + | DOWNLOAD FOR OTHER PLATFORMS \> SDK Tools Only | |
| 268 | + | ||
| 269 | + | android-sdk_r22.6.2-linux.tgz (Recommended) | |
| 270 | + | ||
| 271 | + | Extract SDK () into ~\Android\android-sdk | |
| 272 | + | ||
| 273 | + | ``` bash | |
| 274 | + | tar -zxvf android-sdk_r22.6.2-linux.tgz | |
| 275 | + | ``` | |
| 276 | + | ||
| 277 | + | Now update the SDK (Start ~\Android\android-sdk\tools\android) | |
| 278 | + | ||
| 279 | + | add android 4.0 (API 14) | |
| 280 | + | ||
| 281 | + | add android 2.2 (API 8\] | |
| 282 | + | ||
| 283 | + | Install packages. | |
| 284 | + | ||
| 285 | + | ## Install NDK | |
| 286 | + | ||
| 287 | + | <http://developer.android.com/tools/sdk/ndk/index.html> | |
| 288 | + | ||
| 289 | + | Download only the file android-ndk-r9d-linux-x86.tar.bz2 | |
| 290 | + | ||
| 291 | + | Extract android-ndk-r9d-linux-x86.tar.bz2 into ~\Android\android-ndk-r9 | |
| 292 | + | ||
| 293 | + | ``` bash | |
| 294 | + | tar -jxvf android-ndk-r9d-linux-x86.tar.bz2 | |
| 295 | + | ``` | |
| 296 | + | ||
| 297 | + | ## Build FPC 2.7.1 | |
| 298 | + | ||
| 299 | + | Install latest FPC distribution package: | |
| 300 | + | ||
| 301 | + | ``` bash | |
| 302 | + | sudo apt-get install fpc | |
| 303 | + | ``` | |
| 304 | + | ||
| 305 | + | Download latest FPC trunk from SVN: | |
| 306 | + | ||
| 307 | + | ``` bash | |
| 308 | + | svn co http://svn.freepascal.org/svn/fpc/trunk/ ~/Android/fpcsrc | |
| 309 | + | ``` | |
| 310 | + | ||
| 311 | + | Build FPC trunk for ARM to ~/Android/fpc: | |
| 312 | + | ||
| 313 | + | ``` bash | |
| 314 | + | make crossinstall CPU_TARGET=arm OS_TARGET=linux \ | |
| 315 | + | CROSSBINDIR=~/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 | |
| 316 | + | ``` | |
| 317 | + | ||
| 318 | + | ## Rebuild Lazarus IDE | |
| 319 | + | ||
| 320 | + | Run ~\Android\lazarus | |
| 321 | + | ||
| 322 | + | Select "Start IDE" | |
| 323 | + | ||
| 324 | + | select "Package" "Install/Uninstall Packages" | |
| 325 | + | ||
| 326 | + | select customdrawn 0.0 \> install selection and hit save and rebuild IDE , continue | |
| 327 | + | ||
| 328 | + | ## Links | |
| 329 | + | ||
| 330 | + | - [Android Programming with Lazarus through Custom Drawn Interface](http://pascalgeek.blogspot.cz/2013/10/android-programming-with-lazarus.html) | |
| 331 | + | ||
| 332 | + | --- | |
| 333 | + | *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).* | |
| 334 | + | Category: Android | |
| 335 | + | Category: Tutorials |
