Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build libcamera against Android SDK #54

Open
kbingham opened this issue Oct 14, 2022 · 21 comments
Open

Build libcamera against Android SDK #54

kbingham opened this issue Oct 14, 2022 · 21 comments
Assignees

Comments

@kbingham
Copy link
Owner

References to get started:

https://proandroiddev.com/how-to-setup-android-sdk-without-android-studio-6d60d0f2812a?gi=6f859505330e

https://github.com/ppetraki/meson-android-helloworld

@kbingham kbingham self-assigned this Oct 14, 2022
@rsglobal
Copy link

You probably meant NDK: https://developer.android.com/ndk/downloads

As far as I know SDK is for Android apps.

@rsglobal
Copy link

rsglobal commented Oct 14, 2022

Here's the starting point:

  1. Download ndk into /opt/ndk directory
  2. Clone libcamera
  3. Download build.sh and meson_cross_compile.txt into libcamera directory
  4. Run ./build.sh
  5. $ cd ./build
  6. $ ninja

meson_cross_compile.txt
build.zip

@kbingham
Copy link
Owner Author

Thanks!, that looks like clear for me to integrate.

@rsglobal
Copy link

rsglobal commented Oct 16, 2022

There're some system dependencies to be installed before building (especially when cross-compiling for ARM). It would be nice to come-up with a dockerfile which will include all required dependencies.

@kbingham
Copy link
Owner Author

@rsglobal
Copy link

I don't have any issues building for Android. But my solution is not upstreamable.
I would like to see initial official Android support to reduce my local delta and then see what can I upstream.

@kbingham
Copy link
Owner Author

kbingham commented Oct 17, 2022

Which part of your solution is not upstreamable? Nicholas Roth from the other issue is working on the mailing list to determine adding (I expect /your/ makefile wrapper).

The work can only get upstream if someone works on it.

@rsglobal
Copy link

Which part of your solution is not upstreamable?

Here's my WIP branch. It's very dirty right now, but it can partially answer the question.
https://github.com/GloDroid/glodroid_forks/commits/libcamera-next

The work can only get upstream if someone works on it.

That won't be me, sorry. I'm already supporting a lot of FOSS repos. And only benefit I have from my FOSS activity is a feeling that world is becoming better. Nobody want to pay for that.

@rsglobal
Copy link

rsglobal commented Nov 15, 2022

@kbingham ,

Can you help me please to understand this line?

adb shell LIBCAMERA_LOG_LEVELS=*:DEBUG lc-compliance
[17:41:46.203161361] [5713]  WARN IPAManager ipa_manager.cpp:114 Public key not valid

Why public key may be invalid?

Here's my generated key:
ipa_pub_key.cpp

UPDATE: libcrypto dep was missing, now it works, signature check is working.

@kbingham
Copy link
Owner Author

I've tried following these steps to build with android ndk:

I've created a meson cross file as mesoncross/android-ndk-r25b

[binaries]
ar = '/opt/ndk/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar'
c = '/opt/ndk/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android33-clang'
cpp = '/opt/ndk/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android33-clang++'
c_ld = 'lld'
cpp_ld = 'lld'
pkgconfig = '/usr/bin/pkg-config'
strip = '/opt/ndk/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip'

[host_machine]
system = 'linux'
cpu_family = 'x86_64'
cpu = ''
endian = 'little'

and configured with:

meson build/android-ndk-25b/ \
	--cross mesoncross/android-ndk-r25b \
	-Dsysconfdir=/vendor/etc \
	-Dandroid=enabled

...

