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 file
  • Add the following to the build.gradle file:
1
repositories {
2
maven {
3
url 'https://leiainc.jfrog.io/leiainc/gradle-release'
4
}
5
}
Copied!
  1. 1.
    Add a dependency to the Leia library:
1
dependencies​ {
2
​implementation​ ​'com.leia:leiasdk:4.2.1'
3
}
Copied!
  • 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:
1
import​ ​com​.leia.android.lights.LeiaSDK​;
Copied!
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
  1. 1.
    Open the build.gradle file which you opened for the previous step to include the Leia Android module.
  2. 2.
    Add the following to the build.gradle file:
1
android {
2
...
3
defaultConfig {
4
...
5
ndk {
6
abiFilters ​'arm64-v8a'
7
}
8
...
9
}
10
...
11
}
Copied!
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>
1
<application root>/distribution/
Copied!
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
1
<application root>/distribution/lei​a_sdk
Copied!
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
1
<application root>/<distribution folder>/leia_sdk/include
2
<application root>/<distribution folder>/leia_sdk/lib
Copied!
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.
1
android {
2
sourceSets {
3
main {
4
jniLibs.srcDirs = ['./../distribution/leia_sdk/lib']
5
}
6
}
7
}
Copied!
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:
  1. 1.
    Include the library in the modules CMakeLists.txt
    Note: These changes can be found in ​Appendix B​ or in the TeapotsWithLeia sample at:
    1
    `<LeiaNativeSDK dir>/samples/TeapotsWithLeia/classic-teapot/src/main/cpp/CMakeLists.txt`
    Copied!
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.
1
set(distribution_DIR ${CMAKE_SOURCE_DIR}/../../../../<distribution dir>)
Copied!
B. Add a library variable to the project by adding a call to “add_library”
1
add_library(lib_lei​a_sdk​ STATIC IMPORTED)
Copied!
C. Set the library variable properties by calling “set_target_properties” directly below the “add library” call in (B)
1
set_target_properties(lib_leia_sdk PROPERTIES IMPORTED_LOCATION
2
​${distribution_DIR}/leia_sdk/lib/​${ANDROID_ABI}/libleiasdk.​so​)
Copied!
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.
1
target_include_directories( <ACTIVITY NAME> ​PRIVATE
2
${distribution_DIR}/leia_sdk/i​nclude)
Copied!
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
1
target_link_libraries(<ACTIVITY NAME>
2
lib_lei​a_sdk)
Copied!
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
Copy link