Skip to content

Commit a995389

Browse files
committed
add build utils for vscode
1 parent 6855570 commit a995389

File tree

7 files changed

+253
-1
lines changed

7 files changed

+253
-1
lines changed

.vscode/c_cpp_properties.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"version": 4,
3+
"env": {
4+
"myDefaultIncludePath": [
5+
"${workspaceFolder}",
6+
"${workspaceFolder}/library/src/main/jni",
7+
"${workspaceFolder}/library/src/main/jni/cge/common",
8+
"${workspaceFolder}/library/src/main/jni/cge/extends",
9+
"${workspaceFolder}/library/src/main/jni/cge/filters",
10+
"${workspaceFolder}/library/src/main/jni/custom",
11+
"${workspaceFolder}/library/src/main/jni/ffmpeg",
12+
"${workspaceFolder}/library/src/main/jni/interface"
13+
]
14+
},
15+
"configurations": [
16+
{
17+
"name": "default",
18+
"cStandard": "c11",
19+
"cppStandard": "c++17",
20+
"defines": [
21+
"DEBUG=1",
22+
"_CGE_USE_FFMPEG_=1",
23+
"ANDROID_NDK=1",
24+
"_CGE_DISABLE_GLOBALCONTEXT_=1",
25+
"_CGE_ONLY_FILTERS_=1"
26+
],
27+
"includePath": [
28+
"${myDefaultIncludePath}",
29+
"${env:NDK}/ndk-build-toolchain/sysroot/usr/include"
30+
],
31+
"configurationProvider": "ms-vscode.cmake-tools"
32+
}
33+
]
34+
}

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
3+
"cmake.configureArgs": [
4+
],
5+
"files.exclude": {
6+
},
7+
"files.associations": {
8+
}
9+
}

.vscode/tasks.json

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "[Android] Build Android Demo",
8+
"type": "shell",
9+
"command": "bash",
10+
"args": [
11+
"vscode_tasks.sh",
12+
"--build"
13+
],
14+
"options": {
15+
"cwd": "${workspaceFolder}"
16+
},
17+
"group": "build",
18+
"problemMatcher": "$gcc"
19+
},
20+
{
21+
"label": "[Android] Run Android Demo",
22+
"type": "shell",
23+
"command": "bash",
24+
"args": [
25+
"vscode_tasks.sh",
26+
"--build",
27+
"--run"
28+
],
29+
"options": {
30+
"cwd": "${workspaceFolder}"
31+
},
32+
"group": "build",
33+
"problemMatcher": "$gcc"
34+
},
35+
{
36+
"label": "[Android] Build And Run Android Demo",
37+
"type": "shell",
38+
"command": "bash",
39+
"args": [
40+
"-c",
41+
"echo done!"
42+
],
43+
"options": {
44+
"cwd": "${workspaceFolder}"
45+
},
46+
"group": "build",
47+
"problemMatcher": "$gcc",
48+
"dependsOn": [
49+
"[Android] Build Android Demo",
50+
"[Android] Run Android Demo",
51+
]
52+
},
53+
{
54+
"label": "[Android] Build Native Library",
55+
"type": "shell",
56+
"command": "bash",
57+
"args": [
58+
"library/src/main/jni/buildJNI"
59+
],
60+
"options": {
61+
"cwd": "${workspaceFolder}"
62+
},
63+
"group": "build",
64+
"problemMatcher": "$gcc"
65+
}
66+
]
67+
}

