Using Android Studio with Vuforia

Installing Vuforia in Android Studio

You need to follow following Steps:

  • Read our Getting Started Guide for instructions on setting up the
    Java SDK, Android SDK and NDK:

    https://developer.vuforia.com/downloads/sdk

  • Make sure you have installed the latest version available of Android
    Studio from:

    http://developer.android.com/sdk/index.html

  • Use the Android SDK Manager (from within Android Studio) to get the
    latest Android SDK and Android Platform and Build tools

  • Launch Android Studio

  • Select File - > Import Project ... and browse to the root directory
    of the sample Vuforia project you want to open

  • Proceed in the Import Wizard dialog (click Next, Next) until you
    reach a page with this message:

    1. "Alternatively, you can fill in the actual path map in the table below":
    2. click to edit
    3. enter the actual path to the Vuforia.jar library (which is located under your vuforia_install_dir/build/java/vuforia)
  • In the Project view, right-click on the Project and expand the view
    hierarchy so to locate the Vuforia.jar under app > src > main

  • right-click on Vuforia.jar to open the context menu

  • click on the "Add as library..." option in the context menu

  • Alternatively, if you cannot locate the Vuforia.jar in your project
    hierarchy:

  • right-click on the Project and select, "Open Module Settings"

    1. select "App"
    2. then select the "Dependencies" tab
    3. Click on the "+" button to Add a File Dependency and browse to the

      Vuforia.jar file
  • Create a folder called "jniLibs" under the "app/src/main" folder under your Android Studio project directory

  • Copy the "armeabi-v7a" folder (including the libVuforia.so file
    located inside it) from the "vuforia_install_dir/build/lib" to the
    "app/src/main/jniLibs" folder

the resulting directory structure under your project root should be:

/app
/src
/main
/jniLibs
/armeabi-v7a
/**libVuforia.so**
  • If your project includes a "jni" folder, move it to a location
    outside of your project (otherwise Android Studio may attempt to
    compile the sources in that folder and may fail)
  • Clean and rebuild the project
  • Run the app on your device

Best Luck :)

Vuforia SDK and Android Studio?

To get the Vuforia samples compiling:

  1. Import the Vuforia samples [should be in VUFORIA_SDK/samples/VuforiaSamples-###. If there's only a zip, then extract that]
  2. Next step is handling how the folders were imported- this is to resolve the "cannot resolve symbol" errors. The issue is that the package name doesn't match the file path, ie you have to move all the files into the base app/java directory
    • Note that this may not be necessary if Android Studio imported all the folders correctly. Skip to Step 3 if that is so
    • Note that the project pane in Android Studio compresses all the empty directories in between, which you can toggle by clicking the gear icon in the Project pane then unchecking "Compact Empty Middle Packages"
    • Currently, the files that are causing all the issues should be in app/java/samples/src/com... or somewhere very similar. The com folder needs to be moved into the root java folder, ie app/java
    • In the Project pane inside Android Studio, right click the java directory and choose "Show in Files." Navigate to where your com folder currently is as mentioned previously, and move it to app/java. Done for these errors!
  3. Now you need to actually import the Vuforia jar dependency. This is in VUFORIA_SDK/build/java/vuforia, Vuforia.jar, and needs to be moved into your project.
    • You can move this probably far more elegantly and into a proper folder, but I just personally dragged the file into a directory. Take note of this directory
  4. Finally, Android Studio needs to actually add this as a dependency
    • The easiest way to do this is to open the now-named "Project Structure" window by Ctrl+Alt+Shift+S or under the File menu along the top. Go to your app then go to the Dependencies tab.
    • Click the plus button then choose "2. File Dependency"
    • Navigate to and choose the Vuforia.jar file you imported earlier
  5. You have to include the armeabi.jar file as a dependency, just like in Step 4
    • To create the armeabi.jar file, follow the guide here [for those parts]

Side Step:
If you're explicitly using the samples app, it still may not compile. Note that whoever wrote the app explicitly tried to take advantage of Eclipse's sorting system and other Eclipse-based features. If Android Studio messed up importing all the files, you may need to do more to get the app actually compiling. You may have a (runtime) error in AboutScreen for launching Activities and the error is in regards to launching the intents. You will need to modify how the entire app launches each intent, or do something very short-term like this just for testing:

// Starts the chosen activity
private void startARActivity()
{
Intent i = new Intent(this, ImageTargets.class);
// i.setClassName(mClassToLaunchPackage, mClassToLaunch);
startActivity(i);
}

Now your samples app should compile and run on your phone! Now, to simplify it all for any project, just do steps 3-5.

Incorporate vuforia android SDK in a new project

Instead of relying on Vuforia's module, I built my own real-time OCR from scratch, using the Camera (1) API and Google's Mobile Vision Library.

My app - Optical Dictionary & Vocabulary Teacher - performs a lot better than Vuforia's module. It does real-time scanning of words, shows them in a more friendly manner, and does way better validation of words. It even lemmatizes the words (e.g fooled -> fool, thieves -> thief etc).

Also, needless to say that this gave me complete control over my module as well.

Here is a Video Demo of my app.

If any one wants to build something similar, they can feel free to contact me for assistance.



Related Topics



Leave a reply



Submit