Beginner: Integration of Huawei Accelerate Kit in kotlin (Android)

Introduction

Huawei provides various services for developers to make ease of development and provides best user experience to end users. In this article, we will cover integration of HUAWEI Accelerate Kit in Android.

HUAWEI Accelerate Kit provides multi-thread programming APIs, enhancing the program performance and facilitating the development of multi-core and multi-thread apps, and also provides the multi-thread acceleration capability that efficiently improves concurrent execution of multiple threads. Accelerate Kit provides a new multithreaded programming method using multithread-lib. It unlatched you from the thread management details, so you can focus on developing apps that can fully utilize the multi-core hardware capability of the system, promising more efficient running.

Use Cases

  • Concurrent execution of tasks
  • Serial execution of tasks
  • Synchronization of tasks

Development Overview

You need to install Android studio IDE and I assume that you have prior knowledge about the Android and java.

Hardware Requirements

  • A computer (desktop or laptop) running Windows 10.
  • A Huawei phone (with the USB cable), which is used for debugging.

Software Requirements

  • Java JDK installation package.
  • Android studio IDE installed.
  • Android 5.0 or later.

Follows the steps.

1. Create Android Project.

  • Open Android Studio.
  • Click NEW Project, select a Project Templet.
  • Select Native C++.
  • Enter project name and Package Name and click on Finish:

2. Modify the build.gradle file. Open the /app/build.gradle file and NDK build support lines as follows.

  • arguments “-DANDROID_STL=c++_shared”: multithread-lib depends on libc++. Therefore, c++_shared needs to be declared in the CMake compilation options. Otherwise, some functions will fail to work.
  • abiFilters “arm64-v8a”, “armeabi-v7a”: multithread-lib supports only arm64-v8a and armeabi-v7a.
  • jniLibs.srcDirs = [‘libs’]: specifies the directory of the .so files.

3. Download the SDK package from this link and unzip.

4. Copy the header files in the SDK to the resource library.

In the /app directory, create an include folder. Copy the files to the created include folder as per below screen.

5. Copy the .so files in the SDK to the resource library.

  • Under the /app/libs directory, create two subdirectories: arm64-v8a and armeabi-v7a.
  • Copy the libdispatch.so, libdispatch_stat.so, and libBlocksRuntime.so files in the /lib64 directory of the SDK to the /libs/arm64-v8a directory of Android Studio.
  • Copy the libdispatch.so, libdispatch_stat.so, and libBlocksRuntime.so files in the /lib directory of the SDK to the /libs/armeabi-v7a directory of Android Studio.

6. Modify the CMakeLists.txt file in the app/src/main/cpp directory as shown below.

7. Register as Huawei developer and complete identity verification in Huawei developer’s website, refer to register a Huawei ID.

8. To generate SHA-256 certificate fingerprint. On right-upper corner of android project click Gradle, choose Project Name > app > Tasks > android, and then click signing Report, as follows.

Also we can generate SHA-256 using command prompt.

To generating SHA-256 certificate fingerprint use below command.

9. Create an App in AppGallery Connect.

10. Add the below plugin and dependencies in build.gradle(App level)

11. Open AndroidManifest file and add below permissions.

12. Development Procedure.

Create a kotlin class MainActivity.kt inside your package.

Create activity_main.xml layout file under app > main > res > layout folder.

13. To build apk and run in device, choose Build > Generate Signed Bundle/APK > Build for apk or Build and Run into connected device follow the steps.

Result

The output response of HMS Acceleration Kit is quite faster than the kotlin multithreading code. Although, it depends on your chipset also.

1. Click on “Calculate PI Value” button, it will calculate PI value and shows below result.

2. Click on “Calculate PI Single Thread” button, it will calculate PI value and will check how much time it will take to execute.

3. Click on “Calculate PI Multiple Thread” button, it will calculate PI value using multiple thread and will check how much time it will take to execute.

Tips and Tricks

· Always use the latest version of the library.

· Add header file in include folder without fail.

· Add .SO in libs folder in respective subdirectories without fail.

· Make sure dependencies added in build files.

Conclusion

In this article, we have learnt integration of HUAWEI Accelerate kit. HUAWEI Accelerate Kit provides multi-thread programming APIs, enhancing the program performance and facilitating the development of multi-core and multi-thread apps and increased app overall performance.

References

Accelerate Kit:

https://developer.huawei.com/consumer/en/doc/development/graphics-Guides/introduction-0000001077053686?ha_source=hms1

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store