首页 > 解决方案 > 无法将 Unity ARCore 项目作为 android .AAR 库运行

问题描述

我正在尝试构建一个 Unity ARCore 应用程序,该应用程序将嵌入现有的父 android 应用程序中。作为独立的 ARCore 项目运行良好(作为来自 Unity 的直接 apk 和作为从导出的 unity android studio 项目创建的 apk)。

当我从导出的 unity android studio 项目创建“ .aar ”库文件并将其集成到主 android 应用程序时,它没有运行,并且我收到以下错误: 缺少 Unity 引擎 ARCore 支持。请确保 Unity 项目启用了“Player Settings > XR Settings > ARCore Supported”复选框。.

我已确保在 XR 设置中启用了“支持 ARcore” (也通过独立应用程序运行良好的事实证实了这一点)。此外,统一启动是从父应用程序正确启动的(我可以看到我的统一 UI 和启动动画等),只有 ARCore 相机不会因上述错误而初始化。

以下是我创建“.aar”的教程链接: https ://medium.com/@davidbeloosesky/embedded-unity-within-android-app-7061f4f473a

我还尝试了以下方法: https ://medium.com/@randive.rishiraj/7-steps-to-integrate-google-arcore-unity-project-to-a-native-android-app-d85793ba0b37

以下是 Unity android studio 导出项目的 build.gradle 文件

// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN

buildscript {
    repositories {
        google()
        jcenter()
    }

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

allprojects {
    repositories {
        flatDir {
            dirs 'libs'
        }
    }
}

apply plugin: 'com.android.library'

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation(name: 'arcore_client', ext:'aar')
    implementation(name: 'arcore_rendering_utils', ext:'aar')
    implementation(name: 'arcore_unity', ext:'aar')
    implementation(name: 'google_ar_required', ext:'aar')
    implementation(name: 'unityandroidpermissions', ext:'aar')
    implementation(name: 'unitygar', ext:'aar')
}

android {
    compileSdkVersion 28
    buildToolsVersion '29.0.2'

    defaultConfig {
        minSdkVersion 24
        targetSdkVersion 28
        ndk {
            abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86'
        }
        versionCode 1
        versionName '1.0'
    }

    lintOptions {
        abortOnError false
    }

    aaptOptions {
        noCompress '.unity3d', '.ress', '.resource', '.obb'
    }

    buildTypes {
        debug {
            minifyEnabled false
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
            jniDebuggable true
        }
        release {
            minifyEnabled false
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
            signingConfig signingConfigs.debug
        }
    }

    packagingOptions {
        doNotStrip '*/armeabi-v7a/*.so'
        doNotStrip '*/arm64-v8a/*.so'
        doNotStrip '*/x86/*.so'
    }

}

以下是android清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mbrd.ar" xmlns:tools="http://schemas.android.com/tools" android:installLocation="auto">
  <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
  <application android:theme="@style/UnityThemeSelector" android:icon="@mipmap/app_icon" android:label="@string/app_name" android:isGame="false" android:banner="@drawable/app_banner">
    <activity android:label="@string/app_name" android:screenOrientation="portrait" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="false" android:name="com.mbrd.ar.UnityPlayerActivity">
      <!--<intent-filter>-->
        <!--<action android:name="android.intent.action.MAIN" />-->
        <!--<category android:name="android.intent.category.LAUNCHER" />-->
      <!--</intent-filter>-->
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>
    <meta-data android:name="unity.tango-enable" android:value="True" />
    <meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="true" />
    <meta-data android:name="unity.build-id" android:value="5147ef97-4e9e-47dd-b7ec-317134f40251" />
    <meta-data android:name="unity.splash-mode" android:value="0" />
    <meta-data android:name="unity.splash-enable" android:value="True" />
    <meta-data android:name="android.max_aspect" android:value="2.1" />
  </application>
  <uses-feature android:glEsVersion="0x00020000" />
  <uses-permission android:name="android.permission.CAMERA" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.VIBRATE" />
  <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>

我使用统一 2018.2.16。

任何人都可以就可能是什么原因以及可以采取什么措施来解决这个问题提出一个想法?

谢谢

标签: androidunity3daugmented-realityarcore

解决方案


对于遇到这个问题的人:

能够解决这个问题。这是一个项目设置问题。将脚本运行时版本设置为 .NET 4.x 等效版本并将 Api 兼容性级别设置为 .NET Standard 2.0 为我解决了这个问题。


推荐阅读