[solved]Unable to build apk under windows lazarus / 43-Android ---------------------------------------------------------------------- huberte · 2012-04-27 01:46 I followed http://wiki.lazarus.freepascal.org/Custom_Drawn_Interface/A ndroid#Step_4_-_Creating_the_APK_package_in_Windows, with the latest svn from Lazarus. Here are the "bugs" when I try to build the apk for "example\androidlcl" QuoteD:\Svendi\Lazarus\Android\androidlcl3tbn\android>call javac -verbose -classpath D:\Svendi\Lazarus\Programmes\android- sdk\platforms\android-15\android.jar -d bin\classes src\com\pascal\lclbtn\LCLActivity.java src\com\pascal\lclbtn\LCLActivity.java:341: error: unmappable character for encoding Cp1252     localpaint.getTextBounds("├?qg", 0, 3, localbounds);                                ^ In this file you have a strange caracter on line 341 Deleting it (yep I know ) and trying to relauch ends with http://pastebin.com/MQmy5cpK ---------------------------------------------------------------------- felipemdc · 2012-04-27 06:36 It is not a bug in my code, Java should not do that conversion of Unicode->CPsomething. Maybe we are missing some kind of option for javac which will tell it to use Unicode only. Your Windows is for which language? ---------------------------------------------------------------------- huberte · 2012-04-27 10:35 french. why would it be related with the windows french languague ? I did check the java gile it's encoded in UTF8 (see the file) Quote    lclwidth = lclwidth + (3 * lcltextsize) / 16;     // Don't use just localbounds.height() from the source text     // because it will calculate the minimum necessary height,     // but we can't easily use that to draw text because it draws relative to the baseline     localpaint.getTextBounds("Íqg", 0, 3, localbounds);     lclheight = localbounds.height(); and then why those all bugs ? (paste.bin) ---------------------------------------------------------------------- felipemdc · 2012-04-27 11:44 Quote from: huberte on April 27, 2012, 12:35:08 pmfrench. why would it be related with the windows french languague ? I did check the java gile it's encoded in UTF8 (see the file) The error comes from your Java JDK, in my computer there is no error. I have an polish Windows here. Why would it choose this particular encoding for the file? The JDK probably choose the Windows encoding to use for the file. I read here: http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/javac.html And they say that there is a -encoding directory to javac. Could you try adding "-encoding utf8" or "-encoding utf-8" to the javac call in the batch file and see if this fixes the issue? Quoteand then why those all bugs ? (paste.bin) You are probably using a non-UTF-8 editor. Use Lazarus to open the file and you will see that the string is correct. You can also use a hexadecimal editor to check that it is correct. ---------------------------------------------------------------------- huberte · 2012-04-27 17:15 No error with : Quote-verbose -classpath %APK_SDK_PLATFORM%\android.jar -d bin\classes -encoding utf8 src\com\pascal\lcltest\LCLActivity.java I will add this to the wiki Like I said there were others error (see the paste bin links after), this one occurs : QuoteD:\Svendi\Lazarus\Android\androidlcl\android>call dx --dex --verbose --output=D:\Svendi\Lazarus\Android\androidlcl\android\bin\classes.dex D:\Svendi\Lazarus\Android\androidlcl\android\bin\classes processing D:\Svendi\Lazarus\Android\androidlcl\android\bin\classes\.\ com\pascal\lcltest\LCLActivity$1.class... trouble processing: bad class file magic (cafebabe) or version (0033.0000) ...while parsing com/pascal/lcltest/LCLActivity$1.class ...while processing com/pascal/lcltest/LCLActivity$1.class processing D:\Svendi\Lazarus\Android\androidlcl\android\bin\classes\.\ com\pascal\lcltest\LCLActivity$2.class... This error occurs with 10 warnings Then this QuoteD:\Svendi\Lazarus\Android\androidlcl\android>REM Now build the unsigned APK D:\Svendi\Lazarus\Android\androidlcl\android>del D:\Svendi\Lazarus\Android\androidlcl\android\bin\androidlcltest- unsigned.apk Impossible de trouver D:\Svendi\Lazarus\Android\androidlcl\android\bin\androidlcltest- unsigned.apk D:\Svendi\Lazarus\Android\androidlcl\android>call apkbuilder D:\Svendi\Lazarus\Android\androidlcl\android\bin\androidlcltest- unsigned.apk -v -u -z D:\Svendi\Lazarus\Android\androidlcl\android\bin\andr oidlcltest.ap_ -f D:\Svendi\Lazarus\Android\androidlcl\android\bin\classes.dex THIS TOOL IS DEPRECATED. See --help for more information. thks ---------------------------------------------------------------------- felipemdc · 2012-04-27 18:06 Quote from: huberte on April 27, 2012, 07:15:21 pmtrouble processing: bad class file magic (cafebabe) or version (0033.0000) ...while parsing com/pascal/lcltest/LCLActivity$1.class ...while processing com/pascal/lcltest/LCLActivity$1.class processing D:\Svendi\Lazarus\Android\androidlcl\android\bin\classes\.\ com\pascal\lcltest\LCLActivity$2.class... This error occurs with 10 warnings Strange, I never had so much trouble. It sounds like there is some problem with your javac ... but anyway if it works then maybe this can be ignored. Could you post the 10 warnings too? QuoteTHIS TOOL IS DEPRECATED. See --help for more information. There is no error here. It is just an information. They say it is deprecated but I am not aware of the new way that they recommend, so for now it will stay like that. ---------------------------------------------------------------------- huberte · 2012-04-27 18:27 Pretty much the same I mentionned above QuoteDeleting it (yep I know ) and trying to relauch ends with http://pastebin.com/MQmy5cpK http://pastebin.com/s0zKJWVF Hoping I did not make a silly syntax or path error ---------------------------------------------------------------------- felipemdc · 2012-04-27 19:58 Ummm ... I have no idea personally, for me and for other people working with me it worked fine. Maybe because I have Windows XP 32 bits. Or maybe I am using an older JDK or older Android SDK... Anyway, you should try Google too. There are lots of other people which have the same problem as you, and it is completely generic to Android, nothing Pascal specific here. Read: https://www.google.com/search?client=opera&rls=en&q=android+bad+class+ file+magic+(cafebabe)+or+version+(0033.0000)&sourceid=opera&ie=utf- 8&oe=utf-8&channel=suggest http://stackoverflow.com/questions/7866723/dx-bad-class-file-magic- cafebabe-or-version-0033-0000-with-adk14 http://stackoverflow.com/questions/8538891/bad-class-file-magic-when- using-dx-bat http://stackoverflow.com/questions/8926704/bad-classfile-magic- cafebabe-or-version-0033-0000 ---------------------------------------------------------------------- huberte · 2012-04-27 21:40 THKS ! uninstalled v7, installed v6 : works. Building the apk : androidlcltest.apk Installed on my phone : crash (it worked on linux with 0.9.30) Shutdwon LCL Test (from process com.pascal.lcltest) Please try again here the part of the adb logcat QuoteI/lclapp  ( 1181): Trying to load liblclapp.so E/lclapp  ( 1181): WARNING: Could not load liblclapp.so W/System.err( 1181): java.lang.UnsatisfiedLinkError: Couldn't load lclapp: findLibrary returned null W/System.err( 1181):    at java.lang.Runtime.loadLibrary(Runtime.java:429) W/System.err( 1181):    at java.lang.System.loadLibrary(System.java:554) W/System.err( 1181):    at com.pascal.lcltest.LCLActivity.(LCLActivity.java:701) W/System.err( 1181):    at java.lang.Class.newInstanceImpl(Native Method) W/System.err( 1181):    at java.lang.Class.newInstance(Class.java:1409) W/System.err( 1181):    at android.app.Instrumentation.newActivity(Instrumentation.java:1021) W/System.err( 1181):    at android.app.ActivityThread.performLaunchAct ivity(ActivityThread.java:1565) W/System.err( 1181):    at android.app.ActivityThread.handleLaunchActi vity(ActivityThread.java:1667) W/System.err( 1181):    at android.app.ActivityThread.access$1500(ActivityThread.java:117) W/System.err( 1181):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935) W/System.err( 1181):    at android.os.Handler.dispatchMessage(Handler.java:99) W/System.err( 1181):    at android.os.Looper.loop(Looper.java:130) W/System.err( 1181):    at android.app.ActivityThread.main(ActivityThread.java:3691) W/System.err( 1181):    at java.lang.reflect.Method.invokeNative(Native Method) W/System.err( 1181):    at java.lang.reflect.Method.invoke(Method.java:507) W/System.err( 1181):    at com.android.internal.os.ZygoteInit$MethodAn dArgsCaller.run(ZygoteInit.java:907) W/System.err( 1181):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665) W/System.err( 1181):    at dalvik.system.NativeStart.main(Native Method) I/Launcher(30622): onWindowFocusChanged(false) D/dalvikvm(30375): GC_EXPLICIT freed <1K, 50% free 2726K/5379K, external 0K/0K, paused 57ms D/dalvikvm( 1181): GC_EXTERNAL_ALLOC freed 67K, 50% free 2737K/5379K, external 0K/0K, paused 43ms W/dalvikvm( 1181): No implementation found for native Lcom/pascal/lcltest/LCLActivity;.LCLOnCreate (Lcom/pascal/lcltest/LCLActivity;)I D/AndroidRuntime( 1181): Shutting down VM W/dalvikvm( 1181): threadid=1: thread exiting with uncaught exception (group=0x4001e578) E/AndroidRuntime( 1181): FATAL EXCEPTION: main E/AndroidRuntime( 1181): java.lang.UnsatisfiedLinkError: LCLOnCreate E/AndroidRuntime( 1181):        at com.pascal.lcltest.LCLActivity.LCLOnCreate(Native Method) E/AndroidRuntime( 1181):        at com.pascal.lcltest.LCLActivity.onCreate(LCLActivity.java:246) E/AndroidRuntime( 1181):        at android.app.Instrumentation.callAct ivityOnCreate(Instrumentation.java:1047) E/AndroidRuntime( 1181):        at android.app.ActivityThread.performL aunchActivity(ActivityThread.java:1615) E/AndroidRuntime( 1181):        at android.app.ActivityThread.handleLa unchActivity(ActivityThread.java:1667) E/AndroidRuntime( 1181):        at android.app.ActivityThread.access$1500(ActivityThread.java:117) E/AndroidRuntime( 1181):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935) E/AndroidRuntime( 1181):        at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime( 1181):        at android.os.Looper.loop(Looper.java:130) E/AndroidRuntime( 1181):        at android.app.ActivityThread.main(ActivityThread.java:3691) E/AndroidRuntime( 1181):        at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 1181):        at java.lang.reflect.Method.invoke(Method.java:507) E/AndroidRuntime( 1181):        at com.android.internal.os.ZygoteInit$ MethodAndArgsCaller.run(ZygoteInit.java:907) E/AndroidRuntime( 1181):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665) E/AndroidRuntime( 1181):        at dalvik.system.NativeStart.main(Native Method) E/        (30409): Dumpstate > /data/log/dumpstate_app_error W/ActivityManager(30409):   Force finishing activity com.pascal.lcltest/.LCLActivity I/dumpstate( 1192): begin D/dalvikvm(30622): GC_EXTERNAL_ALLOC freed 31K, 48% free 4573K/8647K, external 23869K/23947K, paused 120ms D/GLSurfaceViewGroup(30622): Skipped drawing due to suspendDrawingUntilResume() I/GLThread(30622): noticed surfaceView surface lost tid=22 W/EglHelper(30622): destroySurface()  tid=22 W/ActivityManager(30409): Activity pause timeout for HistoryRecord{40a7e408 com.pascal.lcltest/.LCLActivity} I/StatusBarPolicy(30528): onDataActivity-D:3 W/WindowManager(30409): Window Window{40a4a710 com.sec.android.app.twlauncher/com.sec.android.app.twlauncher.Launcher paused=false} destroyed surface Surface(name=com.sec.android.app.twlauncher/com.se Tell me if you need the dumpstate_app_error.txt.gz ---------------------------------------------------------------------- felipemdc · 2012-04-28 14:03 Quote from: huberte on April 27, 2012, 11:40:04 pmTHKS ! uninstalled v7, installed v6 : works. v7 of what? JDK? QuoteBuilding the apk : androidlcltest.apk Installed on my phone : crash (it worked on linux with 0.9.30) I/lclapp  ( 1181): Trying to load liblclapp.so E/lclapp  ( 1181): WARNING: Could not load liblclapp.so W/System.err( 1181): java.lang.UnsatisfiedLinkError: Couldn't load lclapp: findLibrary returned null I think that the message is pretty clear. It cannot find liblclapp.so. Do you have that file in android/libs/armeabi/ from your project? liblclapp.so should be your compiled Pascal library file. If you change it's name you need to reflect that in the .java file. Also make sure that in your main library project file you change the exported function names to reflect your Package Name. ---------------------------------------------------------------------- huberte · 2012-04-28 19:54 Quotev7 of what? JDK? Yes, I will add this to the wiki, v7 has some pb with android. QuoteI think that the message is pretty clear. Yep sorry it was a dumb question. And thks not to be angry. I'm now Ok with androidlcl example : building under the latest lazarus, building apk, running on my android. I will write a short guide too if I'm allowed to. Just have these lines when building androidlcl'apk example, is it bad ? : Quote[checking com.pascal.lcltest.LCLActivity] [loading java\lang\Error.class(java\lang:Error.class)] For my own projetc, I think I have done all the checking with renaming for my project (lclbtn), here the error on logcat when I try to launch on Android : QuoteE/AndroidRuntime( 7115): FATAL EXCEPTION: main E/AndroidRuntime( 7115): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.pascal.lclbtn/com.pascal.lclbtn.lclbtn}: java.lang.ClassNotFoundException: com.pascal.lclbtn.lclbt n in loader dalvik.system.PathClassLoader[/data/app/com.pascal.lclbtn-1.apk] Why does it write .lclbtn.lclbtn ? Like a false renaming path or project ? I searched everywhere Note : we have to change strings.xml in android\res\values too when building a new project, will add this too... ---------------------------------------------------------------------- felipemdc · 2012-04-29 09:16 Quote from: huberte on April 28, 2012, 09:54:44 pmJust have these lines when building androidlcl'apk example, is it bad ? : [checking com.pascal.lcltest.LCLActivity] [loading java\lang\Error.class(java\lang:Error.class)] I don't see any error here. He just writes that it is loading a class. QuoteFor my own projetc, I think I have done all the checking with renaming for my project (lclbtn), here the error on logcat when I try to launch on Android : E/AndroidRuntime( 7115): FATAL EXCEPTION: main E/AndroidRuntime( 7115): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.pascal.lclbtn/com.pascal.lclbtn.lclbtn}: java.lang.ClassNotFoundException: com.pascal.lclbtn.lclbt n in loader dalvik.system.PathClassLoader[/data/app/com.pascal.lclbtn-1.apk] Why does it write .lclbtn.lclbtn ? Like a false renaming path or project ? I searched everywhere ummm, maybe this one is wrong: Look at your file android/src/pascal/lclbtn/LCLActivity.java What does it's first line say? The original example says: package com.pascal.lcltest; In your case you should change the package name to your own. ---------------------------------------------------------------------- huberte · 2012-04-29 14:26 QuoteLook at your file android/src/pascal/lclbtn/LCLActivity.java What does it's first line say? The original example says: package com.pascal.lcltest; In your case you should change the package name to your own. I do that for a long time now : In android\src\com\pascal\lclbtn I have LCLActivity.java with Quotepackage com.pascal.lclbtn; import android.app.*; EXIT : Here a more detailed logcat : QuoteD/dalvikvm(20374): Added shared lib /data/data/com.pascal.lclbtn/lib/liblclapp.so 0x4051d1e8 I/lclapp  (20374): JNI_OnLoad called I/lclapp  (20374): Reading our Activity Class F/lclapp  (20374): javaEnvRef^.FindClass failed W/dalvikvm(20374): JNI_OnLoad returned bad version (-1) in /data/data/com.pascal.lclbtn/lib/liblclapp.so 0x4051d1e8 W/dalvikvm(20374): Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lcom/pascal/lclbtn/LCLActivity; W/dalvikvm(20374): Class init failed in newInstance call (Lcom/pascal/lclbtn/LCLActivity;) D/AndroidRuntime(20374): Shutting down VM W/dalvikvm(20374): threadid=1: thread exiting with uncaught exception (group=0x4001e578) E/AndroidRuntime(20374): FATAL EXCEPTION: main E/AndroidRuntime(20374): java.lang.ExceptionInInitializerError E/AndroidRuntime(20374):        at java.lang.Class.newInstanceImpl(Native Method) E/AndroidRuntime(20374):        at java.lang.Class.newInstance(Class.java:1409) E/AndroidRuntime(20374):        at android.app.Instrumentation.newActivity(Instrumentation.java:1021) E/AndroidRuntime(20374):        at android.app.ActivityThread.performL aunchActivity(ActivityThread.java:1565) E/AndroidRuntime(20374):        at android.app.ActivityThread.handleLa unchActivity(ActivityThread.java:1667) E/AndroidRuntime(20374):        at android.app.ActivityThread.access$1500(ActivityThread.java:117) E/AndroidRuntime(20374):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935) E/AndroidRuntime(20374):        at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(20374):        at android.os.Looper.loop(Looper.java:130) E/AndroidRuntime(20374):        at android.app.ActivityThread.main(ActivityThread.java:3691) E/AndroidRuntime(20374):        at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime(20374):        at java.lang.reflect.Method.invoke(Method.java:507) E/AndroidRuntime(20374):        at com.android.internal.os.ZygoteInit$ MethodAndArgsCaller.run(ZygoteInit.java:907) E/AndroidRuntime(20374):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665) E/AndroidRuntime(20374):        at dalvik.system.NativeStart.main(Native Method) E/AndroidRuntime(20374): Caused by: java.lang.NoClassDefFoundError: com.pascal.lcltest.LCLActivity E/AndroidRuntime(20374):        at java.lang.Runtime.nativeLoad(Native Method) E/AndroidRuntime(20374):        at java.lang.Runtime.loadLibrary(Runtime.java:432) E/AndroidRuntime(20374):        at java.lang.System.loadLibrary(System.java:554) E/AndroidRuntime(20374):        at com.pascal.lclbtn.LCLActivity.(LCLActivity.java:701) E/AndroidRuntime(20374):        ... 15 more E/AndroidRuntime(20374): Caused by: java.lang.ClassNotFoundException: com.pascal.lcltest.LCLActivity in loader dalvik.system.PathClassLoader[/data/app/com.pascal.lclbtn-1.apk] E/AndroidRuntime(20374):        at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) E/AndroidRuntime(20374):        at java.lang.ClassLoader.loadClass(ClassLoader.java:551) E/AndroidRuntime(20374):        at java.lang.ClassLoader.loadClass(ClassLoader.java:511) E/AndroidRuntime(20374):        ... 19 more W/ActivityManager( 5350):   Force finishing activity com.pascal.lclbtn/.LCLActivity ---------------------------------------------------------------------- felipemdc · 2012-04-29 20:32 Aha, now I see. Reading it carefully I can clearly recognize that it calls JNI_OnLoad and has issues there. See how it throws debug info writting in JNI_OnLoad: I/lclapp  (20374): JNI_OnLoad called I/lclapp  (20374): Reading our Activity Class F/lclapp  (20374): javaEnvRef^.FindClass failed <<<---- Error here W/dalvikvm(20374): JNI_OnLoad returned bad version (-1) in /data/data/com.pascal.lclbtn/lib/liblclapp.so 0x4051d1e8 And now see the file lazarus/lcl/interfaces/customdrawn/customdrawnobject_android.inc: line 487  javaActivityClass := javaEnvRef^^.FindClass(javaEnvRef,'com/pascal/lcltest/LCLActivity'); =/ Unfortunatelly there it is required the package name to find the activity class... so you need to change there too.  And I can't think of how this could be done in a way as to not require this ... It would be great if you could document in the wiki all the places that need to be changed, since I myself don't know actually =) Ideally some day the IDE should manage all of this. ---------------------------------------------------------------------- huberte · 2012-04-29 20:52 Work, At Last ! C:\lazarus\lcl\interfaces\customdrawn\customdrawnlclintf_android.inc (3 hits) Line 316:   javaActivityClass := javaEnvRef^^.FindClass(javaEnvRef,'com/pascal/lcltest/LCLActivity'); C:\lazarus\lcl\interfaces\customdrawn\customdrawnobject_android.inc (8 hits)    Line 353:   javaActivityClass := javaEnvRef^^.FindClass(javaEnvRef,'com/pascal/lcltest/LCLActivity');    Line 487:   javaActivityClass := javaEnvRef^^.FindClass(javaEnvRef,'com/pascal/lcltest/LCLActivity');         Line 444:     signature:'(Lcom/pascal/lcltest/LCLActivity;)I'; //android/app/Activity; Maybe creating a batch file where we could make all the changes ? In whixh section do you want me to post in the wiki ? ---------------------------------------------------------------------- felipemdc · 2012-04-29 21:35 Quote from: huberte on April 29, 2012, 10:52:07 pmMaybe creating a batch file where we could make all the changes ? Yes, but I will change something. Having the package name in the LCL is very nasty... the LCL should be usable in any project without changes. I will make a routine in the .java file which returns the package name. Hopefully it will work, because JNI_OnLoad is very early. QuoteIn whixh section do you want me to post in the wiki ? Here: http://wiki.lazarus.freepascal.org/Custom_Drawn_Interface/Androi d#Step_3_-_Create_the_Android_project_structure ---------------------------------------------------------------------- huberte · 2012-04-29 21:54 Ok, strange that no one else did see that... I think I'm the first to build an apk with Lazarus ---------------------------------------------------------------------- Leledumbo · 2012-04-30 04:48 QuoteOk, strange that no one else did see that... I think I'm the first to build an apk with LazarusOf course not, a couple of people must have done it, but they just never encounter such a problem or don't take the lazarus way of building andrid apps (I, for example, prefer FPC_JVM instead). ---------------------------------------------------------------------- felipemdc · 2012-04-30 08:38 Quote from: felipemdc on April 29, 2012, 11:35:41 pmYes, but I will change something. Having the package name in the LCL is very nasty... the LCL should be usable in any project without changes. I will make a routine in the .java file which returns the package name. Hopefully it will work, because JNI_OnLoad is very early. Ok, I commited my change here: http://svn.freepascal.org/cgi- bin/viewvc.cgi?view=rev&root=lazarus&revision=37099 Note that you will need to not only update your lcl but also do the small change in the .java file. You should now write the package name in your main project file, like this: library androidlcltest; ............ begin   CDWidgetset.ActivityClassName := 'com/pascal/lcltest/LCLActivity';   CDWidgetset.ActivityOnCreate := @MyActivityOnCreate; end. Please test if now you can use your project without altering the LCL ---------------------------------------------------------------------- truetom · 2012-04-30 14:16 In fact , in China ,i  have success build the androidlcltest APK at 28 February with Lazarus and it's work ok at my Lenovo Lepad A107. i also have finished write a Chinese guide to the Chinese Lazarus user.a lot of people have success build his androidlcltest APK at China. To Felipe: I have test the SVN 37100 androidlcltest , it's work fine at my Lenovo Lepad A107 .thank you great job! sorry for my bad english! ---------------------------------------------------------------------- huberte · 2012-05-01 04:15 Quote from: felipemdc on April 30, 2012, 10:38:37 amPlease test if now you can use your project without altering the LCL Great ! It Works !