sax wrote: viking, could you give me instruction how to build *.apk file from *.so file, please?
I create project according to the instructions from wiki, but I really stuck on building *.apk file.
thx SaX
I really do not have much time, since I need to finish some things for work today, but I will try to be as clear as possible.
There is one thing missing in CT tutorial - the fact that target name in example project should be changed to "
android\libs\armeabi\liblclapp.so".
Looks like you already done that, since you have
.so library. Good.
You need to setup
JDK,
Android SDK and
Android NDK properly. I guess you already done all that, but here is quick checkout list what should be done:
1. Install JDK, set
JAVA_HOME variable. Put the path to the JDK without \bin in the end. For example "
C:\Program Files\Java\jdk1.7.0_51"
2. Download and install Android SDK and NDK.
3. Start SDK manager and install
Tools,
Build Tools,
Platform Tools,
Android 2.2 (API 8) and
Android 4.0 (API 14).
Then you need to change
build_debug_apk.bat
First you need to set some variables:
APP_NAME = name of your apk file
APK_PROJECT_PATH = folder where your apk project is
ANDROID_HOME = folder with android sdk
APK_SDK_PLATFORM = folder with skd files for specific platform
In
PATH, you need to have %ANDROID_HOME%\build-tools\<version number> - folder named by version number is probably only folder in %ANDROID_HOME%\build-tools folder.
19.0.1 for example.
With
CT 4.7 if you want to create apk from adroid lcl example, and if you have installed
android-sdk_r22.3-windows and
android-ndk-r9c-windows-x86_64, first few lines should look like this:
REM Adjust these paths to yours
SET APP_NAME=androidlcltest
SET APK_PROJECT_PATH=c:\codetyphon\CodeOcean\2_Basics\samples\androidlcl\android
SET ANDROID_HOME=c:\Android\android-sdk-windows
SET APK_SDK_PLATFORM=%ANDROID_HOME%\platforms\android-8
SET PATH=%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\build-tools\19.0.1;%JAVA_HOME%\bin
This part is very obvious:
REM Create necessary directory Structure
mkdir bin
mkdir bin\classes
mkdir gen
mkdir gen\com
mkdir gen\com\pascal
mkdir gen\com\pascal\lcltest
mkdir raw
mkdir raw\lib
mkdir raw\lib\armeabi
REM Cleanup
del bin\%APP_NAME%.ap_
del bin\%APP_NAME%.apk
del raw\lib\armeabi\*.so
This part doesn't have clear explanation. This will copy your created .so file in another folder. If your CT produced file doesn't have .so extension it will not be copied and you will end with apk that can not even show your form.
REM More directory preparation
copy libs\armeabi\*.so raw\lib\armeabi\
And now real work start. First create R.java.
REM Resource compilation
call aapt p -v -f -M AndroidManifest.xml -F bin\%APP_NAME%.ap_ -I %APK_SDK_PLATFORM%\android.jar -S res -m -J gen raw
Next compile java sample from src folder.
REM Java compiler
call javac -verbose -encoding UTF8 -classpath %APK_SDK_PLATFORM%\android.jar -d bin\classes src\com\pascal\lcltest\LCLActivity.java
Create classes.dex
REM DX to convert the java bytecode to dalvik bytecode
call dx --dex --verbose --output=%APK_PROJECT_PATH%\bin\classes.dex %APK_PROJECT_PATH%\bin\classes
Now we need to rebuild unsigned apk. Since APK Builder is deprecated we will use aapt for this. Notice that this can be done with 7zip or any zip capable packer.
I had struggle with some parameters of aapt add, so I had to copy classes.dex to current folder and to move ap_ to apk at the end.
REM Now build the unsigned APK
del classes.dex
del %APK_PROJECT_PATH%\bin\%APP_NAME%-unsigned.apk
copy bin\classes.dex classes.dex
call aapt add bin\%APP_NAME%.ap_ classes.dex
move bin\%APP_NAME%.ap_ bin\%APP_NAME%-unsigned.apk
Generate key on the fly for test. For production you should create proper key first. Notice that both passwords are senhas in this example, so you need to use same passwords later. This line should be commented for production. Enter your name instead of John Doe.
REM Generating on the fly a debug key
keytool -genkey -v -keystore bin\LCLDebugKey.keystore -alias LCLDebugKey -keyalg RSA -validity 10000 -dname "CN=Jonh Doe" -storepass senhas -keypass senhas
Singe app with created key using password senhas as when creating the key. You will put your pass here when you create key properly.
REM Signing the APK with a debug key
del bin\%APP_NAME%-unaligned.apk
jarsigner -verbose -keystore bin\LCLDebugKey.keystore -keypass senhas -storepass senhas -signedjar bin\%APP_NAME%-unaligned.apk bin\%APP_NAME%-unsigned.apk LCLDebugKey
Align the apk.
REM Align the final APK package
zipalign -v 4 bin\%APP_NAME%-unaligned.apk bin\%APP_NAME%.apk
EDIT: I fixed a typo in key generation line. I also added more info about setting your name in key.
Unfortunately all this will not get you far with current CT or Lazarus install. You will get main window, but your app will crash whatever you click. It's global problem with latest FPC.
I will make separate post how to temporary overcome this problem. I managed to make this work with some files from older fpc version.