Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-03

Android build without ant

13 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Felipe Monteiro de Carvalho

Hello,

I see that some people that follow this list have been doing this with the FPC Java port, so I though: Does anyone have a script which does the calls to build an APK (right from beginning, that is, building Java code, till the APK signing for debug).

I'm not interrested in FPC Java, but I guess that I could adapt such a script for LCL-CustomDrawn-Android usage. Right now I am googling, but I haven't found much info on building without ANT, and removing ANT from the process would greatly simplify the building in Windows.

thanks,

Felipe Monteiro de Carvalho

Reply by email

Unknown author
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 11 lines
Hello, I see that some people that follow this list have been doing this with the FPC Java port, so I though: Does anyone have a script which does the calls to build an APK (right from beginning, that is, building Java code, till the APK signing for debug). I'm not interrested in FPC Java, but I guess that I could adapt such a script for LCL-CustomDrawn-Android usage. Right now I am googling, but I haven't found much info on building without ANT, and removing ANT from the process would greatly simplify the building in Windows.

The example of Sven Barth contains a makefile that does all steps.

If you can't find it, let me know, I'll mail it to you.

Michael.

Reply by email

Sven Barth
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 7 lines
Ok, I reviewed old threads and found a download link: http://web390.server-drome.com/files/trainlog.zip thanks =)

Bingo ;)

If you need help, please feel free to ask.

PS: One of the tools is considered deprecated (and will print such a message), but it does still work. Somewhen in the future I plan to write a tool (in FPC JVM of course) which uses the class the original tool is based on (the class is not deprecated and used by the Ant build system itself).

Regards,
Sven

Reply by email

Felipe Monteiro de Carvalho
to Sven Barth

Hello,

Ok, so far I have this script:

=================
cmd

SET PATH=C:\Programas\android-sdk\tools;C:\Programas\android-sdk\platform-tools\;C:\Progra~1\Java\jdk1.6.0_20\bin

mkdir bin
mkdir bin\classes

javac -classpath
C:\Programas\android-sdk\platforms\android-8\android.jar -d bin\classes src\com\pascal\lcltest\LCLActivity.java

dx --dex --no-strict --output=bin\classes.dex
F:\Programas\lazarussvn\examples\androidlcl\android\bin\classes\com\pascal\lcltest\LCLActivity.class

apkbuilder bin\androidlcltest-unsigned.apk -u -z
bin\androidlcltest.ap_ -f bin\classes.dex

pause
====================

But when executing "dx -dex" I have a lot of errors.

If I don't put a full path, but just write
bin\classes\com\pascal\lcltest\LCLActivity.class it will say it can't find the class file.

If I don't use --no-strict it will say that the paths don't match

And like I am using it now I get:

F:\Programas\lazarussvn\examples\androidlcl\android>dx --dex --no-strict --outpu t=bin\classes.dex F:\Programas\lazarussvn\examples\androidlcl\android\bin\classe s\com\pascal\lcltest\LCLActivity.class

UNEXPECTED TOP-LEVEL ERROR:
java.io.FileNotFoundException: bin\classes.dex (System nie mo?e odnale?? okre?lo nej ?cie?ki)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source) at java.io.FileOutputStream.<init>(Unknown Source) at com.android.dx.command.dexer.Main.openOutput(Main.java:708) at com.android.dx.command.dexer.Main.run(Main.java:239) at com.android.dx.command.dexer.Main.main(Main.java:174) at com.android.dx.command.Main.main(Main.java:95)

Which is complete non-sense ... it should create this file =/

PS: Ok, now I found ... if I put the full path for the output file it seams to work. So I will send this anyway in case someone in the future has the same issue.

Going further it simply stops while running apkbuilder and says nothing which makes me really lost =)

And it is really annoying that the entire script quits running if any command fails, is there any way to make it more resistent? I would like it to stop at the final pause so that I can more easily see the output ... even if some commands fail I'd like it to keep running...

Felipe Monteiro de Carvalho

Reply by email

Felipe Monteiro de Carvalho
to Felipe Monteiro de Carvalho

Hello,

Ok, now I advanced a lot =)

=============================
REM Adjust these paths to yours
SET PATH=C:\Programas\android-sdk\tools;C:\Programas\android-sdk\platform-tools\;C:\Progra~1\Java\jdk1.6.0_20\bin SET ANDROID_HOME=C:\Programas\android-sdk
SET APK_SDK_PLATFORM=C:\Programas\android-sdk\platforms\android-8 SET APK_PROJECT_PATH=F:\Programas\lazarussvn\examples\androidlcl\android

mkdir bin
mkdir bin\classes
mkdir gen
mkdir gen\com
mkdir gen\com\pascal
mkdir gen\com\pascal\lcltest

REM Resource compilation
aapt p -f -M AndroidManifest.xml -F bin\androidlcltest.ap_ -I %APK_SDK_PLATFORM%\android.jar -S res -m -J gen

