Lazarus

Programming => Operating Systems => Android => Topic started by: WayneSherman on June 04, 2021, 07:56:11 pm

Title: LAMW error with Android NDK revision 22
Post by: WayneSherman on June 04, 2021, 07:56:11 pm
When installing the latest stable android NDK (revision 22):

./sdkmanager "platforms;android-29" "build-tools;29.0.3" "tools" "ndk-bundle" "extras;android;m2repository"

It creates the ./sdk/ndk-bundle directory with the NDK files correctly, but I get an error when creating a new LAMW project in Lazarus:  "Fail! Folder /home/user/android/sdk/ndk-bundle/platforms is empty!"

Error Reference in code:
https://github.com/jmpessoa/lazandroidmodulewizard/blob/master/android_wizard/uformworkspace.pas#L255 (https://github.com/jmpessoa/lazandroidmodulewizard/blob/master/android_wizard/uformworkspace.pas#L255)

According to the NDK changelog:
https://github.com/android/ndk/wiki/Changelog-r22 (https://github.com/android/ndk/wiki/Changelog-r22)
Quote
"The deprecated <NDK>/platforms and <NDK>/sysroot directories have been removed. These directories were merged and relocated into the toolchain during r19. The location of these contents should not be relevant to anyone, including build systems, since the toolchain handles them implicitly. If you are using a build system that hasn't adapted to the changes introduced in NDK r19, file a bug with your build system maintainer. See the Build System Maintainers Guide (https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md) for information on using the NDK in your own build system."

So, if LAMW needs the NDK revision number...
EDIT:  LAMW is looking here for the NDK supported API levels, not the NDK revision number.
Title: Re: LAMW error with Android NDK revision 22
Post by: DonAlfredo on June 05, 2021, 01:47:10 pm
I have just tried to fix this issue. Please test.
Also fixed: LAMW will now build with Lazarus trunk.
Title: Re: LAMW error with Android NDK revision 22
Post by: WayneSherman on June 05, 2021, 04:32:42 pm
I have just tried to fix this issue. Please test.
Also fixed: LAMW will now build with Lazarus trunk.

Yes, it works now without any work-arounds.  Thank you much.

(Will test trunk builds and report back)
Title: Re: LAMW error with Android NDK revision 22
Post by: WayneSherman on June 05, 2021, 07:02:15 pm
Yes, trunk works with LAMW.  I installed a development environment and can build an APK without errors using FPC trunk/Lazarus trunk.  (Xubuntu 20.04 64-bit + FPCUPdeluxe 1.8.2u + latest LAMW + trunk FPC + trunk Lazarus)

(test project with Andriod SDK 29, Target API 29, and NDK r22 API level 26)

Thank you
Title: Re: LAMW error with Android NDK revision 22
Post by: WayneSherman on June 05, 2021, 07:15:30 pm
I have just tried to fix this issue. Please test.
Also fixed: LAMW will now build with Lazarus trunk.

Question about NDK API levels.  There are two different lists for ARM and AArch64:

For ARM, the NDK has folders from 16 to 30 (missing 20, 25)
$HOME/android/sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/arm-linux-androideabi/

For AArch64, the NDK has folders from 21 to 30 (missing 25)
$HOME/android/sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/

But the LAMW new project wizard lists NDK API levels:  16, 17, 18, 19, 21, 22, 23, 24, 26

Why is the new project wizard missing levels 27, 28, 29, 30?

EDIT:  This is fixed.  See here: https://github.com/jmpessoa/lazandroidmodulewizard/issues/383
Title: Re: LAMW error with Android NDK revision 22
Post by: WayneSherman on June 08, 2021, 05:12:45 pm
Opened github issue:
https://github.com/jmpessoa/lazandroidmodulewizard/issues/383
Title: Re: LAMW error with Android NDK revision 22
Post by: WayneSherman on June 08, 2021, 05:59:08 pm
Same issue with NDK rev 21.4.7075529.  New project wizard is missing 27, 28, 29 and 30 NDK API platforms.

Screenshot attached.

Title: Re: LAMW error with Android NDK revision 22
Post by: jmpessoa on June 08, 2021, 06:44:49 pm
Quote
Why is the new project wizard missing levels 27, 28, 29, 30?

Please, change here and do some tests.... [Maybe in the past FPC didn't like that.....]

unit "uformworkspace.pas"  line  244  [LAMW folder "........\android_wizard"]

Code: Pascal  [Select][+][-]
  1.            if (intAux > 13) and (intAux < 27)  then
  2.            begin
  3.               ListBoxNdkPlatform.Items.Add(auxStr);
  4.               count:= count + 1;
  5.            end;
  6.  

But remember:
if you set NDK Api > 22 your app will not run on old Android 4.xxxx [and maybe 5.xxx]
Title: Re: LAMW error with Android NDK revision 22
Post by: WayneSherman on June 09, 2021, 02:49:47 am
Please, change here and do some tests.... [Maybe in the past FPC didn't like that.....]
unit "uformworkspace.pas"  line  244  [LAMW folder "........\android_wizard"]
Code: Pascal  [Select][+][-]
  1. if (intAux > 13) and (intAux < 27)  then

Changed line to:

Code: Pascal  [Select][+][-]
  1. if (intAux > 13) and (intAux <= 30)  then

Yes, it works.  Tested simple "hello world" project built with with NDK API 29 and NDK API 30, with both AARCH64 and ARMv7a+VFPv3.  Builds and runs correctly.  Tested on Pixel 4 Android 11.

Questions:
1) Is the limit for the NDK api level needed anymore, or better to remove it and populate the list with every API found in the selected NDK?

2) How does one change the NDK API level for an existing project (like AppDemo1) ?  The "NDK API" level is shown in the wizard for a new LAMW project, but for an existing project I don't see how to change it.  The Project | Project Options | LAMW Android Project Options, does not have NDK API level, only "Target SDK Version".
Title: Re: LAMW error with Android NDK revision 22
Post by: jmpessoa on June 09, 2021, 03:27:31 am
Quote
1) Is the limit for the NDK api level needed anymore, or better to remove it and populate the list with every API found in the selected NDK?

Ok, I will remove the limit....

Quote
2) How does one change the NDK API level for an existing project (like AppDemo1) ?

Ok. Will try improve the project options....

Thank you!
Title: Re: LAMW error with Android NDK revision 22
Post by: jmpessoa on June 11, 2021, 11:11:54 pm

Done!!!

Now LAMW can handle [transparently] NDK >= 22!

I thank everyone!
Title: Re: LAMW error with Android NDK revision 22
Post by: WayneSherman on June 12, 2021, 12:50:21 am
Done!!!  Now LAMW can handle [transparently] NDK >= 22!

Thank you for your work on this. :-)

I tested it and it does build and allow me to run AppDemo1 on a Pixel4 (Android 11).  I tested the following combinations:

NDK r21 ARMv7a + VFPv3 = OK
NDK r21 Aarch64 = OK
NDK r22 ARMv7a + VFPv3 = OK
NDK r22 Aarch64 = OK

Dev Environment:
    Xubuntu 20.04 64-bit w/ latest updates installed
    Android Command-Line Tools build 7302050
    OpenJDK 11
    Android SDK/API Level 29 (Android 10)
    Gradle 6.8.3 (installed automatically by FPCUPdeluxe)
    FPCUPdeluxe ver 1.8.2u
    FPC stable v3.2.2
    Lazarus stable v2.0.12
    32-bit CPU Target: ARMv7a + VFPv3
    64-bit CPU Target: Aarch64
    LAMW git from 2021-Jun-11
    Android NDK revision 22 (installed to sdk/ndk-bundle)
    Android NDK revision 21 (installed to sdk/ndk/21.4.7075529/)

NOTE about FPCUPdeluxe:
I renamed $HOME/android/fpc-lazarus/cross/lib/ to lib-BAK so those libraries don't get used.
(the current version of FPCUPdeluxe created that folder)

But the $HOME/android/fpc-lazarus/cross/bin folder is required or it doesn't build:
lazaruspackageintf.pas(104,0) Error: Assembler arm-linux-androideabi-as not found, switching to external assembling
So it appears that it is not using the toolchain from the NDK and using the one that FPCUPdeluxe installed instead.

There are some issues and concerns.  Will put those in next message.
Title: Re: LAMW error with Android NDK revision 22
Post by: WayneSherman on June 12, 2021, 12:56:17 am
With latest LAMW changes the following minor issue still exists:

Set paths using LAMW Paths/Settings dialog box not working

After setting the "Path to Android NDK", the edit box gets cleared when setting the Android SDK path using the "..." browse button.
After setting the "Path to Android SDK", the edit box gets cleared when setting the Android NDK path using the "..." browse button.

If I paste the paths to the NDK and SDK, then it works.
Title: Re: LAMW error with Android NDK revision 22
Post by: jmpessoa on June 12, 2021, 01:10:00 am

Quote
With latest LAMW changes the following minor issue still exists....

Around here I can't fix this error.....my LAMW installation works normally in Win64...

Please,  can you try  some  investigation in  "uformsettingspaths.pas" [LAMW folder "ide_tools"]?
Title: Re: LAMW error with Android NDK revision 22
Post by: WayneSherman on June 12, 2021, 01:55:46 am
Regarding the latest LAMW changes, the wrong library files are being used for building when opening an existing project.

When creating a new LAMW Project, it works correctly.  For example, the NDK Api is set to 29, and the Target SDK version set to 29 (i.e. API Level 29), and my path has the correct API level 29 libraries:

/home/wsherman/android/sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/arm-linux-androideabi/29/
or
/home/wsherman/android/sdk/ndk/21.4.7075529/platforms/android-29/arch-arm/usr/lib/

But when opening an existing LAMW project, there is no way to change the NDK API level so even though the Target SDK is set to 29, the API level 22 libraries are still being used:

(after opening AppDemo1 and changing the Target SDK version to 29 in Project Options)
/home/wsherman/android/sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/arm-linux-androideabi/22/
or
/home/wsherman/android/sdk/ndk/21.4.7075529/platforms/android-22/arch-arm/usr/lib/
Title: Re: LAMW error with Android NDK revision 22
Post by: WayneSherman on June 12, 2021, 02:11:59 am
RE: Set paths using LAMW Paths/Settings dialog box not working

Around here I can't fix this error.....my LAMW installation works normally in Win64...

To get it to happen, I have to start Lazarus with both paths empty (delete PathToAndroidSDK and PathToAndroidNDK from LAMW.ini).
Then when running Lazarus, if it opens an existing project, don't set the SDK or NDK paths when it asks. (cancel all the "Path Missing" pop-ups)

Then go to the Tools | LAMW Android Module Wizard | Paths Settings and try to set the NDK and SDK paths using the "..." buttons.
Title: Re: LAMW error with Android NDK revision 22
Post by: jmpessoa on June 12, 2021, 02:36:47 am
Quote
But when opening an existing LAMW project, there is no way to change the NDK API level so even though the Target SDK is set to 29, the API level 22 libraries are still being used...

Yes,  this is an old issue....  and need be improved.... [at the moment, the Api 22 is used by default
to alleviate incompatibilities with old devices using Android 4.x and 5.x]

What is relevant is SDK api target, not NDK api target ....
Title: Re: LAMW error with Android NDK revision 22
Post by: WayneSherman on June 12, 2021, 03:12:35 am
But the $HOME/android/fpc-lazarus/cross/bin folder is required or it doesn't build:
lazaruspackageintf.pas(104,0) Error: Assembler arm-linux-androideabi-as not found, switching to external assembling
So it appears that it is not using the toolchain from the NDK and using the one that FPCUPdeluxe installed instead.

Did more testing.  If I remove access to the FPCUPdeluxe build tools, I get compile errors for missing tools.  But I can get it to build again if I add the correct NDK build tool path.

So it looks like LAMW is using the wrong toolchain folder in the custom compile options (Project | Project Options | Compiler Options | Custom Options)

LAMW uses this:
Code: Text  [Select][+][-]
  1. -FD/home/wsherman/android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin
which give error:
lazaruspackageintf.pas(104,0) Error: Assembler arm-linux-androideabi-as not found, switching to external assembling

If I add this it works:
Code: Text  [Select][+][-]
  1. -FD/home/wsherman/android/sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin
Compile Project, OS: android, CPU: arm, Target: /home/wsherman/android/projects/AppLAMWProject5/libs/armeabi-v7a/libcontrols.so: Success, Hints: 2

EDIT:  I can't tell if it needs both paths or just the llvm/prebuilt one.  It is hard for me to test since LAMW adds the first path as a compile option and I can't remove it.
Title: Re: LAMW error with Android NDK revision 22
Post by: jmpessoa on June 12, 2021, 04:08:32 am

Ok. I will do some tests replacing the old

Quote
-FD/home/wsherman/android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin

