The Android Studio project

In this section, we will use the Android Studio IDE to create our mobile application. We can use a default Native C++ wizard in the Android Studio IDE to create an application stub. Android Studio will create a specific project structure; the following sample shows the most valuable parts of it:

app
|
src
|
main
cpp
|
CMakeLists.txt
native-lib.cpp
java
|
com
|
example
|
Camera2
|
MainActivity.java
res
|
layout
|
activity_main.xml
values
|
colors.xml
strings.xml
styles.xml
...
build.gradle
...
build.gradle
local.properties
...

The cpp folder contains the C++ part of the whole project. In this project, the Android Studio IDE created the C++ part as a native shared library project that had been configured with the CMake build generation system. The java folder contains the Java part of the project. In our case, it is a single file that defines the main activity—the object that's used as a connection between the UI elements and event handlers. The res folder contains project resources, such as UI elements and strings definitions.

We also need to create the jniLibs folder, under the main folder, with the following structure:

app
|
src
|
main
|
...
jniLibs
|
armeabi-v7a
|
libc10.so
libtorch.so
x86
|
...

Android Studio requires us to place additional native libraries in such folders to correctly package them into the final application. It also allows the JNI system to be able to find these libraries. Notice that we placed PyTorch libraries in the armeabi-v7a folder because they have only been compiled for this CPU architecture. If you have libraries for other architectures, you have to create folders with corresponding names.

The IDE uses the Gradle build system for project configuration, so there are two files named build.gradle, which contains the main settings, and local.properties, which contains user-defined values.

Now, we can adapt the default UI for our purposes. We'll learn how to do this in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.189.228