Home | History | Annotate | Download | only in core
      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 # Parse sdk, targetSdk, and uses librares in the APK, then cross reference against build specified ones.
     19 
     20 set -e
     21 local_apk=$1
     22 badging=$(aapt dump badging "${local_apk}")
     23 export sdk_version=$(echo "${badging}" | grep "sdkVersion" | sed -n "s/sdkVersion:'\(.*\)'/\1/p")
     24 # Export target_sdk_version to the caller.
     25 export target_sdk_version=$(echo "${badging}" | grep "targetSdkVersion" | sed -n "s/targetSdkVersion:'\(.*\)'/\1/p")
     26 uses_libraries=$(echo "${badging}" | grep "uses-library" | sed -n "s/uses-library:'\(.*\)'/\1/p")
     27 optional_uses_libraries=$(echo "${badging}" | grep "uses-library-not-required" | sed -n "s/uses-library-not-required:'\(.*\)'/\1/p")
     28 
     29 # Verify that the uses libraries match exactly.
     30 # Currently we validate the ordering of the libraries since it matters for resolution.
     31 single_line_libs=$(echo "${uses_libraries}" | tr '\n' ' ' | awk '{$1=$1}1')
     32 if [[ "${single_line_libs}" != "${uses_library_names}" ]]; then
     33   echo "LOCAL_USES_LIBRARIES (${uses_library_names})" \
     34        "do not match (${single_line_libs}) in manifest for ${local_apk}"
     35   exit 1
     36 fi
     37 
     38 # Verify that the optional uses libraries match exactly.
     39 single_line_optional_libs=$(echo "${optional_uses_libraries}" | tr '\n' ' ' | awk '{$1=$1}1')
     40 if [[ "${single_line_optional_libs}" != "${optional_uses_library_names}" ]]; then
     41   echo "LOCAL_OPTIONAL_USES_LIBRARIES (${optional_uses_library_names}) " \
     42        "do not match (${single_line_optional_libs}) in manifest for ${local_apk}"
     43   exit 1
     44 fi
     45 
     46