bytedeco/sbt-javacpp

Support multiple platforms in a single build

pfn opened this issue · 7 comments

pfn commented

javaCppPlatforms is only a single platform entry. I would like to have support for multiple platforms in a single build.

In my case, I'm building for android, and would like to incorporate android-arm as well as android-x86, in addition to anything else that might end up being supported in the future, e.g. mips, etc.

I'm not sure if it would work, but the only workaround I have in mind currently is to map over libraryDependencies and add artifacts(Artifact(classifier, "jar", "jar")) for each platform I would like to add, not sure if this would work

Interesting use case. I think I can easily add support for multiple platforms in this plugin, but I'm unsure how that will work with JavaCPP itself (e.g. if there are multiple native libs on the path, would it load the libraries properly), though it should be easy to try out. Once I have a snapshot published, can you do me a favour and give it a try (I'll let you know)?

I'm not too familiar with Android development, but if you want to build platform specific Jars, another idea could be to loop over them in Bash and do the following:

for platform in android-arm, android-x86; do
  sbt compile -Dsbt.javacpp.platform=$platform
done
pfn commented

I've uploaded a sample project that builds the FacePreview and RecordActivity demos.

https://github.com/pfn/android-javacv-sample

to build this, you will need to download the Android SDK, and fetch platform-tools, tools, build-tools (all latest) and android platform sdk api 21

to build:
sbt android:package

to build and install:
sbt android:install

The android packaging knows to search for ABI specific libraries in lib/ABI/... and classifiers like android-arm.jar and android-x86.jar have stuff packaged properly already

Sure, JavaCPP supports multiple platforms in the same build!

BTW, is it possible to set the version of JavaCPP as well? There is a variable javaCppVersion, but it doesn't seem to be available as a setting. Since libraries built with different versions of JavaCPP are not fully compatible, one might want to use older versions as well. And the same thing goes for JavaCV...

Thanks guys :) Learning lots here myself about Android and JavaCPP :)

@pfn Can you try out version 1.4-SNAPSHOT of this plugin? You can set multiple platforms in a single build by either setting javaCppPlatform := Seq("android-arm", "android-x86") in your build.sbt or by passing a space separated string to the sbt.javacpp.platform system property.

@saudet yes, that is possible; in build.sbt, simply set the version via javaCppVersion := "1.2"

EDIT @pfn you may need to use the latest snapshot of SBT-JavaCV (1.6-SNAPSHOT)

Cool! To be clear, the Builder class accepts only one set of platform properties at a time, but yes we can run it multiple times in the same build. Maven is kind of limiting, so the BuildMojo class only supports one platform at a time, but if we can do better with sbt, great!

pfn commented

I had to publish-local from feature/multiple-platforms; but otherwise, it appears to work:

$ unzip -t target/android/output/com-hanhuy-android -vision-debug.apk | grep -w lib
    testing: lib/armeabi/libavcodec.so   OK
    testing: lib/armeabi/libavdevice.so   OK
    testing: lib/armeabi/libavfilter.so   OK
    testing: lib/armeabi/libavformat.so   OK
    testing: lib/armeabi/libavutil.so   OK
    testing: lib/armeabi/libjniavcodec.so   OK
    testing: lib/armeabi/libjniavdevice.so   OK
    testing: lib/armeabi/libjniavfilter.so   OK
    testing: lib/armeabi/libjniavformat.so   OK
    testing: lib/armeabi/libjniavutil.so   OK
    testing: lib/armeabi/libjnicvkernels.so   OK
    testing: lib/armeabi/libjniopencv_calib3d.so   OK
    testing: lib/armeabi/libjniopencv_core.so   OK
    testing: lib/armeabi/libjniopencv_face.so   OK
    testing: lib/armeabi/libjniopencv_features2d.so   OK
    testing: lib/armeabi/libjniopencv_flann.so   OK
    testing: lib/armeabi/libjniopencv_highgui.so   OK
    testing: lib/armeabi/libjniopencv_imgcodecs.so   OK
    testing: lib/armeabi/libjniopencv_imgproc.so   OK
    testing: lib/armeabi/libjniopencv_ml.so   OK
    testing: lib/armeabi/libjniopencv_objdetect.so   OK
    testing: lib/armeabi/libjniopencv_optflow.so   OK
    testing: lib/armeabi/libjniopencv_photo.so   OK
    testing: lib/armeabi/libjniopencv_shape.so   OK
    testing: lib/armeabi/libjniopencv_stitching.so   OK
    testing: lib/armeabi/libjniopencv_superres.so   OK
    testing: lib/armeabi/libjniopencv_video.so   OK
    testing: lib/armeabi/libjniopencv_videoio.so   OK
    testing: lib/armeabi/libjniopencv_videostab.so   OK
    testing: lib/armeabi/libjniopencv_xfeatures2d.so   OK
    testing: lib/armeabi/libjnipostproc.so   OK
    testing: lib/armeabi/libjniswresample.so   OK
    testing: lib/armeabi/libjniswscale.so   OK
    testing: lib/armeabi/libopencv_calib3d.so   OK
    testing: lib/armeabi/libopencv_core.so   OK
    testing: lib/armeabi/libopencv_face.so   OK
    testing: lib/armeabi/libopencv_features2d.so   OK
    testing: lib/armeabi/libopencv_flann.so   OK
    testing: lib/armeabi/libopencv_highgui.so   OK
    testing: lib/armeabi/libopencv_imgcodecs.so   OK
    testing: lib/armeabi/libopencv_imgproc.so   OK
    testing: lib/armeabi/libopencv_ml.so   OK
    testing: lib/armeabi/libopencv_objdetect.so   OK
    testing: lib/armeabi/libopencv_optflow.so   OK
    testing: lib/armeabi/libopencv_photo.so   OK
    testing: lib/armeabi/libopencv_shape.so   OK
    testing: lib/armeabi/libopencv_stitching.so   OK
    testing: lib/armeabi/libopencv_superres.so   OK
    testing: lib/armeabi/libopencv_video.so   OK
    testing: lib/armeabi/libopencv_videoio.so   OK
    testing: lib/armeabi/libopencv_videostab.so   OK
    testing: lib/armeabi/libopencv_xfeatures2d.so   OK
    testing: lib/armeabi/libpostproc.so   OK
    testing: lib/armeabi/libswresample.so   OK
    testing: lib/armeabi/libswscale.so   OK
    testing: lib/x86/libavcodec.so    OK
    testing: lib/x86/libavdevice.so   OK
    testing: lib/x86/libavfilter.so   OK
    testing: lib/x86/libavformat.so   OK
    testing: lib/x86/libavutil.so     OK
    testing: lib/x86/libjniavcodec.so   OK
    testing: lib/x86/libjniavdevice.so   OK
    testing: lib/x86/libjniavfilter.so   OK
    testing: lib/x86/libjniavformat.so   OK
    testing: lib/x86/libjniavutil.so   OK
    testing: lib/x86/libjnicvkernels.so   OK
    testing: lib/x86/libjniopencv_calib3d.so   OK
    testing: lib/x86/libjniopencv_core.so   OK
    testing: lib/x86/libjniopencv_face.so   OK
    testing: lib/x86/libjniopencv_features2d.so   OK
    testing: lib/x86/libjniopencv_flann.so   OK
    testing: lib/x86/libjniopencv_highgui.so   OK
    testing: lib/x86/libjniopencv_imgcodecs.so   OK
    testing: lib/x86/libjniopencv_imgproc.so   OK
    testing: lib/x86/libjniopencv_ml.so   OK
    testing: lib/x86/libjniopencv_objdetect.so   OK
    testing: lib/x86/libjniopencv_optflow.so   OK
    testing: lib/x86/libjniopencv_photo.so   OK
    testing: lib/x86/libjniopencv_shape.so   OK
    testing: lib/x86/libjniopencv_stitching.so   OK
    testing: lib/x86/libjniopencv_superres.so   OK
    testing: lib/x86/libjniopencv_video.so   OK
    testing: lib/x86/libjniopencv_videoio.so   OK
    testing: lib/x86/libjniopencv_videostab.so   OK
    testing: lib/x86/libjniopencv_xfeatures2d.so   OK
    testing: lib/x86/libjnipostproc.so   OK
    testing: lib/x86/libjniswresample.so   OK
    testing: lib/x86/libjniswscale.so   OK
    testing: lib/x86/libopencv_calib3d.so   OK
    testing: lib/x86/libopencv_core.so   OK
    testing: lib/x86/libopencv_face.so   OK
    testing: lib/x86/libopencv_features2d.so   OK
    testing: lib/x86/libopencv_flann.so   OK
    testing: lib/x86/libopencv_highgui.so   OK
    testing: lib/x86/libopencv_imgcodecs.so   OK
    testing: lib/x86/libopencv_imgproc.so   OK
    testing: lib/x86/libopencv_ml.so   OK
    testing: lib/x86/libopencv_objdetect.so   OK
    testing: lib/x86/libopencv_optflow.so   OK
    testing: lib/x86/libopencv_photo.so   OK
    testing: lib/x86/libopencv_shape.so   OK
    testing: lib/x86/libopencv_stitching.so   OK
    testing: lib/x86/libopencv_superres.so   OK
    testing: lib/x86/libopencv_video.so   OK
    testing: lib/x86/libopencv_videoio.so   OK
    testing: lib/x86/libopencv_videostab.so   OK
    testing: lib/x86/libopencv_xfeatures2d.so   OK
    testing: lib/x86/libpostproc.so   OK
    testing: lib/x86/libswresample.so   OK
    testing: lib/x86/libswscale.so    OK

Thanks!

@pfn cool :) I should have mentioned that you would need resolvers += Resolver.sonatypeRepo("snapshot") in build.sbt in order for it to resolve the snapshot. Thanks for checking !