Winson | 9947f1e | 2019-08-16 10:20:39 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright (C) 2019 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | aapt2=$1 |
| 17 | soong_zip=$2 |
| 18 | genDir=$3 |
| 19 | FRAMEWORK_RES_APK=$4 |
| 20 | inDir=$5 |
| 21 | |
| 22 | # (String name, boolean retainFiles = false, String... files) |
| 23 | function compileAndLink { |
| 24 | moduleName=$1 |
| 25 | mkdir "$genDir"/out/"$moduleName" |
| 26 | |
| 27 | args="" |
| 28 | for arg in "${@:4}"; do |
| 29 | if [[ $arg == res* ]]; then |
| 30 | args="$args $inDir/$arg" |
| 31 | else |
| 32 | args="$args $arg" |
| 33 | fi |
| 34 | done |
| 35 | |
| 36 | $aapt2 compile -o "$genDir"/out/"$moduleName" $args |
| 37 | |
| 38 | $aapt2 link \ |
| 39 | -I "$FRAMEWORK_RES_APK" \ |
| 40 | --manifest "$inDir"/"$3" \ |
| 41 | -o "$genDir"/out/"$moduleName"/apk.apk \ |
| 42 | "$genDir"/out/"$moduleName"/*.flat \ |
| 43 | --no-compress |
| 44 | |
| 45 | unzip -qq "$genDir"/out/"$moduleName"/apk.apk -d "$genDir"/out/"$moduleName"/unzip |
| 46 | |
| 47 | if [[ "$2" == "APK_WITHOUT_FILE" || "$2" == "BOTH_WITHOUT_FILE" ]]; then |
| 48 | zip -q -d "$genDir"/out/"$moduleName"/apk.apk "res/*" |
| 49 | cp "$genDir"/out/"$moduleName"/apk.apk "$genDir"/output/raw/"$moduleName"Apk.apk |
| 50 | elif [[ "$2" == "APK" || "$2" == "BOTH" ]]; then |
| 51 | cp "$genDir"/out/"$moduleName"/apk.apk "$genDir"/output/raw/"$moduleName"Apk.apk |
| 52 | fi |
| 53 | |
| 54 | if [[ "$2" == "ARSC" || "$2" == "BOTH" || "$2" == "BOTH_WITHOUT_FILE" ]]; then |
| 55 | zip -d "$genDir"/out/"$moduleName"/apk.apk "res/*" |
| 56 | cp "$genDir"/out/"$moduleName"/unzip/resources.arsc "$genDir"/output/raw/"$moduleName"Arsc.arsc |
| 57 | fi |
| 58 | } |
| 59 | |
| 60 | rm -r "$genDir"/out |
| 61 | rm -r "$genDir"/output |
| 62 | rm -r "$genDir"/temp |
| 63 | |
| 64 | mkdir "$genDir"/out |
| 65 | mkdir -p "$genDir"/output/raw |
| 66 | mkdir -p "$genDir"/temp/res/drawable-nodpi |
| 67 | mkdir -p "$genDir"/temp/res/layout |
| 68 | |
| 69 | compileAndLink stringOne BOTH AndroidManifestFramework.xml res/values/string_one.xml |
| 70 | compileAndLink stringTwo BOTH AndroidManifestFramework.xml res/values/string_two.xml |
| 71 | |
| 72 | compileAndLink dimenOne BOTH AndroidManifestFramework.xml res/values/dimen_one.xml |
| 73 | compileAndLink dimenTwo BOTH AndroidManifestFramework.xml res/values/dimen_two.xml |
| 74 | |
| 75 | compileAndLink drawableMdpiWithoutFile BOTH_WITHOUT_FILE AndroidManifestFramework.xml res/values/drawable_one.xml res/drawable-mdpi/ic_delete.png |
| 76 | compileAndLink drawableMdpiWithFile APK AndroidManifestFramework.xml res/values/drawable_one.xml res/drawable-mdpi/ic_delete.png |
| 77 | |
| 78 | compileAndLink layoutWithoutFile BOTH_WITHOUT_FILE AndroidManifestFramework.xml res/values/activity_list_item_id.xml res/layout/activity_list_item.xml |
| 79 | compileAndLink layoutWithFile APK AndroidManifestFramework.xml res/values/activity_list_item_id.xml res/layout/activity_list_item.xml |
| 80 | |
| 81 | cp -f "$inDir"/res/layout/layout_one.xml "$genDir"/temp/res/layout/layout.xml |
| 82 | compileAndLink layoutOne ARSC AndroidManifestApp.xml "$genDir"/temp/res/layout/layout.xml res/values/layout_id.xml |
| 83 | cp -f "$genDir"/out/layoutOne/unzip/res/layout/layout.xml "$genDir"/output/raw/layoutOne.xml |
| 84 | |
| 85 | cp -f "$inDir"/res/layout/layout_two.xml "$genDir"/temp/res/layout/layout.xml |
| 86 | compileAndLink layoutTwo ARSC AndroidManifestApp.xml "$genDir"/temp/res/layout/layout.xml res/values/layout_id.xml |
| 87 | cp -f "$genDir"/out/layoutTwo/unzip/res/layout/layout.xml "$genDir"/output/raw/layoutTwo.xml |
| 88 | |
| 89 | drawableNoDpi="/res/drawable-nodpi" |
| 90 | inDirDrawableNoDpi="$inDir$drawableNoDpi" |
| 91 | |
| 92 | cp -f "$inDirDrawableNoDpi"/nonAssetDrawableOne.xml "$genDir"/temp/res/drawable-nodpi/non_asset_drawable.xml |
| 93 | compileAndLink nonAssetDrawableOne ARSC AndroidManifestApp.xml "$genDir"/temp/res/drawable-nodpi/non_asset_drawable.xml res/values/non_asset_drawable_id.xml |
| 94 | cp -f "$genDir"/out/nonAssetDrawableOne/unzip/res/drawable-nodpi-v4/non_asset_drawable.xml "$genDir"/output/raw/nonAssetDrawableOne.xml |
| 95 | |
| 96 | cp -f "$inDirDrawableNoDpi"/nonAssetDrawableTwo.xml "$genDir"/temp/res/drawable-nodpi/non_asset_drawable.xml |
| 97 | compileAndLink nonAssetDrawableTwo ARSC AndroidManifestApp.xml "$genDir"/temp/res/drawable-nodpi/non_asset_drawable.xml res/values/non_asset_drawable_id.xml |
| 98 | cp -f "$genDir"/out/nonAssetDrawableTwo/unzip/res/drawable-nodpi-v4/non_asset_drawable.xml "$genDir"/output/raw/nonAssetDrawableTwo.xml |
| 99 | |
| 100 | cp -f "$inDirDrawableNoDpi"/nonAssetBitmapGreen.png "$genDir"/temp/res/drawable-nodpi/non_asset_bitmap.png |
| 101 | compileAndLink nonAssetBitmapGreen BOTH AndroidManifestApp.xml "$genDir"/temp/res/drawable-nodpi/non_asset_bitmap.png res/values/non_asset_bitmap_id.xml |
| 102 | cp -f "$genDir"/out/nonAssetBitmapGreen/unzip/res/drawable-nodpi-v4/non_asset_bitmap.png "$genDir"/output/raw/nonAssetBitmapGreen.png |
| 103 | |
| 104 | cp -f "$inDirDrawableNoDpi"/nonAssetBitmapBlue.png "$genDir"/temp/res/drawable-nodpi/non_asset_bitmap.png |
| 105 | compileAndLink nonAssetBitmapBlue ARSC AndroidManifestApp.xml "$genDir"/temp/res/drawable-nodpi/non_asset_bitmap.png res/values/non_asset_bitmap_id.xml |
| 106 | cp -f "$genDir"/out/nonAssetBitmapBlue/unzip/res/drawable-nodpi-v4/non_asset_bitmap.png "$genDir"/output/raw/nonAssetBitmapBlue.png |
| 107 | |
| 108 | $soong_zip -o "$genDir"/out.zip -C "$genDir"/output/ -D "$genDir"/output/ |