[英]Azure spatial anchors integration issues. Missing NativeLibrary implementations
我一直在修補Azure的空間錨點API。 我遵循了Microsoft提供的文檔和示例,沒有很多問題,直到嘗試使用它來創建自己的項目。 當我嘗試使用Spatial anchors API運行自定義項目時,它崩潰了,尋找應由gradle中指定的庫提供的某些功能。 錯誤日志顯示:
2019-05-28 10:32:10.642 28982-28982 / com.azurelib.azureanchorsclean E / AndroidRuntime:致命例外:主進程:com.azurelib.azureanchorsclean,PID:28982 java.lang.UnsatisfiedLinkError:未找到com的實現。 microsoft.azure.spatialanchors.status com.microsoft.azure.spatialanchors.NativeLibrary.ssc_cloud_spatial_anchor_session_create(com.microsoft.azure.spatialanchors.Out)(試過Java_com_microsoft_azure_spatialanchors_NativeLibrary_ssc_1cloud_1spatial_1anchor_1session_1create和Java_com_microsoft_azure_spatialanchors_NativeLibrary_ssc_1cloud_1spatial_1anchor_1session_1create__Lcom_microsoft_azure_spatialanchors_Out_2)在com.microsoft.azure.spatialanchors.NativeLibrary.ssc_cloud_spatial_anchor_session_create(本機方法)...
相關的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示例復制/粘貼的。 我找不到丟失的內容,這導致我的自定義項目無法找到NativeLibrary
的實現。 作為參考, 這是我用來建立自己的項目的Microsoft項目。
這是我實際的 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內部調用initialize方法?
@Override
public void onCreate() {
super.onCreate();
// Use application's context to initialize CloudServices!
CloudServices.initialize(this);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.