by the new:
Quote
-FD/home/wsherman/android/sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin
Title: Re: LAMW error with Android NDK revision 22
Post by: WayneSherman on June 12, 2021, 04:21:59 am

Ok. I will do some tests replacing the old

Quote
-FD/home/wsherman/android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin

by the new:
Quote
-FD/home/wsherman/android/sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin

Ok, thanks.  I can't tell if it needs both paths or just the llvm/prebuilt one.  It is hard for me to test since LAMW adds the first path as a compile option and I can't remove it.
Title: Re: LAMW error with Android NDK revision 22
Post by: jmpessoa on June 12, 2021, 04:32:58 am

Quote
I can't tell if it needs both paths or just the llvm/prebuilt one....

Just one ....  the llvm is the new way to go....
Title: Re: LAMW error with Android NDK revision 22
Post by: WayneSherman on June 12, 2021, 04:46:23 am
Just one ....  the llvm is the new way to go....

I am also trying to test which libraries paths are needed.  On my test system, LAMW adds two library paths:

Code: Bash  [Select][+][-]
  1. /home/wsherman/android/sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/arm-linux-androideabi/29/
  2. /home/wsherman/android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/

But if I rename the "lib" folder in the second path like this so it cannot be found
Code: Bash  [Select][+][-]
  1. /home/wsherman/android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib-BAK/gcc/arm-linux-androideabi/4.9.x/

I can still successfully compile and build. (tested with a simple LAMW "hello world" gui program)

According to the Build System Maintainers Guide
https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#Sysroot
Quote
The Android sysroot is installed to <NDK>/toolchains/llvm/prebuilt/<host-tag>/sysroot and contains the headers, libraries, and CRT object files for each Android target.

Libraries are found in the usr/lib/<triple> directory of the sysroot. Version-specific libraries are installed to usr/lib/<triple>/<API-level>. As with the header files, when using Clang it is not necessary to include these directories explicitly; the sysroot will be automatically selected. If using a compiler other than Clang, ensure that the version-specific library directory takes precedence over the version-generic directory.

So it sounds like both paths should be added to the libraries with the API version first like this:
Code: Bash  [Select][+][-]
  1. /home/wsherman/android/sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/arm-linux-androideabi/29/
  2. /home/wsherman/android/sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/arm-linux-androideabi/

Title: Re: LAMW error with Android NDK revision 22
Post by: jmpessoa on June 12, 2021, 05:03:39 am

Yes, there is a mix in LAMW....  the ideal for NDK>=22 is the pure llvm way....
Title: Re: LAMW error with Android NDK revision 22
Post by: rsu333 on June 12, 2021, 08:59:24 am
Good work and effort from both of you.
Title: Re: LAMW error with Android NDK revision 22
Post by: WayneSherman on June 12, 2021, 05:58:00 pm
Around here I can't fix this error.....my LAMW installation works normally in Win64...
Please,  can you try  some  investigation in  "uformsettingspaths.pas" [LAMW folder "ide_tools"]?

I think I found the problem:
https://github.com/jmpessoa/lazandroidmodulewizard/blob/master/ide_tools/uformsettingspaths.pas#L345

Code: Pascal  [Select][+][-]
  1. procedure TFormSettingsPaths.FormActivate(Sender: TObject);
  2. begin
  3. ...
  4. end;

On Linux it looks like this code runs when the SDK or NDK path speedbuttons "..." are clicked.  It calls TFormSettingsPaths.LoadSettings which clears the NDK and SDK edit boxes since the settings are not set yet.

I think the code here should run in the OnShow event, not OnActivate:

Code: Pascal  [Select][+][-]
  1. procedure TFormSettingsPaths.FormShow(Sender: TObject);
  2. begin
  3. ...(put the code here)
  4. end;


Title: Re: LAMW error with Android NDK revision 22
Post by: jmpessoa on June 12, 2021, 08:54:36 pm
Quote
I think the code here should run in the OnShow event, not OnActivate:

OK. I will fix LAMW!

Thank you!
Title: Re: LAMW error with Android NDK revision 22
Post by: WayneSherman on June 12, 2021, 11:43:46 pm
Quote
I think the code here should run in the OnShow event, not OnActivate:

OK. I will fix LAMW!

Thank you!

yup, yup that fixed it.  The form now works correctly.  Thanks :-)

TinyPortal © 2005-2018