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