[vtkusers] Linking Android library with Gradle that depends on VTK 7.0

Brian Miller b1.miller at samsung.com
Mon Aug 8 14:33:34 EDT 2016


I am trying to build a library project in Android Studio, or using Gradle command-line,
based on VTK 7.0.0 and OpenCV 3.1.0

I built the VTK libraries for Android arm64-v8a platform as static libraries (.a files)
and then included all of them in the build.gradle for my own library project.

For example, my build.gradle includes :

apply plugin: 'com.android.model.native'
def commonBase = "${projectDir}/../../../common"
model {
    repositories {
        libs(PrebuiltLibraries) {
// (more vtk libraries here)
            vtkCommonColor {
                headers.srcDir "${commonBase}/thirdparty/vtk-7.0/include"
                binaries.withType(StaticLibraryBinary) {
                    staticLibraryFile = file("${commonBase}/thirdparty/vtk-7.0/lib/arm64-v8a/libvtkCommonColor-7.0.a")
                }
            }
            vtkCommonCore {
                headers.srcDir "${commonBase}/thirdparty/vtk-7.0/include"
                binaries.withType(StaticLibraryBinary) {
                    staticLibraryFile = file("${commonBase}/thirdparty/vtk-7.0/lib/arm64-v8a/libvtkCommonCore-7.0.a")
                }
            }
// more vtk libraries here
}
}
...
    android {
        compileSdkVersion 21
        buildToolsVersion "23.0.2"

        defaultConfig {
            minSdkVersion.apiLevel 19
            targetSdkVersion.apiLevel 19
        }

        sources {
            main {
                jni {
                    dependencies {
// more vtk libraries here
                        library "vtkCommonColor" linkage "static"
                        library "vtkCommonCore" linkage "static"
// more vtk libraries here

...

and my C++ class referencing VTK includes:

#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkRenderingFreeType);

#include <vtkAbstractPolyDataReader.h>
#include <vtkActor.h>
#include <vtkExtractVOI.h>
#include <vtkImageCast.h>
#include <vtkImageData.h>
#include <vtkJPEGReader.h>
#include <vtkOBJReader.h>
#include <vtkPNGWriter.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
#include <vtkTexture.h>
#include <vtkViewport.h>
#include <vtkWindow.h>
#include <vtkWindowToImageFilter.h>


But even with all of the VTK libraries included, I still get a lot of "undefined reference"
errors for VTK classes/methods which are included in the VTK libraries,
when building (linking) my project via

$ ./gradlew clean buil..

I saw there  were some old threads discussing similar Android issues,
but didn't see much recently as far as any solutions to using Gradle.
Since Google is recommending that Android developers move to
Android Studio and Gradle, and has been adding more NDK / native support,
this seems to be the preferred way of doing things, instead of using
.mk files or CMake

Any other sugestions ?

Brian Miller


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160808/ee10054c/attachment.html>


More information about the vtkusers mailing list