Giter Site home page Giter Site logo

adelphes / android-dev-ext Goto Github PK

View Code? Open in Web Editor NEW
203.0 11.0 28.0 12.26 MB

Android debugging support for VS Code

Home Page: https://marketplace.visualstudio.com/items?itemName=adelphes.android-dev-ext

License: MIT License

JavaScript 98.40% HTML 1.60%
android vscode vscode-extension debugger

android-dev-ext's Introduction

Android for VS Code

This is a preview version of the Android for VS Code Extension. The extension allows developers to install, launch and debug Android Apps from within the VS Code environment.

What's New

  • Java Intellisense for Android is now in beta.

Features

  • Line by line code stepping
  • Breakpoints
  • Variable inspection and modification
  • Logcat viewing [ Command Palette -> Android: View Logcat ]
  • Break on exceptions
  • Step through Android sources

Requirements

You must have Android SDK Platform Tools installed. This extension communicates with your device via the ADB (Android Debug Bridge) interface.

You are not required to have Android Studio installed - if you have Android Studio installed, make sure there are no active instances of it when using this extension or you may run into problems with ADB.

Limitations

  • This is a preview version so expect the unexpected. Please log any issues you find on GitHub.
  • This extension will not build your app.
    If you use gradle (or Android Studio), you can build your app from the command-line using ./gradlew assembleDebug or configure a VSCode Build Task to run the command (see below).

You must use gradle or some other build procedure to create your APK. Once built, the extension can deploy and launch your app, allowing you to debug it in the normal way. See the section below on how to configure a VSCode Task to automatically build your app before launching a debug session.

  • Some debugger options are yet to be implemented. You cannot set conditional breakpoints and watch expressions must be simple variables.
  • If you require a must-have feature that isn't there yet, let us know on GitHub.

Extension Settings

This extension allows you to debug your App by creating a new Android configuration in launch.json.
The following settings are used to configure the debugger:

    {
        "version": "0.2.0",
        "configurations": [
            {
                // 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": "Launch App",

                // Location of the App source files. This value must point to the root of
                // your App source tree (containing AndroidManifest.xml).
                "appSrcRoot": "${workspaceRoot}/app/src/main",

                // Fully qualified path to the built APK (Android Application Package).
                "apkFile": "${workspaceRoot}/app/build/outputs/apk/app-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",

                // Target Device ID (as indicated by 'adb devices').
                // Use this to specify which device is used for deployment
                // when multiple devices are connected.
                "targetDevice": "",

                // Fully qualified path to the AndroidManifest.xml file compiled into the APK.
                // Default: "${appSrcRoot}/AndroidManifest.xml"
                "manifestFile": "${workspaceRoot}/app/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 package.name/launch.activity"
                ],

                // Manually specify the activity to run when the app is started. This option is
                // mutually exclusive with "amStartArgs".
                "launchActivity": ".MainActivity",

                // 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": false
            }
        ]
    }

Building your app automatically

This extension will not build your App. If you would like to run a build each time a debug session is started, you can add a preLaunchTask option to your launch.json configuration which invokes a build task.

.vscode/launch.json

Add a preLaunchTask item to the launch configuration:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "android",
            "request": "launch",
            "name": "App Build & Launch",
            "preLaunchTask": "run gradle",
            ...
        }
    ]
}

Add a new task to run the build command:

.vscode/tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "run gradle",
            "type": "shell",
            "command": "${workspaceFolder}/gradlew",
            "args": [
                "assembleDebug"
            ],
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": false
            },
            "problemMatcher": [],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

Java Intellisense

Support for Java Intellisense is currently in beta, so any feedback is appreciated.

To use Java intellisense, make sure the option is enabled in Settings (Extensions > Android > Enable Java language support for Android) and press ctrl/cmd-space when editing a Java source file.

You can read more about using code-completion on the VSCode website and how to configure code-completion to suit your Android project in the wiki.

Java Intellisense

Expression evaluation

Format specifiers can be appended to watch and repl expressions to change how the evaluated result is displayed. The specifiers work with the same syntax used in Visual Studio. See https://docs.microsoft.com/en-us/visualstudio/debugger/format-specifiers-in-cpp for examples.

123              123
123,x            0x0000007b
123,xb           0000007b
123,X            0x0000007B
123,o            000000000173
123,b            0b00000000000000000000000001111011
123,bb           00000000000000000000000001111011
123,c            '{'
"one\ntwo"       "one\ntwo"
"one\ntwo",sb    one\ntwo
"one\ntwo",!     one
                 two

You can also apply the specifiers to object and array instances to format fields and elements:

arr,x            int[3]
   [0]           0x00000001
   [1]           0x00000002
   [1]           0x00000003

