Skip to content

Commit 0328b4b

Browse files
committed
support run vscode tasks in Windows.
1 parent 5415e16 commit 0328b4b

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

.vscode/tasks.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@
122122
"group": "build",
123123
"problemMatcher": "$gcc"
124124
},
125+
{
126+
"label": "Setup Gradle Project",
127+
"type": "shell",
128+
"command": "bash",
129+
"args": [
130+
"vscode_tasks.sh",
131+
"--setup-project"
132+
],
133+
"options": {
134+
"cwd": "${workspaceFolder}"
135+
},
136+
"group": "build",
137+
"problemMatcher": "$gcc"
138+
},
125139
{
126140
"label": "[Debug] Enable CMake And Build Project With CMake",
127141
"type": "shell",

vscode_tasks.sh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,23 @@ export LAUNCH_ACTIVITY="MainActivity"
1414
export GRADLEW_RUN_TASK="installDebug"
1515
export ANDROID_BUILD_TYPE="assembleDebug"
1616

17+
if ! command -v cmd &>/dev/null && [[ -f "/mnt/c/Windows/system32/cmd.exe" ]]; then
18+
function cmd() {
19+
/mnt/c/Windows/system32/cmd.exe $@
20+
}
21+
fi
22+
23+
function runGradleCommand() {
24+
if ! ./gradlew $@; then
25+
command -v cmd &>/dev/null && cmd /C gradlew $@
26+
fi
27+
}
28+
1729
function setupProject() {
1830
if [[ -f "$PROJECT_DIR/local.properties" ]] && grep -E '^usingCMakeCompile=true' "$PROJECT_DIR/local.properties"; then
1931
echo "Using cmake, skip ndk build..."
2032
else
21-
bash "$PROJECT_DIR/library/src/main/jni/buildJNI"
33+
bash "$PROJECT_DIR/library/src/main/jni/buildJNI" || exit 1
2234
fi
2335
}
2436

@@ -44,11 +56,11 @@ function runAndroidApp() {
4456
}
4557

4658
function cleanProject() {
47-
./gradlew clean --refresh-dependencies
59+
runGradleCommand clean --refresh-dependencies
4860
}
4961

5062
function buildProject() {
51-
if ! ./gradlew -p cgeDemo "$ANDROID_BUILD_TYPE"; then
63+
if ! runGradleCommand -p cgeDemo "$ANDROID_BUILD_TYPE"; then
5264

5365
echo "Failed to run: ./gradlew -p cgeDemo $ANDROID_BUILD_TYPE"
5466
echo "Please run the following command and try again:"
@@ -66,7 +78,7 @@ function buildProject() {
6678
# release can not be installed directly. do adb install.
6779
. "$ADB_COMMAND" -d install "$GENERATED_APK_FILE"
6880
else
69-
if ! ./gradlew -p cgeDemo "$GRADLEW_RUN_TASK"; then
81+
if ! runGradleCommand -p cgeDemo "$GRADLEW_RUN_TASK"; then
7082
echo "Install failed." >&2
7183
fi
7284
fi
@@ -131,7 +143,8 @@ while [[ $# > 0 ]]; do
131143
;;
132144
--setup-project)
133145
setupProject
134-
exit 0 # setup 的情况下不编译.
146+
runGradleCommand signingReport
147+
exit 0 # setup then stop.
135148
;;
136149
--clean)
137150
echo "clean"

0 commit comments

Comments
 (0)