Pages

Subscribe:

Ads 468x60px

5/15/13

Import Vuforia Android Sample in OS X

Phew, it has been so long until I decided to write new tutorial. I have done some just-for-me app, but I just can't stop and write some tutorial about it. And today I grant my wish to write one simple tutorial.


So, AR(Augmented Reality) became very popular these days. And I wish to make one, hopefully with my very own mascot 3D model in near future. But as for now, I will just start the very basic steps.



The first step is to sign up in Vuforia website, and log in. Then go to developer page that give you tutorial how to make Android AR apps used Vuforia. Here I will give some general steps.

1. Download Eclipse, Android SDK, ADT and NDK. Install it based on Android page or here


2. Download vuforia SDK from this page. Unzip it, double click it, and instal it.


3. As a result, you will get this folders :
    4. Then set the QCAR environment variable on eclipse. Eclipse->PreferencesNavigate to Java->Build Path->Classpath Variables using the hierarchy browser. Create a new variable by selecting New...

    5. Now, download the Vuforia samples project from this page.

    6. You may extract it and put it in folder samples inside vuforia-sdk-android-2-0-31 like me.

    7. For this tutorial, I will use ImageTarget project as an example.

    8. Open terminal, then go to ImageTarget project location, and do ndk-build to create native library.
    bash-3.2# cd /Volumes/Data/Android/newVuforia/vuforia-sdk-android-2-0-31/samplesbash-3.2# cd ImageTargets-2-0-7/
    bash-3.2# ls.DS_Store assets project.properties.classpath jni res.project license.txt srcAndroidManifest.xml media 
    bash-3.2# ndk-build

    Compile++ arm    : ImageTargets <= ImageTargets.cpp
    Compile++ arm    : ImageTargets <= SampleUtils.cpp
    Compile++ arm    : ImageTargets <= Texture.cpp
    StaticLibrary  : libstdc++.a
    Prebuilt       : libQCAR.so <= jni/../../../build/lib/armeabi/
    SharedLibrary  : libImageTargets.so
    Install        : libImageTargets.so => libs/armeabi/libImageTargets.so
    Install        : libQCAR.so => libs/armeabi/libQCAR.so
    Compile++ arm    : ImageTargets <= ImageTargets.cpp
    Compile++ arm    : ImageTargets <= SampleUtils.cpp
    Compile++ arm    : ImageTargets <= Texture.cpp
    StaticLibrary  : libstdc++.a
    Prebuilt       : libQCAR.so <= jni/../../../build/lib/armeabi-v7a/
    SharedLibrary  : libImageTargets.so
    Install        : libImageTargets.so => libs/armeabi-v7a/libImageTargets.so
    Install        : libQCAR.so => libs/armeabi-v7a/libQCAR.so
    bash-3.2# 

    9. Then, import ImageTarget project in Eclipse.

    10. Check the .jar of dependencies like QCAR.so, you may check the package tree like this :


    11.  You may see no errors and run it. But maybe you unfortunate like me to get such errors, when you click the "start" button:
    05-14 22:54:22.011: E/AndroidRuntime(17870): FATAL EXCEPTION: main

    05-14 22:54:22.011: E/AndroidRuntime(17870): java.lang.ExceptionInInitializerError
    05-14 22:54:22.011: E/AndroidRuntime(17870): at java.lang.Class.newInstanceImpl(Native Method)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at java.lang.Class.newInstance(Class.java:1409)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at android.app.Instrumentation.newActivity(Instrumentation.java:1040)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1777)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at android.app.ActivityThread.access$1500(ActivityThread.java:135)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at android.os.Handler.dispatchMessage(Handler.java:99)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at android.os.Looper.loop(Looper.java:150)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at android.app.ActivityThread.main(ActivityThread.java:4385)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at java.lang.reflect.Method.invokeNative(Native Method)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at java.lang.reflect.Method.invoke(Method.java:507)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at dalvik.system.NativeStart.main(Native Method)
    05-14 22:54:22.011: E/AndroidRuntime(17870): Caused by: java.lang.NoClassDefFoundError: java.util.UUID
    05-14 22:54:22.011: E/AndroidRuntime(17870): at java.lang.Runtime.nativeLoad(Native Method)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at java.lang.Runtime.loadLibrary(Runtime.java:432)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at java.lang.System.loadLibrary(System.java:554)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at com.qualcomm.QCARSamples.ImageTargets.ImageTargets.loadLibrary(ImageTargets.java:858)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at com.qualcomm.QCARSamples.ImageTargets.ImageTargets.<clinit>(ImageTargets.java:125)
    05-14 22:54:22.011: E/AndroidRuntime(17870): ... 15 more
    05-14 22:54:22.011: E/AndroidRuntime(17870): Caused by: java.lang.NoClassDefFoundError: java.util.UUID
    05-14 22:54:22.011: E/AndroidRuntime(17870): ... 20 more
    05-14 22:54:22.011: E/AndroidRuntime(17870): Caused by: java.lang.NoClassDefFoundError: com.qualcomm.ar.pl.RenderManager
    05-14 22:54:22.011: E/AndroidRuntime(17870): ... 20 more
    05-14 22:54:22.011: E/AndroidRuntime(17870): Caused by: java.lang.NoClassDefFoundError: com.qualcomm.ar.pl.SystemTools
    05-14 22:54:22.011: E/AndroidRuntime(17870): ... 20 more
    05-14 22:54:22.011: E/AndroidRuntime(17870): Caused by: java.lang.NoClassDefFoundError: com.qualcomm.ar.pl.SensorController
    05-14 22:54:22.011: E/AndroidRuntime(17870): ... 20 more
    05-14 22:54:22.011: E/AndroidRuntime(17870): Caused by: java.lang.NoClassDefFoundError: com.qualcomm.ar.pl.SystemTools
    05-14 22:54:22.011: E/AndroidRuntime(17870): ... 20 more
    05-14 22:54:22.011: E/AndroidRuntime(17870): Caused by: java.lang.NoClassDefFoundError: com.qualcomm.ar.pl.ARHttpClient
    05-14 22:54:22.011: E/AndroidRuntime(17870): ... 20 more
    05-14 22:54:22.011: E/AndroidRuntime(17870): Caused by: java.lang.NoClassDefFoundError: com.qualcomm.ar.pl.FileTools
    05-14 22:54:22.011: E/AndroidRuntime(17870): ... 20 more
    05-14 22:54:22.011: E/AndroidRuntime(17870): Caused by: java.lang.NoClassDefFoundError: javax.crypto.spec.SecretKeySpec
    05-14 22:54:22.011: E/AndroidRuntime(17870): ... 20 more
    05-14 22:54:22.011: E/AndroidRuntime(17870): Caused by: java.lang.NoClassDefFoundError: com.qualcomm.ar.pl.CameraPreview
    05-14 22:54:22.011: E/AndroidRuntime(17870): ... 20 more
    05-14 22:54:22.011: E/AndroidRuntime(17870): Caused by: java.lang.ClassNotFoundException: com.qualcomm.ar.pl.CameraPreview in loader dalvik.system.PathClassLoader[/data/app/com.qualcomm.QCARSamples.ImageTargets-1.apk]
    05-14 22:54:22.011: E/AndroidRuntime(17870): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
    05-14 22:54:22.011: E/AndroidRuntime(17870): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    05-14 22:54:22.011: E/AndroidRuntime(17870): ... 20 more


    12. From there you can see that the problem is about the path error, so :
    - go to project Properties > Java Build Path -> select the "Order and Export"  tab
    - here you must enable the checkbox of the QCAR.jar dependency (i.e. "QCAR_SDK_ROOT/....")
    - then Apply/OK and make a clean / build (also, make sure to refresh the project whenever you ndk-build)


    13. Then I restarted my Eclipse. When I re-run it, it doing fine. You may try it, this is the target image of ImageTarget project :

    Congratulation, you have run the Vuforia sample app successfully in Eclipse.

    0 comments:

    Post a Comment