REM Java compiler
javac -classpath %APK_SDK_PLATFORM%\android.jar -d bin\classes src\com\pascal\lcltest\LCLActivity.java

REM DX to convert the java bytecode to dalvik bytecode dx --dex --no-strict --output=%APK_PROJECT_PATH%\bin\classes.dex %APK_PROJECT_PATH%\bin\classes\com\pascal\lcltest\LCLActivity.class

REM Now build the unsigned APK
apkbuilder bin\androidlcltest-unsigned.apk -u -z
bin\androidlcltest.ap_ -f bin\classes.dex

pause
==================

Still no idea about these issues:

1-> How to integrate the .so native library into the process

2-> Why apkbuilder quits without saying anything

Felipe Monteiro de Carvalho

Reply by email

Sven Barth
to Felipe Monteiro de Carvalho: Ok, so far I have this script: ================= cmd SET…
Felipe Monteiro de Carvalho wrote 18 lines
Hello, Ok, so far I have this script: ================= cmd SET PATH=C:\Programas\android-sdk\tools;C:\Programas\android-sdk\platform-tools\;C:\Progra~1\Java\jdk1.6.0_20\bin mkdir bin mkdir bin\classes javac -classpath C:\Programas\android-sdk\platforms\android-8\android.jar -d bin\classes src\com\pascal\lcltest\LCLActivity.java dx --dex --no-strict --output=bin\classes.dex F:\Programas\lazarussvn\examples\androidlcl\android\bin\classes\com\pascal\lcltest\LCLActivity.class

AFAIK it should be

dx --dex --no-strict --output=bin\classes.dex
F:\Programas\lazarussvn\examples\androidlcl\android\bin\classes

Note that the path only goes up to "classes" not the class path below it.

Show quoted text 5 lines
And it is really annoying that the entire script quits running if any command fails, is there any way to make it more resistent? I would like it to stop at the final pause so that I can more easily see the output ... even if some commands fail I'd like it to keep running...

You should look for the concepts of "errorlevel" and "if". See e.g. here:

http://ss64.com/nt/if.html
http://www.robvanderwoude.com/errorlevel.php

AFAIK the variable ERRORLEVEL is set if you run a program (perhaps you need to use "call" for it, don't know). I've never used the concept though up to now, so you'll need to inform yourself.

Regards,
Sven

Reply by email

Felipe Monteiro de Carvalho
to Sven Barth

Hello,

Thanks, "call" seams to do the trick.

The next issues:

1> How to add more files to the apk. aapt tool seams to have no way for me to specify where the file will be inside the package and here it simply strips all of the paths, not even keeping the relative dir =/

F:\Programas\lazarussvn\examples\androidlcl\android>aapt a bin\androidlcltest.ap _ libs\armeabi\liblclapp.so
'libs\armeabi\liblclapp.so' as 'liblclapp.so'... <<--- I want it to add as "lib\armeabi\liblclapp.so"

Maybe I will have to write a tool for this =/

2> Signing. Your method seams to require a "keystore" and even asks me for a password? But plain "ant debug" does not require any password to be typed and just works .... any ideas how it achieves that?

Enter Passphrase for keystore:
jarsigner error: java.lang.RuntimeException: keystore load: C:\Documents and Set tings\Opera\.keystore (Nie mo?na odnale?? okre?lonego pliku) Aby kontynuowa?, naci?nij dowolny klawisz . . .

Current file:

============================
REM Adjust these paths to yours
SET PATH=C:\Programas\android-sdk\tools;C:\Programas\android-sdk\platform-tools\;C:\Progra~1\Java\jdk1.6.0_20\bin SET APP_NAME=androidlcltest
SET ANDROID_HOME=C:\Programas\android-sdk
SET APK_SDK_PLATFORM=C:\Programas\android-sdk\platforms\android-8 SET APK_PROJECT_PATH=F:\Programas\lazarussvn\examples\androidlcl\android

mkdir bin
mkdir bin\classes
mkdir gen
mkdir gen\com
mkdir gen\com\pascal
mkdir gen\com\pascal\lcltest

REM Cleanup
del bin\%APP_NAME%.ap_

REM Resource compilation
call aapt p -f -M AndroidManifest.xml -F bin\%APP_NAME%.ap_ -I %APK_SDK_PLATFORM%\android.jar -S res -m -J gen
aapt a bin\%APP_NAME%.ap_ libs\armeabi\liblclapp.so

REM Java compiler
call javac -classpath %APK_SDK_PLATFORM%\android.jar -d bin\classes src\com\pascal\lcltest\LCLActivity.java

REM DX to convert the java bytecode to dalvik bytecode call dx --dex --output=%APK_PROJECT_PATH%\bin\classes.dex %APK_PROJECT_PATH%\bin\classes

REM It seams that dx calls echo off
@echo on
REM Now build the unsigned APK
call apkbuilder %APK_PROJECT_PATH%\bin\%APP_NAME%-unsigned.apk -u -z %APK_PROJECT_PATH%\bin\%APP_NAME%.ap_ -f
%APK_PROJECT_PATH%\bin\classes.dex

REM Signing the APK with a debug key
REM KEYSTORE = /home/sven/android.keystore -keystore $(KEYSTORE) jarsigner -signedjar bin\%APP_NAME%.apk bin\%APP_NAME%-unsigned.apk debugkey

REM call and pause together allow us to see the results in the end pause
============================

Felipe Monteiro de Carvalho

Reply by email

Sven Barth
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 17 lines
Hello, Thanks, "call" seams to do the trick. The next issues: 1> How to add more files to the apk. aapt tool seams to have no way for me to specify where the file will be inside the package and here it simply strips all of the paths, not even keeping the relative dir =/ F:\Programas\lazarussvn\examples\androidlcl\android>aapt a bin\androidlcltest.ap _ libs\armeabi\liblclapp.so 'libs\armeabi\liblclapp.so' as 'liblclapp.so'...<<--- I want it to add as "lib\armeabi\liblclapp.so" Maybe I will have to write a tool for this =/

Maybe you can check how the corresponding tasks in the Ant file work. I have never used aapt for native binaries yet, so I'm in uncharted area as well as you are. But maybe googling for aapt and paths can help you ;)

Show quoted text 8 lines
2> Signing. Your method seams to require a "keystore" and even asks me for a password? But plain "ant debug" does not require any password to be typed and just works .... any ideas how it achieves that? Enter Passphrase for keystore: jarsigner error: java.lang.RuntimeException: keystore load: C:\Documents and Set tings\Opera\.keystore (Nie mo?na odnale?? okre?lonego pliku) Aby kontynuowa?, naci?nij dowolny klawisz . . .

"ant debug" uses a predefined debug key. You need to create your own one as outlined here:

http://wiki.freepascal.org/FPC_JVM_Android_Development#Generate_a_Key_Store

AFAIK you can also pass the keystore passwords as part of the command line.

Regards,
Sven

Reply by email

Kjow
to Felipe Monteiro de Carvalho: I see that some people that follow this list have been doing this with the FPC Java port,…

2012/3/26 Felipe Monteiro de Carvalho :

Show quoted text 15 lines
Hello, I see that some people that follow this list have been doing this with the FPC Java port, so I though: Does anyone have a script which does the calls to build an APK (right from beginning, that is, building Java code, till the APK signing for debug). I'm not interrested in FPC Java, but I guess that I could adapt such a script for LCL-CustomDrawn-Android usage. Right now I am googling, but I haven't found much info on building without ANT, and removing ANT from the process would greatly simplify the building in Windows. thanks, -- Felipe Monteiro de Carvalho

Hi,

this is a great thing :)

__

I don't think so, but maybe ZenGL could be usefull (it can compile android/ios/desktops apps with fpc 2.6 also on Windows):

http://zengl.org/wiki/doku.php?id=compilation:android

I'm sorry if this post is useless, I'm not yet inside lazarus for android... but I will start to try soon (I hope).

Regards,
Kjow

Reply by email

Felipe Monteiro de Carvalho
to Sven Barth: Maybe you can check how the corresponding tasks in the Ant file work. I have never used…
Sven Barth wrote
"ant debug" uses a predefined debug key. You need to create your own one as outlined here: http://wiki.freepascal.org/FPC_JVM_Android_Development#Generate_a_Key_Store

I think I managed to get it somewhat working, at least it gives no errors, but still it didn't add any files to the APK. Does it add files to the APK for you after signing or is signing something internal to the zip structure?

I was expecting it to create a META-INF directory in the zip and put some files there as I am comparing the output from "ant debug" with the one from my batch script.

Felipe Monteiro de Carvalho

Reply by email

Sven Barth
to Felipe Monteiro de Carvalho: Thanks, "call" seams to do the trick. The next issues: 1> How to add more files to the…
Felipe Monteiro de Carvalho wrote 12 lines
The next issues: 1> How to add more files to the apk. aapt tool seams to have no way for me to specify where the file will be inside the package and here it simply strips all of the paths, not even keeping the relative dir =/ F:\Programas\lazarussvn\examples\androidlcl\android>aapt a bin\androidlcltest.ap _ libs\armeabi\liblclapp.so 'libs\armeabi\liblclapp.so' as 'liblclapp.so'...<<--- I want it to add as "lib\armeabi\liblclapp.so"

I just got an idea: what if you specifiy only the "libs" directory and not the library itself? It seems that aapt just plainly adds what you tell it.

So:

aapt a bin\androidlcltest.ap_ libs

Note: I did not test it, it's just an idea.

Regards,
Sven

Reply by email