Note: Format specifiers for floating point values (e/g) and string encoding conversions (s8/su/s32) are not supported.

Powered by coffee

The Android Developer Extension is a completely free, fully open-source project. If you've found the extension useful, you can support it by buying me a coffee.

If you use ApplePay or Google Pay, you can scan the code with your phone camera:

BuyMeACoffee Code

Every coffee makes a difference, so thanks for adding your support.

Questions / Problems

If you run into any problems, tell us on GitHub or contact me on Twitter.

Launch Android App

android-dev-ext's People

Contributors

adelphes avatar dependabot[bot] avatar fancypantalons avatar lbhnrg2021 avatar nathmcbride avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-dev-ext's Issues

What does the extension do with the APK?

Typically with my code, I compile the APK, then use adb push to send it to /system/priv-app. Since I started using this extension I'm having weird behavior, where my changes aren't reflected in the app if I push the APK manually, only if I push it using this extension. So it seems like however the extension is installing the APK is giving it higher priority than the copy in /system/priv-app.

What does this extension do with the APK, and how can I remove it from the device?

Filter installation on incompatible device APIs

Currently, the debugger allows an App to be deployed onto any device, regardless of the API level. If an app is deployed to a device with an API lower than the minimum required by the app, the installation fails.

Now that the launch routine knows the device API before deployment, we should check it against the App's API level and give an appropriate message.

We could also filter connected devices, ignoring those whose API is not compatible (rather than requiring the user to always choose a target device.)

[Feature Request] Debugger Support - Kotlin

First off this is a really cool extension and I am now able to use VS Code to run and deploy my android apps.

We are using kotlin for our Android project and it appears there isn't debugger support for kotlin in VS Code. According to #19 this extension hooks into the JDWP which is the protocol for debugging java classes.

Feature Request
Do you plan to support kotlin debugging and what is your timeline for that if you do?

How to debug native applications?

Hi guys,

I was wondering whether this plugin is capable of debugging native applications through VS.

I have an app and I generate the manifest and the whole directory tree through a python script (no gradle, purely javac). This means that my source files, the *.c files, are kept separated from this tree. Now, when I hit the debug button, the application correctly boots up on my device, but I don't seem to be able to hit the breakpoints in the native code, in fact, they grey out as soon as the debugger starts. Moreover, and I don't know whether this is relevant or not, on the screen of my mobile phone a popup shows up saying the application is waiting for the debugger to be attached. After a few moments it goes away, so I guess, the debugger is properly attached.

Any suggestion?

Live code editing

Investigate possibility of editing code and deploying changes to the running app without requiring a new build.

Launch failed

After adding Launch configuration as below

{

"version": "0.2.0",
"configurations": [
{
    "type": "android",
    "request": "launch",
    "name": "Launch App",
    "appSrcRoot": "${workspaceRoot}",
    "apkFile": "${workspaceRoot}/build/outputs/apk/android-debug.apk",
    "adbPort": 5037
}
]

}

I faced the following error

Checking build
Warning: Build is not up-to-date. Source files may not match execution when debugging.
Searching for devices...
Found 1 device
Current build already installed
Launching com.dev.test.android/MainActivity on device TA38502I37 [API:23]
Launch failed: Error: Activity class {com.dev.test.android/MainActivity} does not exist.

Please correct me, if I am missing anything?

Java language service does not work

Hey guys. Is there a way to get the Java extension to see the dependencies on my android project? I use VSCode for Java development but for some reason it does not seem to work for Android projects. Thank you

'rs error wrong parameters' shown after adb restart

Launch fails on the first attempt after (re)starting adb. The error message rs error wrong parameters appears in the console.
Reproduction steps:

  1. Kill adb (adb kill-server)
  2. Attempt a launch - fails (correctly)
  3. Restart adb (adb start-server)
  4. Attempt a launch - fails with rs error wrong parameters
  5. Attempt a launch (again) - succeeds.

breakpoints dont work in chromium android webview code

Hi Dave.
I am using your androud vscode plugin and it looks very promising. Currently I am trying to debug webview app from chroumium project. I build a debug version of AndroidWebView.apk without optimizations and set up your plugin. It starts activity on the device and shows thread list, but breakpoints show error "breakpoint location is not valid".
Gdb debugger attaches to this process and breakpoints work from command line.

What could be the reason and is it possible to enable breakpoints in vscode?

Allow product flavors

Hi. I have an AndroidStudio project with product flavors defined in the gradle file for staging and production environments. Each flavor defines its own applicationId.

I have the args defined with 'assembleStagingDebug' in tasks.json so it can gradlew with the selected flavor profile.

