-
Notifications
You must be signed in to change notification settings - Fork 40
/
create-android-project
executable file
·73 lines (51 loc) · 2.47 KB
/
create-android-project
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
set -e
function die() {
echo "$1" 1>&2
exit 1
}
IOS_PROJECT_DIR=${IOS_PROJECT_DIR:-.}
SCRIPT_PATH=`dirname $0`
TEMPLATE_PATH=${SCRIPT_PATH}/samples/getting-started
[[ ! -d "${IOS_PROJECT_DIR}/android" ]] \
|| die "The directory '${IOS_PROJECT_DIR}/android' already exists. Remove it and try again."
BUNDLE_IDENTIFIER=`grep -m 1 PRODUCT_BUNDLE_IDENTIFIER ${IOS_PROJECT_DIR}/*.xcodeproj/project.pbxproj | xargs | cut -d ' ' -f 3 | sed 's~;~~g'`
[[ $BUNDLE_IDENTIFIER ]] || die "your current working directory doesn't seem to be an xcode project"
APP_NAME=${BUNDLE_IDENTIFIER##*.}
PACKAGE=${BUNDLE_IDENTIFIER%.*}
echo "Found iOS Target '${PACKAGE}.${APP_NAME}'"
echo
# We assume the iOS dir equals the project name
TARGET_SOURCES_DIRECTORY=${IOS_PROJECT_DIR}/${APP_NAME}
echo "Creating ${IOS_PROJECT_DIR}/CMakeLists.txt"
cp "${TEMPLATE_PATH}/CMakeLists.txt" .
echo "Creating ${TARGET_SOURCES_DIRECTORY}/androidMain.swift with UIApplicationDelegate class 'AppDelegate'"
cp "${TEMPLATE_PATH}/DemoApp/androidMain.swift" "$TARGET_SOURCES_DIRECTORY"/
cp -R "${TEMPLATE_PATH}/android" .
rm -rf ${IOS_PROJECT_DIR}/android/{.idea,.gradle,build,android.iml,app/{.externalNativeBuild,build}}
PACKAGE_WITH_FORWARDSLASHES=${PACKAGE/.//} # e.g. com/example/DemoApp
rm -rf ${IOS_PROJECT_DIR}/android/app/src/main/java/
mkdir -p "${IOS_PROJECT_DIR}/android/app/src/main/java/${PACKAGE_WITH_FORWARDSLASHES}"
PATH_TO_MAIN_ACTIVITY="${TEMPLATE_PATH}/android/app/src/main/java/com/example/MainActivity.kt"
cp $PATH_TO_MAIN_ACTIVITY "${IOS_PROJECT_DIR}/android/app/src/main/java/${PACKAGE_WITH_FORWARDSLASHES}"
echo "Creating Android project at '${IOS_PROJECT_DIR}/android'"
FILES_TO_CHANGE=(
"CMakeLists.txt"
"android/app/build.gradle"
"android/app/src/main/AndroidManifest.xml"
"android/app/CMakeLists.txt"
"android/app/src/main/java/${PACKAGE_WITH_FORWARDSLASHES}/MainActivity.kt"
)
for file in ${IOS_PROJECT_DIR}/${FILES_TO_CHANGE[@]}
do
sed -i '' "s~DemoApp~${APP_NAME}~g" $file
sed -i '' "s~com.example~${PACKAGE}~g" $file
done
# adjust path to UIKit
sed -i '' "s~../../../~../UIKit/~g" ${IOS_PROJECT_DIR}/android/settings.gradle
sed -i '' "s~../../~./UIKit/~g" ${IOS_PROJECT_DIR}/CMakeLists.txt
sed -i '' "s~../../../../~../../UIKit/~g" ${IOS_PROJECT_DIR}/android/app/CMakeLists.txt
PACKAGE_WITH_UNDERSCORES=${PACKAGE/./_} # e.g. com_example_DemoApp
sed -i '' "s~com_example~${PACKAGE_WITH_UNDERSCORES}~g" ${TARGET_SOURCES_DIRECTORY}/androidMain.swift
echo
echo "Done."