'Unity ARCORE DllNotFoundException: arcore_unity_api

I tried to export the project from Unity and then export it as a library from Android Studio but when I import that library into another project I get that error: E/Unity: Unable to find arpresto_api

(If I run it without exporting as a library everything works fine)

Any help would be apreciated.

Already tried Unity + ARCORE DllNotFoundException: arcore_unity_api and it doesn't work.

gradle:


buildscript {
    repositories {
        google()
        jcenter()
    }

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

allprojects {
    repositories {
        google()
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

apply plugin: 'com.android.library'


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation(name: 'arcore_client', 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 26
    buildToolsVersion '28.0.3'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion 26
        targetSdkVersion 28
        ndk {
            abiFilters 'armeabi-v7a', 'x86'
        }
        versionCode 1
        versionName '0.1'
    }

    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 '*/x86/*.so'
    }

    splits {
        language {
            enable false
        }
        density {
            enable false
        }
        abi {
            enable true
        }
    }
}
E/Unity: Unable to find arpresto_api
E/Unity: DllNotFoundException: arcore_unity_api
        at (wrapper managed-to-native) GoogleARCoreInternal.ARPrestoCallbackManager+ExternApi.ArCoreUnity_setArPrestoInitialized(GoogleARCoreInternal.ARPrestoCallbackManager/EarlyUpdateCallback)
      at GoogleARCoreInternal.ARPrestoCallbackManager._Initialize () [0x0002c] in /Users/petrosmaliotis/New Unity Project 4/Assets/GoogleARCore/SDK/Scripts/Managers/ARPrestoCallbackManager.cs:181
      at GoogleARCoreInternal.ARPrestoCallbackManager.get_Instance () [0x00018] in /Users/petrosmaliotis/New Unity Project 4/Assets/GoogleARCore/SDK/Scripts/Managers/ARPrestoCallbackManager.cs:91
      at GoogleARCoreInternal.ARCoreAndroidLifecycleManager.get_Instance () [0x00023] in /Users/petrosmaliotis/New Unity Project 4/Assets/GoogleARCore/SDK/Scripts/Managers/ARCoreAndroidLifecycleManager.cs:80
      at GoogleARCoreInternal.LifecycleManager.get_Instance () [0x00029] in /Users/petrosmaliotis/New Unity Project 4/Assets/GoogleARCore/SDK/Scripts/Managers/LifecycleManager.cs:43
      at GoogleARCore.ARCoreS


Solution 1:[1]

Managed to solve it by adding the folders [ jniLibs, assets, libs ] to my project along with the library.

It appears to be a problem when you export a UnityProject as library.

Copy and paste those folders from the UnityProject (the exported version from Unity) to the project you imported your library and make some changes in the Manifest and Gradle (app) file. Make sure that the folders are in the correct place.

libs should be in: yourApp/app/libs

jniLibs should be in: yourApp/app/src/main/jniLibs

assets should be in: yourApp/app/src/main/assets

Gradle changes.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.something.ar"
        minSdkVersion 26
        targetSdkVersion 28
        ndk {
            abiFilters 'armeabi-v7a', 'x86'
        }
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } }

    aaptOptions {
        noCompress = ['.unity3d', '.ress', '.resource', '.obb']
    }

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

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation(name: 'arcore_client', 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')
    implementation project(':ar_demo')
    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'
}

Manifest file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.something.ar">

    <supports-screens
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:xlargeScreens="true"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>

        </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="a2756142-8f7a-45e0-95ae-a566f7d2a2a2"/>
        <meta-data
            android:name="unity.splash-mode"
            android:value="0"/>
        <meta-data
            android:name="unity.splash-enable"
            android:value="True"/>
    </application>

    <uses-feature android:glEsVersion="0x00020000"/>

    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <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>

Solution 2:[2]

Other possible solution is to fix autogenerated Unity build.gradle file. Change dependencies part to

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //implementation(name: 'arcore_client', ext:'aar')
    //implementation(name: 'ARPresto', ext:'aar')
    //implementation(name: 'unityandroidpermissions', ext:'aar')
    //implementation(name: 'UnityARCore', ext:'aar')

    implementation files('libs/arcore_client.aar')
    implementation files('libs/ARPresto.aar')
    implementation files('libs/unityandroidpermissions.aar')
    implementation files('libs/UnityARCore.aar')
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 insomniusWalker
Solution 2 ilya_kas