Setting up EasyAR Android SDK

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 and this for samples.

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

Pre-Requirements

  • JDK 1.7 or later

  • Android NDK

  • Android SDK with Build Tools at least version 23.0.1

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

You can use EasyAR in Eclipse or Android Studio.

EasyAR SDK 2.0 and later have both Java and C++ API, you can choose your favorite language.

Import EasyAR Android SDK

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

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 SDK -- Java API

Nothing special.

Gradle Configuration for EasyAR SDK -- 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/armeabi-v7a
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'
        }
    }
}

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

(deprecated in 2.1.0) Use cn.easyar.engine.EasyAR.initialize to initialize EasyAR. You can add the initialize into your activity like this.

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

(since 2.1.0) Use cn.easyar.Engine.initialize to initialize EasyAR. You can add the initialize into your activity like this.

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

Other Code

The reset is to write EasyAR logics and other code. You can reference EasyAR samples for more details.