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 20.0.0

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

You can use EasyAR in Eclipse or Android Studio. For simple configuration, we suggest to use Android Studio 1.5 as we did in samples.

*Note: EasyAR do not support Java only API for now, you have to program both Java code and C++ code to make EasyAR work. You can reference the samples to do so. It is relatively simple to use EasyAR C++ classes, you do not have to worry about pointers and memory management. We will add Java API support in future releases.

To use EasyAR in Android Studio 1.5 like the samples, you may also need the followings

JDK 1.7 or later

Android Studio 1.5 or later

Android NDK r10e

Android SDK with Build Tools at least version 20.0.0

Android API 23 (download from Android SDK Manager)

*Note: EasyAR SDK do support building from Android Studio 1.4 or below, or from Eclipse. We choose Android Studio 1.5 for sample creation because it is the best tool for now that offers a simple way to configure and debug Android Java code and C++ code together.

Import EasyAR Android SDK

This step is different in Eclipse and Android Studio, and you may need to write Android.mk in some tools. Here we will introduce the configuration details when using Android Studio 1.5.

First you have to change your build.gradle according to this official article.

After above change, you can now add EasyAR specific configurations

Add EasyAR native include directories

model {
    android.ndk {
        cppFlags.add("-I${file("/path/to/EasyARSDK/package/include")}".toString())
    }
}

You may also want to add some common native configurations

model {
    android.ndk {
        cppFlags.add("-DANDROID")
        cppFlags.add("-fexceptions")
        cppFlags.add("-frtti")
        stl = "gnustl_static"
        ldLibs.add("log")
        ldLibs.add("GLESv2")
    }
}

Add EasyAR native library dependencies

model {
    android.sources {
        main {
            jni {
                dependencies {
                    library file("/path/to/EasyARSDK/package/Android/libs/armeabi-v7a/libEasyAR.so") abi "armeabi-v7a"
                }
            }
        }
    }
}

Add EasyAR Java library dependencies

dependencies {
    compile fileTree(include: ['*.jar'], dir: '/path/to/EasyARSDK/package/Android/libs')
}

Finially you may have a build.gradle like this

apply plugin: 'com.android.model.application'
model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.2"
        defaultConfig.with {
            applicationId = "cn.easyar.samples.helloar"
            minSdkVersion.apiLevel  =15
            targetSdkVersion.apiLevel = 22
            versionCode = 1
            versionName = "1.0"
        }
    }
    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles.add(file("proguard-rules.pro"))
        }
    }
    android.ndk {
        moduleName = "HelloARNative"
        cppFlags.add("-I${file("../../../package/include")}".toString())
        cppFlags.add("-DANDROID")
        cppFlags.add("-fexceptions")
        cppFlags.add("-frtti")
        stl = "gnustl_static"
        ldLibs.add("log")
        ldLibs.add("GLESv2")
    }
    android.productFlavors {
        create("arm") {
            ndk.with {
                abiFilters.add("armeabi-v7a")
            }
        }
    }
    android.sources {
        main {
            jni {
                dependencies {
                    library file("../../../package/Android/libs/armeabi-v7a/libEasyAR.so") abi "armeabi-v7a"
                }
            }
        }
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: '../../../package/Android/libs')
}

If you are using Eclipse or Android Studio 1.4 or bellow, you may need to write Android.mk. You can find relative settings like above.

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 EasyAR.initialize to initialize EasyAR. You can add the initialize into your activity like this.

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

Other Code

The reset is to write EasyAR logics and other code. Both Java code and C++ code are needed. You can reference EasyAR samples for more details.

results matching ""

    No results matching ""