Mathieu Chartier | d022b65 | 2018-03-23 21:57:02 -0700 | [diff] [blame] | 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 | |
Mathieu Chartier | 116790d | 2018-05-14 10:13:37 -0700 | [diff] [blame] | 18 | # apt_binary is $(AAPT) in the build. |
| 19 | |
Mathieu Chartier | d022b65 | 2018-03-23 21:57:02 -0700 | [diff] [blame] | 20 | # Parse sdk, targetSdk, and uses librares in the APK, then cross reference against build specified ones. |
| 21 | |
| 22 | set -e |
| 23 | local_apk=$1 |
Ulya Trafimovich | 5a09c20 | 2021-02-17 16:05:21 +0000 | [diff] [blame] | 24 | status_file=$2 |
Mathieu Chartier | 116790d | 2018-05-14 10:13:37 -0700 | [diff] [blame] | 25 | badging=$(${aapt_binary} dump badging "${local_apk}") |
Mathieu Chartier | d022b65 | 2018-03-23 21:57:02 -0700 | [diff] [blame] | 26 | export sdk_version=$(echo "${badging}" | grep "sdkVersion" | sed -n "s/sdkVersion:'\(.*\)'/\1/p") |
| 27 | # Export target_sdk_version to the caller. |
| 28 | export target_sdk_version=$(echo "${badging}" | grep "targetSdkVersion" | sed -n "s/targetSdkVersion:'\(.*\)'/\1/p") |
| 29 | uses_libraries=$(echo "${badging}" | grep "uses-library" | sed -n "s/uses-library:'\(.*\)'/\1/p") |
| 30 | optional_uses_libraries=$(echo "${badging}" | grep "uses-library-not-required" | sed -n "s/uses-library-not-required:'\(.*\)'/\1/p") |
| 31 | |
Ulya Trafimovich | 5a09c20 | 2021-02-17 16:05:21 +0000 | [diff] [blame] | 32 | errmsg= |
| 33 | |
Mathieu Chartier | d022b65 | 2018-03-23 21:57:02 -0700 | [diff] [blame] | 34 | # Verify that the uses libraries match exactly. |
| 35 | # Currently we validate the ordering of the libraries since it matters for resolution. |
| 36 | single_line_libs=$(echo "${uses_libraries}" | tr '\n' ' ' | awk '{$1=$1}1') |
| 37 | if [[ "${single_line_libs}" != "${uses_library_names}" ]]; then |
Ulya Trafimovich | 5a09c20 | 2021-02-17 16:05:21 +0000 | [diff] [blame] | 38 | errmsg="LOCAL_USES_LIBRARIES (${uses_library_names}) do not match (${single_line_libs}) in manifest for ${local_apk}" |
Mathieu Chartier | d022b65 | 2018-03-23 21:57:02 -0700 | [diff] [blame] | 39 | fi |
| 40 | |
| 41 | # Verify that the optional uses libraries match exactly. |
| 42 | single_line_optional_libs=$(echo "${optional_uses_libraries}" | tr '\n' ' ' | awk '{$1=$1}1') |
| 43 | if [[ "${single_line_optional_libs}" != "${optional_uses_library_names}" ]]; then |
Ulya Trafimovich | 5a09c20 | 2021-02-17 16:05:21 +0000 | [diff] [blame] | 44 | errmsg="LOCAL_OPTIONAL_USES_LIBRARIES (${optional_uses_library_names}) do not match (${single_line_optional_libs}) in manifest for ${local_apk}" |
Mathieu Chartier | d022b65 | 2018-03-23 21:57:02 -0700 | [diff] [blame] | 45 | fi |
| 46 | |
Ulya Trafimovich | 5a09c20 | 2021-02-17 16:05:21 +0000 | [diff] [blame] | 47 | if [[ ! -z "${errmsg}" ]]; then |
| 48 | echo "${errmsg}" > "${status_file}" |
| 49 | if [[ "${relax_check}" != true ]]; then |
| 50 | # fail immediately |
| 51 | echo "${errmsg}" |
| 52 | exit 1 |
| 53 | fi |
| 54 | else |
| 55 | touch "${status_file}" |
| 56 | fi |