libcamera 0.0.1

  Versions
    Sources                  : 0.0.1+70-0eb4ccd3

  Paths
    LIBCAMERA_DATA_DIR       : "/usr/local/share/libcamera"
    LIBCAMERA_SYSCONF_DIR    : "/vendor/etc/libcamera"
    IPA_PROXY_DIR            : "/usr/local/libexec/libcamera"
    IPA_CONFIG_DIR           : "/vendor/etc/libcamera/ipa:/usr/local/share/libcamera/ipa"
    IPA_MODULE_DIR           : "/usr/local/lib/libcamera"

  Configuration
    Enabled pipelines        : ipu3
                               raspberrypi
                               rkisp1
                               simple
                               uvcvideo
                               vimc
    Enabled IPA modules      : ipu3
                               raspberrypi
                               rkisp1
                               vimc
    Tracing support          : YES
    Android support          : YES
    GStreamer support        : YES
    Python bindings          : NO
    V4L2 emulation support   : NO
    cam application          : YES
    qcam application         : YES
    lc-compliance application: YES
    Unit tests               : NO

  Subprojects
    libyuv                   : YES

  User defined options
    Cross files              : mesoncross/android-ndk-r25b
    sysconfdir               : /vendor/etc
    android                  : enabled


But I get a lot of host header pollution:

In file included from /opt/ndk/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/features.h:36:
/usr/include/x86_64-linux-gnu/sys/cdefs.h:64:6: error: function-like macro '__GNUC_PREREQ' is not defined
# if __GNUC_PREREQ (4, 6) && !defined _LIBC
     ^

Do you get this? or have you already resolved such issues ?

@kbingham
Copy link
Owner Author

pkgconfig = '/usr/bin/pkg-config'

Seems 'suspicious' to me...

@rsglobal
Copy link

Try pkgconfig = ['env', 'PKG_CONFIG_LIBDIR='path_to_NDK_pkgs_dir', '/usr/bin/pkg-config']

@rsglobal
Copy link

I haven't tried to build libcamera using NDK yet. I think it would require some minimal sysroot preparation with packages and C headers from AOSP.

@kbingham
Copy link
Owner Author

Oh - I thought #54 (comment) was something you had done.
I don't seem to have much in the way of a sysroot for the NDK indeed, so not much for the pkg-config to point to ..

@kbingham
Copy link
Owner Author

/opt/ndk/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/sysroot seems to be a reasonable sysroot starting point though...

@rsglobal
Copy link

May be useful:

That's how env. variables can be overridden for service to enable logcat debug:

+++ /vendor/etc/init/[email protected]_64.rc
service vendor.camera-provider-2-5 /vendor/bin/hw/[email protected]_64
    interface [email protected]::ICameraProvider legacy/0
    interface [email protected]::ICameraProvider legacy/0
    class hal
    user cameraserver
    group audio camera input drmrpc
    ioprio rt 4
    capabilities SYS_NICE
    task_profiles CameraServiceCapacity MaxPerformance
+    setenv LIBCAMERA_LOG_LEVELS *:DEBUG
+    setenv LIBCAMERA_LOG_FILE syslog

@rsglobal
Copy link

rsglobal commented Nov 15, 2022

Oh - I thought #54 (comment) was something you had done.

Not yet, but have the plans to do it in a future.

EDIT:

But I tested this manual before posting: #54 (comment)
IIRC I got successful build.

@kbingham
Copy link
Owner Author

Ok, good to know you were able to build ... I got further with setting the sysroot - but still get linker errors:

ld.lld: error: unable to find library -ldw
ld.lld: error: unable to find library -lelf

So I'll have to do some more digging next time I get chance.

@rsglobal
Copy link

It should not be able to find, therefore require libdw:
Meson config should print this:

Run-time dependency libdw found: NO (tried pkgconfig and cmake)

@kbingham
Copy link
Owner Author

So preventing finding the host libraries requires setting (correctly, without typos!) the pkg_config_libdir property in the mesoncross file.

But now I'm hit by not having libexif available in the NDK sysroot, which is required for the android layer. Next steps, identify how to provide libexif to the NDK sysroot.

@rsglobal
Copy link

Sharing my thoughts:

  1. Create synthetic libexif.pc file
  2. Add headers from https://android.googlesource.com/platform/external/libexif/+/refs/heads/master/libexif/ to sysroot/usr/include/libexif directory
  3. Pull libexif.so from /vendor/lib{64}/ of Android you're building for (you may try pulling it from the waydroid in case you have it installed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants