Azure / azure-spatial-anchors-samples

Azure Spatial Anchors sample code
Other
293 stars 138 forks source link

Unity 2019.3 Android Unable to find azurespatialanchorsndk #126

Closed ei2kpi-ptc closed 4 years ago

ei2kpi-ptc commented 4 years ago

I am trying to use ASA in a project within Unity 2019.3. Unity 2019.3 builds two separate Android projects: One which is just a launcher and the other which gets built into a unityLibrary aar file that the launcher then launches.

I get the same issue when I try to build and run the samples (after upgrading to Unity 2019.3 and upgrading the relevant packages)

I think the issue is related to the fact that the mainTemplate.gradle file has been written for Unity 2019.2 and below where only one application gets built.

The first time I built, Unity asked if I would like to upgrade my mainTemplate.gradle file and the only things it changed was:

My guess is I need to change something in the mainTemplate.gradle file such that the ASA plugin gets added to both the launcher and the unityLibrary projects since that was the problem with the podfile in iOS land

Updated file after Unity 2019.3 did its thing: mainTemplate.gradle.txt

Original mainTemplate.gradle file from the Samples repo: mainTemplate.gradle.backup.txt

ei2kpi-ptc commented 4 years ago

Think I found a fix...

It seems like some combination of Unity 2019.3.0f6, the packages that are "verified" with Unity 2019.3 and AzureSpatialAnchors 2.1.1 means that this line should no longer be in the mainTemplate.gradle: {exclude group: 'com.google.ar' }

So, the dependency injection for Azure Spatial Anchors should now look like this in the Assets/Plugins/Android/mainTemplate.gradle

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
**DEPS**
    // Azure Spatial Anchors
    implementation ("com.microsoft.azure.spatialanchors:spatialanchors_ndk:[${azureSpatialAnchorsSdkVersion}]") {
        exclude group: 'com.google.ar'
    }
    natives "com.microsoft.azure.spatialanchors:spatialanchors_ndk:[${azureSpatialAnchorsSdkVersion}]"
}

This seems to work with the attached manifest.json file. I have also attached my full mainTemplate.gradle file which has the above updates that Unity made automatically (remember to rename it to mainTemplate.gradle if you end up using it)

manifest.json.txt

mainTemplate.gradle.txt

ei2kpi-ptc commented 4 years ago

Wow ok that was a wild goose chase :(

In the end, I just had to make sure I was using the latest .unitypackage and the following AR subsystem packages:

    "com.unity.xr.arcore": "2.2.0-preview.6",
    "com.unity.xr.arfoundation": "2.2.0-preview.6",
    "com.unity.xr.arkit": "2.2.0-preview.6",
    "com.unity.xr.arsubsystems": "2.2.0-preview.6",

The above worked in my project with Unity 2019.3.0f6 and AzureSpatialAnchors 2.1.1 without needing to modify any gradle scripts at all