Recent

Author Topic: [solved]Unable to build apk under windows  (Read 19535 times)

huberte

  • Jr. Member
  • **
  • Posts: 78
[solved]Unable to build apk under windows
« on: April 27, 2012, 03:46:01 am »
I followed http://wiki.lazarus.freepascal.org/Custom_Drawn_Interface/Android#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"

Quote
D:\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
« Last Edit: April 29, 2012, 10:53:50 pm by huberte »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Unable to build apk under windows
« Reply #1 on: April 27, 2012, 08:36:32 am »
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

  • Jr. Member
  • **
  • Posts: 78
Re: Unable to build apk under windows
« Reply #2 on: April 27, 2012, 12:35:08 pm »
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)
« Last Edit: April 27, 2012, 12:45:03 pm by huberte »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Unable to build apk under windows
« Reply #3 on: April 27, 2012, 01:44:14 pm »
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)

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?

Quote
and 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.
« Last Edit: April 27, 2012, 01:47:34 pm by felipemdc »

huberte

  • Jr. Member
  • **
  • Posts: 78
Re: Unable to build apk under windows
« Reply #4 on: April 27, 2012, 07:15:21 pm »
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 :
Quote
D:\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

Quote
D:\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

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Unable to build apk under windows
« Reply #5 on: April 27, 2012, 08:06:27 pm »
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

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?

Quote
THIS 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

  • Jr. Member
  • **
  • Posts: 78
Re: Unable to build apk under windows
« Reply #6 on: April 27, 2012, 08:27:08 pm »
Pretty much the same I mentionned above

Quote
Deleting 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

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Unable to build apk under windows
« Reply #7 on: April 27, 2012, 09:58:11 pm »
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
« Last Edit: April 27, 2012, 10:00:56 pm by felipemdc »

huberte

  • Jr. Member
  • **
  • Posts: 78
Re: Unable to build apk under windows
« Reply #8 on: April 27, 2012, 11:40:04 pm »
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

Quote
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
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.<clinit>(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.performLaunchActivity(ActivityThread.java:1565)
W/System.err( 1181):    at android.app.ActivityThread.handleLaunchActivity(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$MethodAndArgsCaller.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.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 1181):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
E/AndroidRuntime( 1181):        at android.app.ActivityThread.handleLaunchActivity(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
« Last Edit: April 28, 2012, 02:08:36 am by huberte »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Unable to build apk under windows
« Reply #9 on: April 28, 2012, 04:03:53 pm »
THKS ! uninstalled v7, installed v6 : works.

v7 of what? JDK?

Quote
Building 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

  • Jr. Member
  • **
  • Posts: 78
Re: Unable to build apk under windows
« Reply #10 on: April 28, 2012, 09:54:44 pm »
Quote
v7 of what? JDK?

Yes, I will add this to the wiki, v7 has some pb with android.

Quote
I 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 :

Quote
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

Note : we have to change strings.xml in android\res\values too when building a new project, will add this too...

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Unable to build apk under windows
« Reply #11 on: April 29, 2012, 11:16:37 am »
Just 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.

Quote
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 :

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.
« Last Edit: April 29, 2012, 05:25:07 pm by felipemdc »

huberte

  • Jr. Member
  • **
  • Posts: 78
Re: Unable to build apk under windows
« Reply #12 on: April 29, 2012, 04:26:23 pm »
Quote
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.

I do that for a long time now :

In android\src\com\pascal\lclbtn

I have LCLActivity.java with

Quote
package com.pascal.lclbtn;

import android.app.*;

EXIT :

Here a more detailed logcat :

Quote
D/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.performLaunchActivity(ActivityThread.java:1565)
E/AndroidRuntime(20374):        at android.app.ActivityThread.handleLaunchActivity(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.<clinit>(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
« Last Edit: April 29, 2012, 09:48:32 pm by huberte »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Unable to build apk under windows
« Reply #13 on: April 29, 2012, 10:32:54 pm »
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.
« Last Edit: April 29, 2012, 10:34:57 pm by felipemdc »

huberte

  • Jr. Member
  • **
  • Posts: 78
Re: Unable to build apk under windows
« Reply #14 on: April 29, 2012, 10:52:07 pm »
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 ?
« Last Edit: April 29, 2012, 11:45:16 pm by huberte »