This is a continuation of I want to develop Android apps on Android. It describes from installing adb, a tool for debugging, to actually starting the debugger using Android Studio.
You need one PC. It cannot be implemented on Android alone. This time, I will introduce the procedure using Windows.
Android needs to be connected to a router etc. via Wifi.
The screen display of Ubuntu is described on the assumption that XSDL is used.
Open the following site on Windows, download the SDK Platform Tools, and unzip it.
https://developer.android.com/studio/releases/platform-tools.html
After unzipping, you should find the adb.exe file in the platform-tools folder. You will use adb.exe later.
Install the USB driver on Windows. Later I will connect my Windows and Android device with a USB cable, Use the USB driver to recognize your Android device from Windows. I can't write the procedure because the driver is different for each company that develops Android devices. It will be thrown round, but please install it referring to the following site.
https://developer.android.com/studio/run/oem-usb
Turn on the developer option on your Android device, then turn on USB debugging. When enabled, it runs in debug mode and can be stopped in the middle of the program. Since the procedure is different for each Android device, please refer to the following site as it can not be written.
https://developer.android.com/studio/debug/dev-options
Start UserLAnd or Termux Ubuntu on an Android device and execute the following command from LXTerminal etc. to install adb.
#Install adb on Ubuntu (Termux does not require sudo; UserLAnd requires sudo)
sudo apt install -y adb
#Copy adb and make it available from Android Studio
cp /usr/bin/adb ~/Android/Sdk/platform-tools/
Connect Windows and Android with a USB cable. A dialog will appear, so press the OK button.
Right-click on the Windows mark and select "Run". Type cmd in the name field and press Enter to bring up the command prompt.
Use the cd command to go to the platform-tools directory where the adb command is located, and use adb to connect to your Android device via Wifi as shown below.
# D:\platform-tools_r29.0.6-windows\To platform-If you have tools. Please read as appropriate according to the decompression destination you specified.
cd D:\platform-tools_r29.0.6-windows\platform-tools
#Set up your Android device to connect via Wifi
adb tcpip 5555
Execute adb and when "restarting in TCP mode port: 5555" is displayed, disconnect the USB cable. The settings you make here will take effect until you restart Android.
Launch the Ubuntu desktop environment, then launch Android Studio. (If you have already started Android Studio, please close it and then restart it.) If the Android device name appears in the combo box at the bottom of the menu, it is successful. It is ready for debugging.
Let's actually try the debugger.
First, after creating a suitable project, open MainActivity.java. You should see the onCreate method. Click on the right side of the line number on the left side of the first line in the method, the line that says super.onCreate ~. Is it circled? Pauses the running program at this circle.
Next, there are four buttons on the right side of the Android device name under the menu that are shaped like insects. Press the bug button. After a while, the app will launch and you will see Waiting For Debugger. Do not press Force Close at this time.
Open the Android notification area and click XServer XSDL is running. (Be careful not to touch Stop on the right side) After returning to Android Studio and waiting for a while, Waiting For Debugger will automatically disappear and start debugging. It should have stopped at the circled line earlier.
Now you can debug. The fact that you don't need an emulator may be an advantage.
Recommended Posts