cgeDemo/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ android {
44
compileSdkVersion 25
55

66
defaultConfig {
7-
applicationId "org.wysaid.cgedemo"
7+
applicationId "org.wysaid.cgeDemo"
88
minSdkVersion 14
99
targetSdkVersion 22
1010
versionCode 1

run_android_app.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
3+
cd "$(dirname "$0")"
4+
THIS_DIR="$(pwd)"
5+
PROJECT_DIR="$THIS_DIR"
6+
ADB_COMMAND="$PROJECT_DIR/utils/adb_command.sh"
7+
8+
export PACKAGE_NAME="org.wysaid.cgeDemo"
9+
export LAUNCH_ACTIVITY="MainActivity"
10+
GRADLEW_RUN_TASK="installDebug"
11+
12+
function setupProject() {
13+
bash "$PROJECT_DIR/library/src/main/jni/buildJNI"
14+
}
15+
16+
while [[ $# > 0 ]]; do
17+
18+
PARSE_KEY="$1"
19+
20+
case "$PARSE_KEY" in
21+
--build-only)
22+
GRADLEW_RUN_TASK=""
23+
shift
24+
;;
25+
--run-only)
26+
SKIP_GRADLEW_TASKS=true
27+
shift
28+
;;
29+
--rebuild-android-demo)
30+
cd "$PROJECT_DIR" && git clean -ffdx
31+
setupProject
32+
CLEAN_GRADLEW_TASKS=true
33+
GRADLEW_RUN_TASK="${GRADLEW_RUN_TASK} --refresh-dependencies"
34+
shift
35+
;;
36+
--setup-project)
37+
setupProject
38+
exit 0 # setup 的情况下不编译.
39+
;;
40+
*)
41+
echo "Invalid argument $PARSE_KEY..."
42+
shift
43+
;;
44+
esac
45+
46+
done
47+
48+
if [[ ! -f "local.properties" ]]; then
49+
if [[ -n "$ANDROID_SDK_HOME" ]]; then
50+
echo "sdk.dir=$ANDROID_SDK_HOME" >>local.properties
51+
elif [[ -n "$ANDROID_SDK_ROOT" ]]; then
52+
echo "sdk.dir=$ANDROID_SDK_ROOT" >>local.properties
53+
elif [[ -n "$ANDROID_SDK" ]]; then
54+
echo "sdk.dir=$ANDROID_SDK" >>local.properties
55+
fi
56+
fi
57+
58+
if [[ -z "$SKIP_GRADLEW_TASKS" ]]; then
59+
60+
if [[ -n "$CLEAN_GRADLEW_TASKS" ]]; then
61+
./gradlew clean
62+
fi
63+
64+
if ! ./gradlew -p cgeDemo assembleDebug $GRADLEW_RUN_TASK; then
65+
66+
echo "Failed to run..."
67+
echo "Please run the following command and try again:"
68+
echo "---"
69+
echo "$THIS_DIR/run_android_app.sh --setup-project"
70+
echo "---"
71+
setupProject
72+
exit 1
73+
fi
74+
fi
75+
76+
if [[ -n "$GRADLEW_RUN_TASK" ]] || [[ -n $SKIP_GRADLEW_TASKS ]]; then
77+
. "$ADB_COMMAND" -d shell am start -n "$PACKAGE_NAME/$PACKAGE_NAME.$LAUNCH_ACTIVITY" &&
78+
. "$ADB_COMMAND" -d logcat | grep -iE "(cge|demo|wysaid)"
79+
else
80+
echo "apk generated at:"
81+
find "$THIS_DIR/cgeDemo/build" -iname "*.apk"
82+
fi

utils/adb_command.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
if ! command -v adb &>/dev/null; then
4+
5+
if [[ -n "$ANDROID_SDK_HOME" ]]; then
6+
export PATH=$PATH:$ANDROID_SDK_HOME/platform-tools
7+
elif [[ -n "$ANDROID_SDK_ROOT" ]]; then
8+
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools
9+
fi
10+
11+
if ! command -v adb &>/dev/null; then
12+
echo "can't find adb!'"
13+
exit 1
14+
fi
15+
fi
16+
17+
if [[ $# -gt 0 ]]; then
18+
adb $@
19+
else
20+
command -v adb
21+
fi

vscode_tasks.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
3+
THIS_DIR="$(dirname $0)"
4+
cd $THIS_DIR
5+
PROJECT_DIR=$(pwd)
6+
7+
if [[ $# -eq 0 ]]; then
8+
echo "usage: [--clean] [--build] [--run]"
9+
fi
10+
11+
while [[ $# > 0 ]]; do
12+
13+
PARSE_KEY="$1"
14+
15+
case "$PARSE_KEY" in
16+
--clean)
17+
echo "clean"
18+
19+
shift # past argument
20+
;;
21+
--build)
22+
echo "build"
23+
bash "$PROJECT_DIR/library/src/main/jni/buildJNI"
24+
. "$PROJECT_DIR/run_android_app.sh" --build-only
25+
shift # past argument
26+
;;
27+
--run)
28+
echo "run android demo"
29+
. "$PROJECT_DIR/run_android_app.sh"
30+
shift # past argument
31+
;;
32+
*)
33+
echo "unknown option $PARSE_KEY..."
34+
exit 1
35+
;;
36+
37+
esac
38+
39+
done

0 commit comments

Comments
 (0)