Project Setup Steps
This section explains the steps required to prepare your Android Studio project to use the LeiaNativeSDK.
To start, open your existing project or start a new NDK project in Android Studio.
Next connect to the Java module that gives access to the Leia Display and the hardware values associated with that.
In Android Studio, every project contains modules, and both the project and modules contain build.gradle files. The modules are where the local code exists, so any module that will be interacting with the Leia Display needs to be adjusted. You can add the Java module to your own application module:
Note: These changes can be found in Appendix A or in the TeapotsWithLeia sample at:
<LeiaNativeSDK dir>/samples/TeapotsWithLeia/classic-teapot/build.gradle
In your module’s folder, open the
build.gradle
fileAdd the following to the build.gradle file:
Add a dependency to the Leia library:
NOTE: On older projects, “implementation” will need to be changed to “compile”
TEST: You can now include Leia specific imports if everything went well. If adding imports from
the Leia module works, then you have successfully pulled it into your application. Rebuilding
your project should work without error. Errors like “error: package com.leia.android.lights does
not exist” show the above did not work.
Try adding the following code to your application module and if the rebuild works you can move
on to the next step:
Now that the build.gradle knows how to find the Android module, you want to update your application module to build for the correct target. In this case, the build target supported by Leia currently is “arm64-v8a”. The way we can add this to the module is by doing the following: Note: These changes can be found in Appendix A or in the TeapotsWithLeia sample at:
<LeiaNativeSDK dir>/samples/TeapotsWithLeia/classic-teapot/build.gradle
Open the build.gradle file which you opened for the previous step to include the Leia Android module.
Add the following to the build.gradle file:
Once the Java module added, it is necessary to link to the native portion. Android Studio supports CMakeLists.txt for building native applications, this is the approach used to add the native LeiaNativeSDK library. First add the header files and libraries into the project by creating a common directory. Then update the CMakeLists.txt file in the source code directory. The steps below show how to do this:
1) In the application root directory, create a folder for common libraries Note: These changes can be found in:
<LeiaNativeSDK dir>/samples/TeapotsWithLeia/
A. referenced in future steps as
<application root>/<distribution folder>
2) Inside the
<distribution folder>
, create a folder named “leia_sdk” Note: These changes can be found in:<LeiaNativeSDK dir>/samples/TeapotsWithLeia/distribution/
A. referenced in future steps as
<application root>/<distribution folder>/leia_sdk
3) Inside the leia folder just created, add the folders found in the LeiaNativeSDK folder. Note: These changes can be found in:
<LeiaNativeSDK dir>/samples/TeapotsWithLeia/distribution/leia_sdk
With the directory created, you have added the Leia native libraries to your project. Now you need to tell the project how to find them and include them in the application. This can be done accomplished by the following steps:
Note: These changes can be found in Appendix A or in the TeapotsWithLeia sample at:
<LeiaNativeSDK dir>/samples/TeapotsWithLeia/classic-teapot/build.gradle
1) Update the build.gradle for the application’s module which will be using the Leia library by adding jniLibs.srcDirs with the distribution directory from the previous step. If the build.gradle already contains jniLibs.srcDirs, and the distribution directory from the previous step to the list instead.
Your application now understands how to interact with the Leia Java module, and it knows how to find the Leia library, and include it in the package. The next step is to make the library visible to the native code, so you can make LeiaNativeSDK library calls. To do this, follow the instructions below:
Include the library in the modules CMakeLists.txt
Note: These changes can be found in Appendix B or in the TeapotsWithLeia sample at:
A. Add a Cmake variable for the distribution directory (and change
<distribution dir>
to your directory) by calling the “set” function, near the top of the file.
B. Add a library variable to the project by adding a call to “add_library”
C. Set the library variable properties by calling “set_target_properties” directly below the “add library” call in (B)
D. Add the include directory for the headers (and change ACTIVITY NAME to the name of activity running your module) by adding a call to “target_include_directories” function.
E. Link to the library (and change ACTIVITY NAME to the name of activity running your module) by adding “lib_leia_sdk” to the “target_link_libraries” function
TEST: Add one of the header files included in
<application root>/<distribution folder>/leia_sdk/include
and from the Build menu select Rebuild Project to verify the application can now see the include directory
Last updated