android studio creates C++ project

1. Create a Native C++ project
insert image description here
2. Configure the project environment
insert image description here
insert image description here
3. Run the code
Select the project in the upper left corner and replace Android with Project
insert image description here
insert image description here
4. Download the toolkit that C++ runs dependent on.
As shown in the figure, select NDK and CMake, and click Apply. A pop-up window will appear, telling you the name, version and other information of the package to be installed. At this point, just click ok (next), and the following is waiting for the installation.

  Android Native Development Kit (NDK): A toolset that enables you to use C and C++ code in Android projects; it provides various platform libraries that allow you to manage native activities and access physical device components such as sensors and touches enter.
  CMake: An external build tool that works with Gradle to build native libraries. If you only plan to use ndk-build, you don't need this component.

insert image description here
5. Create a virtual machine
insert image description here
  and select a mobile phone model, just choose it.
insert image description here
  Select x86 pixels, and then select a suitable version and click Download. The suitable version is actually that there is no error in the red font on the right, but the system version number must be correct. Check whether your machine is 32-bit or 64-bit, and then click finish. Just wait for the download. insert image description here
  After creating the virtual machine, click Run, or double-click, and the virtual machine will appear below.
insert image description here
6. Run the code
  Run the code, the result of the virtual machine is as shown in the figure:
insert image description here
Question 1: If the virtual machine in the upper left corner is not loaded after starting the virtual machine.
insert image description here
insert image description here
Solution:
<1>, task manager, end the adb process, as many as there are, here may be due to multiple clicks to run or other reasons, start multiple adb.exe, all end.
insert image description here
<2>, win+r, enter cmd to open the dos window, first execute adb kill-server, and then execute adb start-server.
At this point, please note that running adb kill-server will report an error, showing that port 5037 is called. Here I will teach you most of the methods on the Internet to let you check what process the port is called, and then end the process.
But what I want to say is, don't worry about it, just report an error, and then continue to run adb start-server.
insert image description here
At this point, return to android studio, and you will find that the virtual machine is successfully loaded.
<3>, if it still doesn't work, restart android studio, and remember to open it as an administrator.
Question 2: The java file cannot be run, or adb cannot be run
Solution:
<1. Install jdk, configure jdk environment variables
<2. Install SDK, configure SDK environment variables

Guess you like

Origin blog.csdn.net/weixin_43202123/article/details/125484685
Recommended