Thanks all for the helps and suggestions. But unfortunately, the result is same: "Unfortunately, Project1 has stopped."
Although, I'm still not able to produce correct APK for Android Intel 64-bit, here I post all the things I found. Hope it would be useful for someone who is willing to try and for LazForApk/laz4Android future improvement.
1. Extract the apk and see if the file structure is correct. Under the unzipped directory, there is a "lib" folder and there should be 2 sub-folders(armeabi & x86) in "lib". Check if the files in those 2 sub folders correspond to the CPU structure.
I now able to produce x86 only and fat binaries (armeabi & x86). But the code just won't run on my phone. It make me think that the problem wasn't my failure to create x86 lib in the apk file.
On my previous attempts, I failed to build x86 lib in the apk file because of 2 reasons:
1. On the Lazarus - Project Settings, I didn't notice that I have to change "
android\libs\armeabi\liblclapp" to "
android\libs\x86\liblclapp" on the
Path >
Target File Name setting. It caused the result file (x86 code) to be saved in the folder named armeabi.
2. The script file "
build_debug_apk.bat" generated by LazForApk contain hardcoded text "armeabi" but without "x86". So I have to manually added the text "x86".
2. Write a simplest "Hello World" test app to see whether it works. If it works, maybe there's something wrong in your code?
I didn't write my own code for the tests. But I used the default test project generated by LazForApk. So it makes me think that perhaps the
default test project generated by LazForApk or the
Custom Drawn package might ever call any function that is only for arm machines, which is not compatible with Intel 64-bit.
Library Path:
$(LazarusDir)\Android_NDK\platforms\android-9\arch-x86\usr\lib;
$(LazarusDir)\Android_NDK\toolchains\x86-4.8\prebuilt\windows\lib\gcc\i686-linux-android\4.8
and no Custom Options.
Maybe you missed my second library path.
I have tested with the second library path added + with/without custom options. I also have tried with:
- ...\platforms\
android-9\...
- ...\platforms\
android-16\...
- ...\toolchains\x86-4.8\...\i686-linux-android\
4.8- ...\toolchains\x86-4.8\...\i686-linux-android\
4.9I think it's not laz4android problems , laz4android is support android x86 compiled ok.
I think maybe when the Laztoapk build the APK file, it's not include x86 folder into the android APK file.
please try use the attachments(build_debug_apk_new.bat) to build the APK file.
Thank you truetom for the new script file. It can't run, but I managed to fix it by changing the paths to mine. Also there was one missing file on this line:
REM Convert the java bytecode to dalvik bytecode
call java -Djava.ext.dirs=%ANDROID_HOME%\platform-tools\lib\ -jar %ANDROID_HOME%\platform-tools\lib\dx.jar --dex --verbose --output=%APK_PROJECT_PATH%\bin\classes.dex %APK_PROJECT_PATH%\bin\classes
The code above (in build_debug_apk_new.bat) need to be changed to:
REM DX to convert the java bytecode to dalvik bytecode
call java -Djava.ext.dirs=%ANDROID_HOME%\platform-tools\lib\ -jar %ANDROID_HOME%\build-tools\%SDK_BUILDTOOLS%\lib\dx.jar --dex --verbose --output=%APK_PROJECT_PATH%\bin\classes.dex %APK_PROJECT_PATH%\bin\classes
The difference is the file "
..\lib\dx.jar" should not be be located under "...\platform-tools" because there no such file in that location. It works if I changed it to "
...\build-tools\%SDK_BUILDTOOLS%\lib\dx.jar"
Now the new script file is able to run correctly.
did you look at the sourcecode of laztoapk?
You try to use laztoapk to build x86 android apps. This is not supported by laztoapk.
I would need to change things in laztoapk.
If you look at the code
http://sourceforge.net/p/laztoapk/svn/HEAD/tree/trunk/source/apkmanagermain.pas#l965
and search for "CopyNDKFilesToFPC" you will see that laztoapk copies only arm -stuff from the ndk folder into the laz4android folder.
Yep, I had already noticed it and tested to copy the x86 version of NDK files before you told me. But I just re-performed the test again with combining all the suggestions (as I mentioned above), but still got the same error.
Can anyone tell me, my phone is Intel Atom 64-bit, is it able to run code that compiled by Lazarus with
Intel I386 setting? Or must I change the Lazarus
Target CPU Family setting to x86_64? I tried to change it to x86_64, but it can't because it hasn't cross compile to that target.
Those above are what I found so far, hope it can be useful for others.