When the debugger is trying to launch the MainActivity, it uses the defaultConfig applicationId/packageName to search for it.
It ends with the error "Launch failed: Error: Activity class {(packageName)/(MainActivity)} does not exist."

I can see the source code uses the command to launch activity 'am start' with the 'this.session.build.pkgname'.
Is it possible to have a launch configuration to specify the pkgname or any other way of searching the correct package of the flavor used?

Launch failed: Error: Activity class {MainActivity} does not exist.

I work with ionic 3, so when I launch my app I get the next message:
Checking build
Searching for devices...
Found 1 device
Current build already installed
Launching io.ionic.starter/MainActivity on device 6XT4C17609001962 [API:26]
Launch failed: Error: Activity class {io.ionic.starter/MainActivity} does not exist.

Any solution?

specify Launch-activity in launch.json

I don't have a launch activity in the Manifest (and won't add one, because it normally runs as a service). I use an Activity for debugging to launch the App and used to do it in Android Studio with specifying a launch configuration.
Reading the error output Launch failed: No valid launch activity found in AndroidManifest.xml or launch.json indicates I could do the same, but how to I set it? At least the auto-suggestions did not suggest a suitable attribute.

Logcat is not shown

using vscode insiders-1.37.0 doesn't show logcat. the error description is:

[renderer1] [error] command 'vscode.previewHtml' not found: Error: command vscode.previewHtml' not found at Proxy._tryExecuteCommand 

I looked it up and it seems that it's deprecated in the newer vscode releases.
is there a workaround on this ?

Thank you

Launch failed: Cannot read property 'connection' of null

{
"version": "0.2.0",
"configurations": [
{
"type": "android",
"name": "Android Debug",
"request": "launch",
"appSrcRoot": "${workspaceRoot}/app/src/main",
"apkFile": "${workspaceRoot}/app/build/outputs/apk/debug/app-debug.apk",
"adbPort": 5037
}
]
}

Checking build
Warning: Build is not up-to-date. Source files may not match execution when debugging.
Searching for devices...
Found 1 device
Current build already installed
Launching js.j2v8/.MainActivity on device emulator-5554 [API:27]
Launch failed: Cannot read property 'connection' of null
Debugger disconnected

Update node dependencies

added 379 packages from 895 contributors and audited 1261 packages in 8.285s
found 3 vulnerabilities (1 low, 1 high, 1 critical)
run npm audit fix to fix them, or npm audit for details
$ npm audit

                   === npm audit security report ===

Run npm install --save-dev [email protected] to resolve 3 vulnerabilities

SEMVER WARNING: Recommended action is a potentially breaking change
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High │ Regular Expression Denial of Service │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ minimatch │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ mocha [dev] │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ mocha > glob > minimatch │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://nodesecurity.io/advisories/118
└───────────────┴──────────────────────────────────────────────────────────────┘

┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low │ Regular Expression Denial of Service │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ debug │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ mocha [dev] │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ mocha > debug │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://nodesecurity.io/advisories/534
└───────────────┴──────────────────────────────────────────────────────────────┘

┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Critical │ Command Injection │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ growl │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ mocha [dev] │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ mocha > growl │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://nodesecurity.io/advisories/146
└───────────────┴──────────────────────────────────────────────────────────────┘

found 3 vulnerabilities (1 low, 1 high, 1 critical) in 1261 scanned packages
3 vulnerabilities require semver-major dependency updates.

AndroidViewLogcat

Is it possible to make this option only log the current apk in the configuration ?
I mean it should do something like
adb logcat | findstr in.asdjsad.myremote.app

or maybe add another Android view to display on the current apk specified in the config file

Automatically build

Would it be possible to add the feature to automatically build the apk. It is very annoying that I have to go into the console to build and the run the app.

Update default APK build path

For newer AndroidStudio projects, the build path to the APK now includes the configuration.

.../app/build/outputs/apk/app-debug.apk

is now

.../app/build/outputs/apk/debug/app-debug.apk

Doesn't work with VSCode 1.33

Updating to VSCode 1.33 broke the ability to set breakpoints, anytime I try the breakpoint comes up grey and hovering on it says that the location is not valid. Reverting my VSCode installation to 1.32.3 made it work again.

pm install -t option

For our project I had to edit debugMain.js at line 404 to add '-t' to the pm install command. I'm not sure if there are any downsides to always having that flag set, but would it be possible to either add it permanently, or have it as an option in the configuration?

Extract package name from APK during deployment

