android-dev-ext icon indicating copy to clipboard operation
android-dev-ext copied to clipboard

Launch task not waiting for build to finish

Open puchm opened this issue 3 years ago • 0 comments

Hi,

I have the problem that when I make changes to my app and restart it, I always need to do it twice. I found that the gradle build actually still runs when the app launches on my phone so what I think is happening is that it launches an old version of the app. When I restart again it has all the recent changes.

Here are my files: launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "android",
            "request": "launch",
            "name": "Android launch",
            "appSrcRoot": "${workspaceRoot}/app-android/app/src/main",
            "apkFile": "${workspaceRoot}/app-android/app/build/outputs/apk/debug/app-debug.apk",
            "adbPort": 5037,
            "preLaunchTask": "run gradle"
        },
        {
            "type": "android",
            "request": "attach",
            "name": "Android attach",
            "appSrcRoot": "${workspaceRoot}/app-android/app/src/main",
            "adbPort": 5037,
            "processId": "${command:PickAndroidProcess}"
        }
    ]
}

tasks.json

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

Since I am running the task from a different folder than where the gradlew file is in I needed to specify --project-dir since it didn't find assembleDebug otherwise. I also changed the paths at all places where it was necessary because of the same reason (I added /app-android).

What can I do to only have to restart once? Also, is there a way to watch for changes and automatically restart the app?

Thank you for your help in advance!

-Moritz

puchm avatar Feb 17 '21 16:02 puchm