Recent

Author Topic: Android on Lazarus  (Read 9840 times)

mbdev

  • New Member
  • *
  • Posts: 44
Android on Lazarus
« on: March 20, 2013, 09:35:07 pm »
Hello,
I want to develop Android apps with my Lazarus. I'm usining Lazarus v.1.0.8 and Freepascal 2.6.2.
I tried to make a simple Android app, but it crashs with the error:

C:\lazarus\fpc\2.6.2\bin\i386-win32\arm-linux-ld.exe: warning: link.res contains output sections; did you forget -T?
C:\lazarus\fpc\2.6.2\bin\i386-win32\arm-linux-ld.exe: C:\Android\ndk-r8d\platforms\android-9\arch-arm\usr\lib\/libjnigraphics.so: Unknown mandatory EABI object attribute 44
C:\lazarus\fpc\2.6.2\bin\i386-win32\arm-linux-ld.exe: failed to merge target specific data of file C:\Android\ndk-r8d\platforms\android-9\arch-arm\usr\lib\/libjnigraphics.so

I'm not sure what I did wrong, because I also added "-dAndroid" in the LCLBase (See Screenshot)  :(

Leledumbo

  • Hero Member
  • *****
  • Posts: 8244
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Android on Lazarus
« Reply #1 on: March 20, 2013, 11:27:28 pm »
I don't you can do it with FPC 2.6.2, you'll need quite new trunk (2.7.1 no more than a week ago) or the old hacked 2.5.1. Please read the wiki instruction regarding Android. Here if you use 2.7.1.

mbdev

  • New Member
  • *
  • Posts: 44
Re: Android on Lazarus
« Reply #2 on: March 27, 2013, 06:27:16 pm »
Hi,
I prepared it with FPC 2.7.1 but I'm getting the same error :/
Could it be that something is wrong with my android NDK?

mbdev

  • New Member
  • *
  • Posts: 44
Re: Android on Lazarus
« Reply #3 on: March 27, 2013, 06:58:24 pm »
I fixed it  :D

It was wrong that I used the NDK8C and I just changed to the NDK7C  8)

mbdev

  • New Member
  • *
  • Posts: 44
Re: Android on Lazarus
« Reply #4 on: March 27, 2013, 09:55:23 pm »
I've got another question.
Where I need to put my compiled application when I want to generate the apk-file.

The script (generate_debug_apk.bat):
Code: [Select]
REM Adjust these paths to yours
SET PATH=C:\Android\sdk-20130219\sdk\tools;C:\Android\sdk-20130219\sdk\platform-tools\;C:\Program Files\Java\jdk1.6.0_43\bin
SET APP_NAME=Testapp
SET ANDROID_HOME=C:\Android\sdk-20130219\sdk
SET APK_SDK_PLATFORM=C:\Android\sdk-20130219\sdk\platforms\android-8
SET APK_PROJECT_PATH=C:\Users\Administrator\Desktop\Project\Testapp\android

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

REM More directory preparation
copy libs\armeabi\*.so raw\lib\armeabi\

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

REM Java compiler
call javac -verbose -encoding UTF8 -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 --verbose --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
del %APK_PROJECT_PATH%\bin\%APP_NAME%-unsigned.apk
call apkbuilder %APK_PROJECT_PATH%\bin\%APP_NAME%-unsigned.apk -v -u -z %APK_PROJECT_PATH%\bin\%APP_NAME%.ap_ -f %APK_PROJECT_PATH%\bin\classes.dex

REM Generating on the fly a debug key
rem keytool -genkey -v -keystore bin\LCLDebugKey.keystore -alias LCLDebugKey -keyalg RSA -validity 10000 -dname NAME -storepass senhas -keypass senhas

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

REM Align the final APK package
zipalign -v 4 bin\%APP_NAME%-unaligned.apk bin\%APP_NAME%.apk

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

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Android on Lazarus
« Reply #5 on: March 28, 2013, 10:21:42 am »
The shared object should be placed in lib\armeabi\

mbdev

  • New Member
  • *
  • Posts: 44
