1#!/bin/bash
2#
3# Copyright (C) 2018 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17
18# apt_binary is $(AAPT) in the build.
19
20# Parse sdk, targetSdk, and uses librares in the APK, then cross reference against build specified ones.
21
22set -e
23local_apk=$1
24badging=$(${aapt_binary} dump badging "${local_apk}")
25export sdk_version=$(echo "${badging}" | grep "sdkVersion" | sed -n "s/sdkVersion:'\(.*\)'/\1/p")
26# Export target_sdk_version to the caller.
27export target_sdk_version=$(echo "${badging}" | grep "targetSdkVersion" | sed -n "s/targetSdkVersion:'\(.*\)'/\1/p")
28uses_libraries=$(echo "${badging}" | grep "uses-library" | sed -n "s/uses-library:'\(.*\)'/\1/p")
29optional_uses_libraries=$(echo "${badging}" | grep "uses-library-not-required" | sed -n "s/uses-library-not-required:'\(.*\)'/\1/p")
30
31# Verify that the uses libraries match exactly.
32# Currently we validate the ordering of the libraries since it matters for resolution.
33single_line_libs=$(echo "${uses_libraries}" | tr '\n' ' ' | awk '{$1=$1}1')
34if [[ "${single_line_libs}" != "${uses_library_names}" ]]; then
35  echo "LOCAL_USES_LIBRARIES (${uses_library_names})" \
36       "do not match (${single_line_libs}) in manifest for ${local_apk}"
37  exit 1
38fi
39
40# Verify that the optional uses libraries match exactly.
41single_line_optional_libs=$(echo "${optional_uses_libraries}" | tr '\n' ' ' | awk '{$1=$1}1')
42if [[ "${single_line_optional_libs}" != "${optional_uses_library_names}" ]]; then
43  echo "LOCAL_OPTIONAL_USES_LIBRARIES (${optional_uses_library_names}) " \
44       "do not match (${single_line_optional_libs}) in manifest for ${local_apk}"
45  exit 1
46fi
47
48