- Print
- DarkLight
Adding HUD APIs and Project Cleanup
Configure build.gradle
Android projects have multiple build.gradle files. These files provide the compiler with compile-time information about the project. This information includes how to compile, what dependency libraries are used, where to get them, and which Android versions the application will support in addition to other application information.
For this example, it is important to configure the build.gradle file for the main app module. Please be sure to modify the correct file as shown below. Open the build.grade (Module: ShieldSampleApp), not the build.gradle (Project: ShieldSampleApp) file. The screen below shows an unmodified version of the build.gradle file generated by Android Studio. There is some additional information here that we will remove shortly.
For simplicity of this example application, remove the testInstrumentationRunner line from the defaultConfig section.
And replace all of the dependencies in the dependencies section with simply implementation 'com.vuzix:hud-actionmenu:1.13.0' and implementation 'com.vuzix:hud-resources:1.8.0'.
Note: Anytime this file is modified, Android Studio will display a warning stating that the files have changed, and a project sync should be performed. We will do a project sync after making other changes as well.
Before we can sync the project, let’s change the layout of the main activity as described in the next section.
Change Default Activity Layout
By default, Android Studio will generate activities using a Constraint layout. For simplicity, this example uses the Relative layout.
Open the activity_main.xml layout (\res\layout\activity_main.xml).
The Layout will open on the "Design" tab but you may find the "Split" or "Code" tabs more useful.
We recommend that you change your Default Device via the Device Editor to be the Vuzix Shield. If you have not register the Vuzix Shield as a device in Android studio, we strongly recommend you do so now to aid in the development of UI elements.
Notice the ConstraintLayout class is used as the main Layout Element.
Change the Layout to now be a RelativeLayout by right clicking on the Constraint Layout in the Component Tree and choosing "Convert view".
For more information on the Android Layouts or the ConstraintLayout class see the Android documentation:
https://developer.android.com/guide/topics/ui/declaring-layout.
https://developer.android.com/reference/android/support/constraint/ConstraintLayout.
Note: The constraint layout requires a dependency. We removed that dependency when we modified the generated gradle.build file above.
Adding the Maven repository
If you are a Gradle version 6.8 or higher we are going to add the jitpack maven repository to the settings.gradle file. If you are on a lower version we will edit the Project build.gradle file. You can check this by
Sync the project
Now that we have modified the build.gradle file and simplified our activity layout, we are ready to sync the project.
Open the build.gradle file again and click on the Sync now link in the top right.
Android Studio will refresh the project using the modified build.gradle file and build the project.
If the build.gradle file and layout file are correct, the Build should complete successfully as shown below.
Once the project has built successfully, the Shield-specific libraries can be inspected in the Project window.
Change the project view from the Android view to the Project view in the top left of the file explorer.
Expand the External Libraries section to explore the hud-actionmenu and hud-resources classes.
We now have all the Vuzix HUD resource and libraries.
These libraries will provide a lot of resources that will help you as a developer to build more intuitive apps with performance dedicated to the Vuzix Shield.
To learn more about these libraries, you can download the independent JavaDocs or read our section on them.
JavaDocs
For the HUD Resource Package: HUD-Resources Java Docs
For the HUD ActionMenu Package: HUD-ActionMenu Java Docs