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