Friday 31 May 2019

Azure spatial anchors integration issues. Missing NativeLibrary implementations

I've been tinkering with Azure's spatial anchors API. I followed the docs and examples provided by Microsoft without many issues until I tried to make my own project from it. When I try to run a custom project using the Spatial anchors API it crashes looking for some functions that should be provided by the libraries specified in the gradle. The error log says this:

2019-05-28 10:32:10.642 28982-28982/com.azurelib.azureanchorsclean E/AndroidRuntime: FATAL EXCEPTION: main Process: com.azurelib.azureanchorsclean, PID: 28982 java.lang.UnsatisfiedLinkError: No implementation found for com.microsoft.azure.spatialanchors.status com.microsoft.azure.spatialanchors.NativeLibrary.ssc_cloud_spatial_anchor_session_create(com.microsoft.azure.spatialanchors.Out) (tried Java_com_microsoft_azure_spatialanchors_NativeLibrary_ssc_1cloud_1spatial_1anchor_1session_1create and Java_com_microsoft_azure_spatialanchors_NativeLibrary_ssc_1cloud_1spatial_1anchor_1session_1create__Lcom_microsoft_azure_spatialanchors_Out_2) at com.microsoft.azure.spatialanchors.NativeLibrary.ssc_cloud_spatial_anchor_session_create(Native Method) ...

The relevant ssc_cloud... functions can be found in the spatialanchors_java dependency specified in the gradle build:enter image description here

For the cloud session, I start a new activity in my MainActivity's onResume():

@Override
protected void onResume(){
    super.onResume();
    Intent intent = new Intent(this, AzureSpatialAnchorsActivity.class);
    intent.putExtra("BasicDemo", true);
    startActivity(intent);
}

And on AzureSpatialAnchorsActivity I create the ArCore Session and start the anchor manager:

    @Override
    protected void onResume() {
        super.onResume();

        if (session == null) {
            try {
                ...
                // Create the session.
                session = new Session(/* context= */ this);

            ... //Required catch statements
            } catch (Exception e) {
                message = "Failed to create AR session";
                exception = e;
            }
        }


        try {
            session.resume();
            startNewSession();
        } catch (CameraNotAvailableException e) {
            ...
        }
    }

    private void startNewSession() {
        destroySession();

        cloudAnchorManager = new AzureSpatialAnchorsManager(session);
        cloudAnchorManager.addAnchorLocatedListener(this::onAnchorLocated);
        cloudAnchorManager.addLocateAnchorsCompletedListener(this::onLocateAnchorsCompleted);
        cloudAnchorManager.addSessionUpdatedListener(this::onSessionUpdated);
        cloudAnchorManager.start();
    }

The error happens because when I try to create a CloudSpatialAnchorSession object

public AzureSpatialAnchorsManager(Session arCoreSession) {
    spatialAnchorsSession = new CloudSpatialAnchorSession();
    ...
}

the constructor calls a function from NativeLibrary

public CloudSpatialAnchorSession() {
    Out<Long> result_handle = new Out();
    status resultStatus = NativeLibrary.ssc_cloud_spatial_anchor_session_create(result_handle);
    this.handle = (Long)result_handle.value;
    NativeLibraryHelpers.checkStatus(this.handle, resultStatus);
    CookieTracker.add(this);
}

The problem seems to be that what I previously showed on the the jar screenshot is all there is. ssc_cloud_spatial_anchor_session_create gets called, the application lands on an dead end:

class NativeLibrary {
    NativeLibrary() {
    }
    ...
    static native status ssc_cloud_spatial_anchor_session_create(Out<Long> var0);
    ...
}


The gradle and other configs are copy/paste from the original Microsoft sample. I can't find what I'm missing that's causing my custom project not to find the implementations of NativeLibrary. For reference, here's the Microsoft project that I'm using to base my own project of

Here's my actual gradle files just for reference:

Project gradle

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Module gradle:

apply plugin: 'com.android.application'
def azureSpatialAnchorsSdkVersion = '1.1.0'
android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.azurelib.azureanchorsclean"
        minSdkVersion 24
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.ar:core:1.7.0'
    implementation "com.microsoft.azure.spatialanchors:spatialanchors_jni:[${azureSpatialAnchorsSdkVersion}]"
    implementation "com.microsoft.azure.spatialanchors:spatialanchors_java:[${azureSpatialAnchorsSdkVersion}]"
    implementation 'de.javagl:obj:0.2.1'
    implementation 'com.microsoft.aad:adal:1.16.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Thanks!



from Azure spatial anchors integration issues. Missing NativeLibrary implementations

No comments:

Post a Comment