Setting up EasyAR Sense for Android

This article shows how to setup EasyAR non-Unity Android projects using EasyAR package.

If you want to use EasyAR unity package, please read this for setup.

If you want to run EasyAR non-Unity Android sample, please read this instead.

Pre-Requirements

  • JDK 1.8 or later

  • Android NDK

  • Android SDK with Build Tools at least version 28.0.3

It is recommended to install the latest version of NDK and SDK

You can use EasyAR in Eclipse or Android Studio.

EasyAR Sense have both Java and C++ API, and support Kotlin, you can choose your favorite language.

Import EasyAR Sense for Android

Configuration may be different when using different IDEs. Here we will introduce the configuration details when using Android Studio 2.2 and later with gradle.

Using Java only API

  • Put EasyAR.aar to app/libs or explicitly specified folder in your gradle settings.

Using both Java and C++ API

  • Put EasyAR.jar to app/libs or explicitly specified folder in your gradle settings.

  • Put armeabi-v7a and/or arm64-v8a to app/src/main/jniLibs or explicitly specified folder in your gradle settings.

  • Put easyar folder from include to app/src/main/jni or explicitly specified folder in your Android.mk or CMakeLists.txt.

You can get more details about arm64-v8a support from About Android arm64-v8a.

Gradle Configuration for EasyAR Sense – Java API

Nothing special.

Gradle Configuration for EasyAR Sense – C++ API

You may reference Google official article for this.

Makefile / CMakeLists

Here we only describe how to write Android.mk, if you prefer CMake, you can reference Google official article.

  1. prebuilt library

include $(CLEAR_VARS)
# make sure this path is available for libEasyAR.so
LOCAL_PATH := $(LOCAL_PATH_TOP)/../jniLibs/$(TARGET_ARCH_ABI)
LOCAL_MODULE := EasyAR
LOCAL_SRC_FILES := libEasyAR.so
include $(PREBUILT_SHARED_LIBRARY)
  1. link libEasyAR.so

    GLESv2 is required.

LOCAL_LDLIBS += -lGLESv2
LOCAL_SHARED_LIBRARIES += EasyAR

External Native Build

android {
    externalNativeBuild {
        ndkBuild {
            path 'src/main/jni/Android.mk'
        }
    }
}

If you prefer CMake, you can reference Google official article.

Specify ABIs

android {
    defaultConfig {
        ndk {
            abiFilters 'armeabi-v7a', 'arm64-v8a'
        }
    }
}

If you need only one of armeabi-v7a or arm64-v8a, keep that one in the above.

Warning: Since August 1, 2019, Google Play Store requires that an application with armeabi-v7a be committed with support for arm64-v8a. (Support 64-bit architectures)

Add Permissions in AndroidManifest

EasyAR require the following permissions, missing permissions may cause initialize fail.

android.permission.CAMERA android.permission.INTERNET

Add them to AndroidManifest like this.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.easyar.samples.helloar" >
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.INTERNET" />
</manifest>

Initialize EasyAR

Use cn.easyar.Engine.initialize to initialize EasyAR. You can add the initialization into your activity like this.

protected void onCreate() {
    Engine.initialize(this, key);
}

Other Code

What is left is to write EasyAR logics and other code. You can refer to EasyAR samples for more details.

260 character path limit on Windows

On Windows, if any file in the project (including temporary files generated in the build process) has a path of longer than 260 characters, Android Studio may fail the build. Reduce the directory path length to workaround this problem.

ARCore

If you use ARCore, please refer to its official documentation to configure AndroidManifest and build.gradle.

In spite of that, it is neccessary to call the following line before initialization of EasyAR.

System.loadLibrary("arcore_sdk_c");