1#!/bin/bash --posix 2# Copyright 2021 The Bazel Authors. All rights reserved. 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 16out_manifest="${1}" 17base_apk="${2}" 18package="${3}" 19split="${4}" 20title_id="${5}" 21fused="${6}" 22aapt="${7}" 23 24aapt_cmd="$aapt dump xmltree $base_apk --file AndroidManifest.xml" 25version_code=$(${aapt_cmd} | grep "http://schemas.android.com/apk/res/android:versionCode" | cut -d "=" -f2 | head -n 1 ) 26if [[ -z "$version_code" ]] 27then 28 echo "Base app missing versionCode in AndroidManifest.xml" 29 exit 1 30fi 31 32cat >$out_manifest <<EOF 33<?xml version="1.0" encoding="utf-8"?> 34<manifest xmlns:android="http://schemas.android.com/apk/res/android" 35 xmlns:dist="http://schemas.android.com/apk/distribution" 36 package="$package" 37 split="$split" 38 android:versionCode="$version_code" 39 android:isFeatureSplit="true"> 40 41 <dist:module 42 dist:instant="false" 43 dist:title="@string/$title_id"> <!-- title must be an ID! Needs to work with proguard/resource shrinking --> 44 <dist:fusing dist:include="$fused" /> 45 <dist:delivery> 46 <dist:on-demand /></dist:delivery> 47 </dist:module> 48 49 <application android:hasCode="false" /> <!-- currently only supports asset splits --> 50</manifest> 51EOF 52