Deploy yolov5 to the mobile phone through Android Studio (2023 latest version suitable for newbies)
java17 installation
Downloadjava17
Configure environment variables
This is the path after I installed it, copy this path
Set environment variables
Click New in System Variables
JAVA_HOME
%JAVA_HOME17%
Continue to create a new
CLASSPATH
.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar
Continue to create a new
JAVA_HOME17
自己的java17路径
After the new creation is completed, click OK
Test Java17
java -version
Successful installation! ! ! !
Android studio installation
Android Studio download
Download link: Download Android Studio & App Tools - Android Developers (google.cn)
The current version is: | 2022.3.1 Patch 1
start installation
Remember to change the path, don’t put it in the c drive
basic configuration
- After opening, the system will prompt to import the Android Studio configuration, select Do not import settings , and then click OK .
- Set up data sharing and select Don't send
- When prompted to update the plug-in, you can click Update to update, or ignore it.
- Click: Next to enter the next step
- Select the installation type: Standard (default) or Custom (custom), click: Next to proceed to the next step
- Select the Android SDK component to be installed and the installation location. The default component is sufficient. Check all the boxes below. I have already installed it here. You can choose the installation location by yourself (don’t put it on the c drive). Click: Next to enter the next step . .
- Emulator Settings emulator memory allocation, allocate the required memory (this step is not skipped directly)
8. Click Finish to install the components selected above.
- Wait for the download and installation to complete.
10. Click Finish to complete the installation.
yolo configuration
Download the following two yolo links: (I guess you need to use an accelerator here, otherwise it will be slower)
First:
Releases · Tencent/ncnn (github.com)
the second:
nihui/ncnn-android-yolov5: The YOLOv5 object detection android example (github.com)
After downloading the two files, unzip them
After opening the vulkan file, copy and paste it into ncnn-android-yolov5-master\app\src\main\jni
copy:
Paste location:
Use Android studio to open ncnn-android-yolov5-master (don't open the wrong path here, otherwise it will be difficult to install)
Then modify the directory at the same level and change the variable value CMakeLists.txt
in it toncnn_DIR
set(ncnn_DIR ${CMAKE_SOURCE_DIR}/${ANDROID_ABI}/lib/cmake/ncnn)
Continue to modify the file, open ncnn-android-yolov5-master/build.gradle, and replace the red box with 7.3.0 (you can also open the file with android studio)
Continue to modify the file, open ncnn-android-yolov5-master\gradle\wrapper, and replace the red box with 7.4 (you can also use android studio to open the file)
sdk configuration
Open settings
Pay attention to the installation of cmake here, click on show package in the lower right corner...
Then click apply
After the sdk download is completed, open the following file with Android Studio and wait for compilation
Install the app on your phone
Connect the computer to the data cable and plug it into the phone. Turn on the developer mode on the phone (the location may be different for different phones), turn on USB debugging, and USB installation. Android Studio will recognize the mobile device.
My mobile device
Click to run
After running, the software will be installed on the phone:
running result: