1# 2# Copyright (C) 2021 The Android Open Source Project 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 16#!/usr/bin/bash 17 18# This script prints two base64 encoded strings to be pasted in Main.java. 19 20# The first string is base64 encoded src-optional/java/util/OptionalLong.java. 21 22# The second is base64 encoded dex, compiled from 23# src-optional/java/util/OptionalLong.class, which in its turn compiled from 24# src-optional/java/util/OptionalLong.java. 25 26set -e 27 28if [ -t 1 ]; then 29 # Color sequences if terminal is a tty. 30 red='\033[0;31m' 31 green='\033[0;32m' 32 yellow='\033[0;33m' 33 magenta='\033[0;35m' 34 nc='\033[0m' 35fi 36 37function help { 38 cat << EOF 39Usage: $0 -d8 $ANDROID_HOME/build-tools/*/d8 \\ 40 -android-jar $ANDROID_HOME/platforms/android-*/android.jar 41 42This script automates regeneration of CLASS_BYTES and DEX_BYTES variables in Main.java 43EOF 44 45 exit 0 46} 47 48while [ $# -gt 0 ]; do 49 key="$1" 50 51 case $key in 52 -d8) 53 d8="$2" 54 shift 55 shift 56 ;; 57 -android-jar) 58 android_jar="$2" 59 shift 60 shift 61 ;; 62 -h|--help) 63 help 64 ;; 65 esac 66done 67 68if [ -z $d8 ]; then 69 printf "${red}No path to d8 executable is specified${nc}\n" 70 help 71fi 72 73if [ -z $android_jar ]; then 74 printf "${red}No path to android.jar specified${nc}\n" 75 help 76fi 77 78if [ ! -f "src-optional/java/util/OptionalLong.java" ]; then 79 printf "${red}src-optional/OptionalLong.java does not exist${nc}\n" 80 exit 1 81fi 82 83printf "${green}Compiling OptionalLong.java... ${nc}" 84javac -source 8 -target 8 src-optional/java/util/OptionalLong.java 1>/dev/null 2>/dev/null 85$d8 --lib $android_jar --release --output . src-optional/java/util/*.class 86printf "${green}Done\n${nc}\n" 87 88 89printf "CLASS_BYTES to be pasted in src/Main.java are below:\n" 90printf "${yellow}8<------------------------------------------------------------------------------${nc}\n" 91cat src-optional/java/util/OptionalLong.java | base64 | sed "s/\(.*\)/\"\1\" \+/g" 92printf "${yellow}8<------------------------------------------------------------------------------${nc}\n\n\n" 93 94printf "DEX_BYTES to be pasted in src/Main.java are below:\n" 95printf "${yellow}8<------------------------------------------------------------------------------${nc}\n" 96cat classes.dex | base64 | sed "s/\(.*\)/\"\1\" \+/g" 97printf "${yellow}8<------------------------------------------------------------------------------${nc}\n\n\n" 98 99printf "${green}Cleaning up...${nc} " 100rm -f src-optional/java/util/OptionalLong.class 101rm -f classes.dex 102printf "${green}Done${nc}\n" 103