The package name passed to am is currently extracted from the AndroidManifest.xml file, but is also embedded in the apk. In our case these do not match (there are some extra .XXX bits added). As a temporary workaround I added 'apkPackage' to the configuration options, but it would be better to read it from the apk.
AAPT can display the package name, and probably everything else you're currently reading from the manifest, but I imagine you'd prefer not to be dependent on that executable. AFAIK the information is stored in an embedded AndroidManifest.xml as a binary XML file within the APK. Not sure if there are js modules that can read that?

App terminates when stepping through an exception

  1. Enable All Exceptions
  2. Set a breakpoint within a try block
  3. Step through statements until an exception is thrown
  4. Try to step again - the App terminates and the debugger disconnects.

This seems to be because the step event is still pending when the exception break happens - and attempting to step again causes the device-side debugger to crash.

breakpoints don't work on jni layer

hi, I follow the instructions and I can debug my android studio app in the VS code. But I need to debug my .cpp files that they are in the jni layer. Can anybody help me?

Allow multi-device deployments

The debugger only permits deployment to a single device. If multiple devices are connected, a target device must be chosen in launch.json.

A nice option would be to allow the built app to be simultaneously deployed to all (or a selection) of connected devices, but only to debug on one of them.

Build apk

Building apk is already done for flutter/dart vs code extension. So it could be probably copied from there or done similar. Of course this could be optional. But most users probably want to build app before debugging.

Object instances cannot be modified in locals

Object instances are displayed as an expandable section when evaluated in locals, watches, etc.
There's no (simple) way of setting Object instances to null or updating them with a new instance.

Currently, only the fields of each Object instance can be modified.

Add a license

The license field in your package.json file says that this project is MIT licensed. However, there is no license file in the root directory of this repository.

Debug starts but dies on splash activity

Hi! I'm very interested in using your debugger. Look quite good. I've successfuly connected to ADB, setup the apk file through the launch.json file and so. The thing is that when I press F5 I have the following output in the cosole:

Checking buildSearching for devices...
Found 1
deviceDeploying current build...
Installing...
Launching com.aviron.pasajeros/.splash.SplashActivity on device 192.168.189.101:5555 [API:16]
Device disconnected

Those lines are shown alltogether but that's not an issue right now. The thing is that after launching the app the debugging process dies and so the app.

Maybe I'm doing something wrong.

My context is:

  • Windows 10 64 bits.
  • AMD processor
  • Running with Genymotion

Thanks in advance

Logcat filtering

Need to add filtering to logcat - regular expressions?
Also need a logcat-clear command.

Debugger reports other threads running when breakpoint hit

When a breakpoint is hit, the active thread is marked as paused and the call stack displayed - the other threads are marked as still running. This is incorrect - the debugger actually stops all threads.

This is apparent when a new thread is started and a breakpoint hit within it - the debugger shows the thread as paused, but the main UI thread is clearly paused too.

Improve expression parsing

Currently, watches and evaluations only support simple variables, object instance fields and array elements.

Need to add:

  • Arithmetic, relational and logic operators
  • Type casts
  • Method calls
  • Static fields (using type names, not instance variables)
  • Class types (e.g Object.class)

Debugger does not detect terminated app on emulator

  1. Launch App (with later API classes) on an emulator instance
  2. App is successfully deployed and started
  3. App immediately terminates (due to missing - newer API - classes)
  4. Debugger still reports app is running

Unable to view Logcat

Hi, thanks a lot for the extension, it's great to have some alternative to Android Studio. I've just installed it on VS Code 1.29.1, but when I try to open logcat I get the following error:

command 'android-dev-ext.view_logcat' not found

Does this look like a bug or is it something I'm missing?

Cheers!

Attaching debugger to running process

Is there any way to attach the debugger to an existing process? Specifically, I'm using flutter and I'd like to attach to a plugin running in my app.

Waiting for Debugger

Hi! I used gradle to build the android project and tried to run the google map activity sample from android studio on vscode, with the automatically generated configuration. I ran into the problem that on my apk emulator device, it is telling me that it is "Waiting for the debugger". I could not find any similar problem shown up using the vscode extension.
image
Thus, I am here to see if anyone have run into this before.

Remove ADB dependency

The only mandatory requirement for the debugger is the ADB service, present in the Android SDK Platform Tools. This could be replaced with an internal version meaning the Android SDK would not be required.

Note that until we build it ourselves, gradle or some other tools are still a required dependency to build the app.

Build is not up-to-date is always reported

When attempting to launch a debug session with staleBuilds configuration set to stop, the app is never deployed. The console reports:

Checking build
Launch failed: Build is not up-to-date

Even after a successful rebuild of the App, this message persists.

Support Kotlin debugging

I'm not able to set breakpoints in Kotlin files within vs code, presumably because this extension does not yet support Kotlin debugging

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.