1#!/bin/bash 2 3# Copyright (C) 2021 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 17readme() { 18 echo ''' 19Add images listed in INPUT_CSV to Android SDK dir. So you can use them by Android Studio AVD manager. e.g. 20./batch_add_avd_image.sh ./resource/avd_img_list.csv 21''' 22} 23 24MY_NAME=$0 25SCRIPT_NAME="${MY_NAME##*/}" 26SCRIPT_DIR="${MY_NAME%/$SCRIPT_NAME}" 27echo Running from $SCRIPT_DIR 28 29INPUT_CSV=$1 30if [[ -z "${INPUT_CSV}" ]]; then 31 INPUT_CSV="$SCRIPT_DIR/resource/avd_img_list.csv" 32fi 33 34echo "Process ${INPUT_CSV}" 35header=0 36avdCount=0 37while IFS=',' read -r name api zip others || [ -n "${name}" ]; do 38 if [[ "${name}" == "name" ]]; then 39 # skip header 40 header="${name},${api},${zip}" 41 else 42 addAvdImgCmd="VARIANT=${name} API_LEVEL=${api} OEM_AVD_ZIP=${zip} ${SCRIPT_DIR}/add_avd_img.sh" 43 echo "${addAvdImgCmd}" 44 eval "${addAvdImgCmd}" 45 46 createAvdCmd="AVD_IMG_NAME=${name} API_LEVEL=${api} DEFAULT_DEVICE_XML=${SCRIPT_DIR}/resource/devices.xml ${SCRIPT_DIR}/create_avd.sh" 47 echo "${createAvdCmd}" 48 eval "${createAvdCmd}" 49 50 echo 51 ((avdCount+=1)) 52 fi 53done < $INPUT_CSV 54 55if [[ $header != "name,api,zip" ]]; then 56 readme 57 echo "ERROR: The header:$header is not as expected in $INPUT_CSV" 58 cat $INPUT_CSV 59fi 60 61echo "Processed ${avdCount} AVDs"