Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
C++

Linker error using the sensor components for Android in RAD Studio 10.3.3

An issue in Androidapi.Sensor.pas referring to symbols introduced in SDK version 26 will cause an linking error when your app references SDK version 22

If you are building Android applications with C++Builder 10.3.3, you may encounter an error [ldandroid Error] “ld” exited with code 1. The same issue can appear with different symptoms for Delphi 10.3.3 when attempt to match symbol names (such as using a script to gain symbols from call stacks generated by third party call stack libraries on Android, such as Grijjy’s error reporting code) in Delphi, where you will also get a linker error.

The issue is caused by a few symbols in the Androidapi.Sensor.pas file only being introduced in Android SDK version 26, but your application will link against version 22 where those symbols are not present. To resolve the errors, just make a local copy of the unit and comment out the symbols.

Workaround

  1. Find the C:Program Files (x86)EmbarcaderoStudio20.0sourcertlandroidAndroidapi.Sensor.pas and Androidapi.inc files (or the same file in your RAD Studio installation folder, if you installed to a different location.)
  2. Make a copy of them in your project’s source folder, and addAndroidapi.Sensor.pas only to your project. Androidapi.inc is required to build your local copy of Androidapi.Sensor.pas.
  3. Open the file and locate and comment out the declarations for the following symbols:
    1. ASensorManager_getInstanceForPackage
    2. ASensorManager_getDefaultSensorEx
    3. ASensorManager_createSharedMemoryDirectChannel
    4. ASensorManager_createHardwareBufferDirectChannel
    5. ASensorManager_destroyDirectChannel
    6. ASensorManager_configureDirectReport
    7. ASensorEventQueue_registerSensor
    8. ASensor_isDirectChannelTypeSupported
    9. ASensor_getHighestDirectReportRateLevel
  4. Ensure that when you upgrade to the next version, you remove your local copy of this file from your projects.

Writeup

Brian Long kindly wrote up a longer article about the issue and workaround. Thanks, Brian!

Do you want to make your own sensor-enabled Android App?
Try out the IDE Software and make the most of it. Request a Free Trial here.
See What's New in 12.2 Athens See What's New in 12.2 Athens Dev Days of Summer 2-24

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

About author

David is an Australian developer, currently living in far-north Europe. He is the senior product manager for C++ at Idera, looking after C++Builder and Visual Assist.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES