-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreate-container-app.sh
95 lines (67 loc) · 2.49 KB
/
create-container-app.sh
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/sh
#The script takes the apk as input
APK_FULL_PATH=$1.apk
NEW_PACKAGE_NAME=$2
UNZIPPED_APK_FOLDER=$1
BASE_CONTAINER=./base-container
if [ ! -f $APK_FULL_PATH ]; then
echo "Error: The apk file does not exist!"
fi
#Get the name of the APK
IFS='/' read -r -a array <<< "$1"
APK_NAME=${array[${#array[@]}-1]}
echo $APK_NAME
#Unzip the APK file
echo 'Unzip the apk file'
apktool d $APK_FULL_PATH -o $UNZIPPED_APK_FOLDER
#Copy the BaseContainer app
START=$(date +%s)
if [ ! -d ./containers ]; then
mkdir ./containers
fi
echo 'Create the folder for the container app'
CONTAINER_FOLDER=./containers/$APK_NAME
mkdir $CONTAINER_FOLDER
cp -r $BASE_CONTAINER/* $CONTAINER_FOLDER/
#Create local.properties file with the path to the SDK
#Infer SDK path from adb command first
SDK_PATH_ADB=$(which adb)
SDK_PATH_ADB=${SDK_PATH_ADB%"/platform-tools/adb"}
read -p "Please enter the path to your Android SDK [$SDK_PATH_ADB]: " SDK_PATH
SDK_PATH=${SDK_PATH:-$SDK_PATH_ADB}
touch $CONTAINER_FOLDER/local.properties
echo "sdk.dir=$SDK_PATH" > $CONTAINER_FOLDER/local.properties
#Replace the Manifest file in DroidPlugin lib
echo 'Create Manifest file for DroidPlugin'
CONTAINER_MANIFEST=$CONTAINER_FOLDER/DroidPlugin/AndroidManifest.xml
APK_MANIFEST=$UNZIPPED_APK_FOLDER/AndroidManifest.xml
if [ -f AndroidManifest.xml ]; then
rm AndroidManifest.xml
fi
python2 ./manifest-stubs/create_new_manifest.py $APK_MANIFEST $CONTAINER_MANIFEST AndroidManifest.xml
cp -f AndroidManifest.xml $CONTAINER_MANIFEST
rm AndroidManifest.xml
python2 ./manifest-stubs/create_stubs_java.py $CONTAINER_MANIFEST
python2 ./manifest-stubs/create_service_stubs_java.py $CONTAINER_MANIFEST
#Copy the apk to the asset
if [ ! -d $CONTAINER_FOLDER/app/src/main/assets ]; then
mkdir $CONTAINER_FOLDER/app/src/main/assets
fi
cp $APK_FULL_PATH $CONTAINER_FOLDER/app/src/main/assets/target.apk
if [ -d $UNZIPPED_APK_FOLDER/assets ]; then
cp -r $UNZIPPED_APK_FOLDER/assets/* $CONTAINER_FOLDER/app/src/main/assets
fi
python2 ./manifest-stubs/handle_package_name.py $CONTAINER_FOLDER $NEW_PACKAGE_NAME
rm $CONTAINER_FOLDER/app/src/main/java/org/hma/hma_app1/*.java
echo 'Compiling the container app'
cd $CONTAINER_FOLDER
#./gradlew --stop
sh gradlew assembleDebug
cd ../../
if [ ! -f $CONTAINER_FOLDER/app/build/outputs/apk/app-debug.apk ]; then
echo "APK file does not exist!"
fi
cp $CONTAINER_FOLDER/app/build/outputs/apk/app-debug.apk HMA-apps/$NEW_PACKAGE_NAME.apk
END=$(date +%s);
echo 'Remove the unzipped apk folder'
rm -r $UNZIPPED_APK_FOLDER