Original Android Studio
Android Studio is the most commonly used development tool for Android developers. Based on IntelliJ IDEA, It provides many powerful functions and is the first choice for Android developers. However, Android Studio also has its own problems. However, when using Android Studio, it feels a bit bloated, the memory starts to rise after opening a few more pages, the computer fan is buzzing, and every time he has to wait for the project to be compiled after syncing. Of course, all this is ok, but I have recently started to look at some C++ code, and Android Studio looks a bit inconvenient. Since vscode is used to write C++ before writing games, vscode cross-platform, high appearance level, and C++ support is very good, so naturally think of can use it to develop android programs?
Theoretical support
In terms of daily development, I mainly use code jump, project compilation and debugging, UI preview, but we all know that vscode is actually a lightweight code editor, function between ide and text editor, let it support Android development, the most important is to see the plug-in.
Plug in
First, take a document, but only found support for Java, found no support for Android and Kotlin, support for Java can see document code.visualstudio.com/docs/java/j…
The Android plug-in
I mainly installed a few plug-ins
This plugin is used for Android development and debugging. What does it support
Code debugging, variable query, logcat, source query, looks good, but how to compile? The first thing to look at is tasks in VS Code. Tasks in VS Code can be configured to run scripts and start processes so that many existing tools can be used in VS Code without entering command lines or writing new Code. So let’s configure vscode to support the compilation of android projects. Add a tasks.json file to.vscode at the root of the project and add the following code to it.
"Version" : "2.0.0", "tasks" : [{" label ":" run gradle ", "type" : "shell", "command" : "${workspaceFolder}/gradlew", "args": [ "assembleDebug" ], "problemMatcher": [ "$eslint-stylish" ] }, { "label": "gradle debug", "type": "shell", "command": "adb", "args": [ "install", "-t", "${workspaceFolder}/xt-application/build/outputs/apk/debug/xt-application-debug.apk" ], "dependsOn": [ "run gradle" ], "group": { "kind": "build", "isDefault": true }, "problemMatcher": [ "$eslint-stylish" ] }, { "label": "kuafu debug", "type": "shell", "command": "${workspaceFolder}/kuafuconfig.sh", "args": ["/Users/skateboard/AndroidStudioProjects/aquaman_android ", "Debug", "1.4.0", "0"], "problemMatcher" : [ "$eslint-stylish" ], "group": { "kind": "build", "isDefault": true } }, { "label": "clean project", "type": "shell", "command": "${workspaceFolder}/gradlew", "args": [ ":xt-application:clean" ], "problemMatcher": [ "$eslint-stylish" ], "group": { "kind": "build", "isDefault": true } } ] }Copy the code
In this JSON file, each unit in the JSON array represents a task. For example, gradle Debug installs the compiled APK into the mobile phone through ADB, where label stands for the name of the task and type stands for the type of the task. Here is the shell script, where the command represents the shell command executed by the task, where the command is adb, and the args represents the parameters followed by the ADB command. As you can see, it is a JSON array, and each parameter option is a unit. DependsOn represents the “run gradle”task that needs to be executed before this task is executed. This represents the./gradlew assembleDebug compilation we use on the command line. Of course you can customize tasks with this knowledge, as you can see I also defined a Clean Project task, which is for clean Project, called Kuafu DEBUG, which we use for incremental code compilation, using our own plug-in. Vscode tasks look similar to gradle tasks, they are weaker, but simpler to configure. Then open the option bar in the terminal-run Task of VScode and enter the corresponding Task name to execute it. With the plug-in installed before, it is basically enough to use VScode to develop Android. Of course, you may need to debug the code or view logcat. At this point you can either write a custom task or use the functionality provided by the plug-in you just installed by configuring launch.json and adding configuration to it.
"Version" : "0.2.0," "configurations: [{" type" : "android", "request" : "attach", "name" : "Android Attach", "appSrcRoot": "${workspaceRoot}/xt-application/src/main", "adbPort": 5037, "processId": "${command:PickAndroidProcess}" }, { // configuration type, request and name. "launch" is used to deploy the app // to your device and start a debugging session. "type": "android", "request": "launch", "name": "App Build & Launch", "preLaunchTask": "run gradle", "targetDevice": "GDBNW20309000947", // Location of the App source files. This value must point to the root of // your App source tree (containing AndroidManifest.xml). "appSrcRoot": "${workspaceRoot}/xt-application/src/main", // Fully qualified path to the built APK (Android Application Package). "apkFile": "${workspaceFolder}/xt-application/build/outputs/apk/debug/xt-application-debug.apk", // `host:port` configuration for connecting to the ADB (Android Debug Bridge) server instance. // Default: localhost:5037 "adbSocket": "localhost:5037", // Automatically launch 'adb start-server' if not already started. // Default: true "autoStartADB": true, // Launch behaviour if source files have been saved after the APK was built. // One of: [ ignore warn stop ]. Default: warn "staleBuild": "warn", // Fully qualified path to the AndroidManifest.xml file compiled into the APK. // Default: "${appSrcRoot}/AndroidManifest.xml" "manifestFile": "${workspaceRoot}/xt-application/src/main/AndroidManifest.xml", // Custom arguments passed to the Android package manager to install the app. // Run 'adb shell pm' to show valid arguments. Default: ["-r"] "pmInstallArgs": [ "-r" ], // Custom arguments passed to the Android application manager to start the app. // Run `adb shell am` to show valid arguments. // Note that `-D` is required to enable debugging. "amStartArgs": [ "-D", "--activity-brought-to-front", "-a android.intent.action.MAIN", "-c android.intent.category.LAUNCHER", "-n com.***.**t/com.**.**.launch.LaunchActivity" ], // Manually specify the activity to run when the app is started. This option is // mutually exclusive with "amStartArgs". // "launchActivity": "com.kwai.aquaman.launch.LaunchActivity", // Time in milliseconds to wait after launching an app before attempting to attach // the debugger. Default: 1000ms "postLaunchPause": 1000, // Set to true to output debugging logs for diagnostics. "trace": true } ] }Copy the code
The following is my configuration of the demo, because the annotation is very clear, I will not explain, using this configuration can achieve a package installation restart dragon, but also support breakpoint debugging.
Kotlin plugin
Due to the heavy use of Kotlin code in the project, I needed Kotlin code syntax highlighting, incomplete code and jump functions, but the Android plug-in mentioned above did not provide Kotlin support, so I installed the following plug-in.
Although according to its own introduction, it supports defined jumps, incomplete code, etc., but unfortunately, I can not achieve the defined jumps and incomplete code in the actual use.
conclusion
After several attempts, I failed to solve the problem that kotlin’s code has not defined the jump completely. Therefore, I have to give up the idea of using vscode for development.
Follow my official account: “Old Arsenic on skateboards”