Re: Android on Lazarus
« Reply #6 on: March 28, 2013, 12:33:11 pm »
Hm,

I put my compile app in the lib\armeabi\ folder and renamed it to Testapp.so.
Now my application is bigger, but it crashs at startup  :(

Hopefully somebody can help me, I also uploaded my project (without android folder).

Here are my scripts:
build_debug_apk.bat
Code: [Select]
REM Adjust these paths to yours
SET PATH=C:\Android\sdk-20130219\sdk\tools;C:\Android\sdk-20130219\sdk\platform-tools\;C:\Program Files\Java\jdk1.6.0_43\bin
SET APP_NAME=Testapp
SET ANDROID_HOME=C:\Android\sdk-20130219\sdk
SET APK_SDK_PLATFORM=C:\Android\sdk-20130219\sdk\platforms\android-8
SET APK_PROJECT_PATH=C:\Users\Administrator\Desktop\Project\Testapp\android

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

REM More directory preparation
copy libs\armeabi\*.so raw\lib\armeabi\

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

REM Java compiler
call javac -verbose -encoding UTF8 -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 --verbose --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
del %APK_PROJECT_PATH%\bin\%APP_NAME%-unsigned.apk
call apkbuilder %APK_PROJECT_PATH%\bin\%APP_NAME%-unsigned.apk -v -u -z %APK_PROJECT_PATH%\bin\%APP_NAME%.ap_ -f %APK_PROJECT_PATH%\bin\classes.dex

REM Generating on the fly a debug key
rem keytool -genkey -v -keystore bin\LCLDebugKey.keystore -alias LCLDebugKey -keyalg RSA -validity 10000 -dname NAME -storepass senhas -keypass senhas

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

REM Align the final APK package
zipalign -v 4 bin\%APP_NAME%-unaligned.apk bin\%APP_NAME%.apk

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

generate_debug_key.bat
Code: [Select]
REM Adjust these paths to yours
SET PATH=C:\Android\sdk-20130219\sdk\tools;C:\Android\sdk-20130219\sdk\platform-tools\;C:\Program Files\Java\jdk1.6.0_43\bin
SET APP_NAME=Testapp
SET ANDROID_HOME=C:\Android\sdk-20130219\sdk
SET APK_SDK_PLATFORM=C:\Android\sdk-20130219\sdk\platforms\android-8
SET APK_PROJECT_PATH=C:\Users\Administrator\Desktop\Project\Testapp\android


mkdir bin

keytool --help

keytool -genkey -v -keystore bin\LCLDebugKey.keystore -alias LCLDebugKey -keyalg RSA -validity 10000

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

I don't understand what I have to do with my compiled linux-arm app?

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Android on Lazarus
« Reply #7 on: March 28, 2013, 01:30:40 pm »
I put my compile app in the lib\armeabi\ folder and renamed it to Testapp.so.
Now my application is bigger, but it crashs at startup  :(

What was the name before you renamed it? It should already have been the proper name.

Study the example application that comes with Lazarus. Android native applications are not executables, they are libraries, and they need to export a set of functions with the proper name refleting the package name of the application.

mbdev

  • New Member
  • *
  • Posts: 44
Re: Android on Lazarus
« Reply #8 on: March 28, 2013, 03:02:20 pm »
It was just named Testapp without a file extension  :o

Like here: http://www.pilotlogic.com/sitejoom/index.php/codetyphon/codetyphon-help (last picture on 10.2.3)
« Last Edit: March 28, 2013, 03:03:57 pm by mbdev »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Android on Lazarus
« Reply #9 on: March 28, 2013, 04:17:49 pm »
Does your project main source file start with "program"? If it does, then it is wrong, it should be "library". Study the example.

mbdev

  • New Member
  • *
  • Posts: 44
Re: Android on Lazarus
« Reply #10 on: March 28, 2013, 07:44:01 pm »
THANK YOU SO MUCH  :)

It was a program. Now my app runs fine and I can understand why :)
You helped me a lot  ;)

 

TinyPortal © 2005-2018