Azure 空间锚点集成问题。缺少 NativeLibrary 实现
Azure spatial anchors integration issues. Missing NativeLibrary implementations
我一直在修补 Azure 的空间锚 API。在我尝试从中创建自己的项目之前,我遵循了 Microsoft 提供的文档和示例,没有遇到太多问题。当我尝试 运行 使用空间锚点 API 的自定义项目时,它崩溃寻找一些应该由 gradle 中指定的库提供的功能。错误日志是这样说的:
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)
...
相关的ssc_cloud...函数可以在gradle构建中指定的spatialanchors_java依赖中找到:
对于云会话,我在 MainActivity 的 onResume()
:
中开始一个新的 activity
@Override
protected void onResume(){
super.onResume();
Intent intent = new Intent(this, AzureSpatialAnchorsActivity.class);
intent.putExtra("BasicDemo", true);
startActivity(intent);
}
然后在 AzureSpatialAnchorsActivity
我创建 ArCore
Session
并启动锚点管理器:
@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();
}
错误发生是因为当我尝试创建一个 CloudSpatialAnchorSession
对象时
public AzureSpatialAnchorsManager(Session arCoreSession) {
spatialAnchorsSession = new CloudSpatialAnchorSession();
...
}
构造函数从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);
}
问题似乎是我之前在jar截图上显示的就是全部。 ssc_cloud_spatial_anchor_session_create
被调用,应用程序陷入死胡同:
class NativeLibrary {
NativeLibrary() {
}
...
static native status ssc_cloud_spatial_anchor_session_create(Out<Long> var0);
...
}
gradle 和其他配置来自原始 Microsoft 示例的 copy/paste。我找不到导致我的自定义项目找不到 NativeLibrary
实现的遗漏内容。作为参考,我使用 here's the Microsoft project 作为我自己的
项目的基础
这是我的实际gradle文件,仅供参考:
项目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
}
模块 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'
}
谢谢!
由于您正在创建自己的项目,因此您是否在应用程序的 OnCreate 中调用了初始化方法 class?
@Override
public void onCreate() {
super.onCreate();
// Use application's context to initialize CloudServices!
CloudServices.initialize(this);
}
我一直在修补 Azure 的空间锚 API。在我尝试从中创建自己的项目之前,我遵循了 Microsoft 提供的文档和示例,没有遇到太多问题。当我尝试 运行 使用空间锚点 API 的自定义项目时,它崩溃寻找一些应该由 gradle 中指定的库提供的功能。错误日志是这样说的:
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) ...
相关的ssc_cloud...函数可以在gradle构建中指定的spatialanchors_java依赖中找到:
对于云会话,我在 MainActivity 的 onResume()
:
@Override
protected void onResume(){
super.onResume();
Intent intent = new Intent(this, AzureSpatialAnchorsActivity.class);
intent.putExtra("BasicDemo", true);
startActivity(intent);
}
然后在 AzureSpatialAnchorsActivity
我创建 ArCore
Session
并启动锚点管理器:
@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();
}
错误发生是因为当我尝试创建一个 CloudSpatialAnchorSession
对象时
public AzureSpatialAnchorsManager(Session arCoreSession) {
spatialAnchorsSession = new CloudSpatialAnchorSession();
...
}
构造函数从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);
}
问题似乎是我之前在jar截图上显示的就是全部。 ssc_cloud_spatial_anchor_session_create
被调用,应用程序陷入死胡同:
class NativeLibrary {
NativeLibrary() {
}
...
static native status ssc_cloud_spatial_anchor_session_create(Out<Long> var0);
...
}
gradle 和其他配置来自原始 Microsoft 示例的 copy/paste。我找不到导致我的自定义项目找不到 NativeLibrary
实现的遗漏内容。作为参考,我使用 here's the Microsoft project 作为我自己的
这是我的实际gradle文件,仅供参考:
项目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
}
模块 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'
}
谢谢!
由于您正在创建自己的项目,因此您是否在应用程序的 OnCreate 中调用了初始化方法 class?
@Override
public void onCreate() {
super.onCreate();
// Use application's context to initialize CloudServices!
CloudServices.initialize(this);
}