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}" 20aapt="${5}" 21 22aapt_cmd="$aapt dump xmltree $base_apk --file AndroidManifest.xml" 23version_code=$(${aapt_cmd} | grep "http://schemas.android.com/apk/res/android:versionCode" | cut -d "=" -f2 | head -n 1) 24min_sdk=$(${aapt_cmd} | grep "http://schemas.android.com/apk/res/android:minSdkVersion" | cut -d "=" -f2 | head -n 1) 25if [[ -z "$version_code" ]] 26then 27 echo "Base app missing versionCode in AndroidManifest.xml" 28 exit 1 29fi 30 31if [[ -z "$min_sdk" ]] 32then 33 echo "Base app missing minsdk in AndroidManifest.xml" 34 exit 1 35fi 36 37cat >$out_manifest <<EOF 38<?xml version="1.0" encoding="utf-8"?> 39<manifest xmlns:android="http://schemas.android.com/apk/res/android" 40 xmlns:dist="http://schemas.android.com/apk/distribution" 41 package="$package" 42 split="$split" 43 android:versionCode="$version_code" 44 android:isFeatureSplit="true"> 45 46 <application android:hasCode="false" /> <!-- currently only supports asset splits --> 47 <uses-sdk android:minSdkVersion="$min_sdk" /> 48</manifest> 49EOF 50