1#!/bin/bash 2# 3# Copyright (C) 2009 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# This tool checks the integrity of the optimized dex files on a single 19# Android device connected to your computer. 20# 21# Brief HOW-TO: 22# 23# 1. Disconnect all but one device from USB. 24# 2. Set up a standard shell environment (envsetup.sh, lunch, etc.). 25# 3. Run "adb root" if necessary to ensure read permission on 26# /data/dalvik-cache. If in doubt, run the command. Power users may 27# also use "su" followed by "chmod 777 /data/dalvik-cache". 28# 4. Run this script, e.g. from the build root, "dalvik/tools/dexcheck". 29# 30# If all of the dex files are okay, you will just see a series of 31# lines written to your shell window naming each of the files. If 32# there is a problem, though, you will see something like this: 33# 34# system@app@Maps.apk@classes.dex 35# Failure in system@app@Maps.apk@classes.dex: ERROR: DEX parse failed 36# 37# When this happens, the log ("adb logcat") will generally have at 38# least a little more information about the dex level of the problem. 39# However, any error at all usually indicates some form of lower level 40# filesystem or filesystem cache corruption. 41# 42 43# Get the list of files. Use "sed" to drop the trailing carriage return. 44files=`adb shell "cd /data/dalvik-cache; echo *" | sed -e s/.$//` 45if [ "$files" = "*" ]; then 46 echo 'ERROR: commands must run as root on device (try "adb root" first?)' 47 exit 1 48fi 49 50failure=0 51 52# Check each file in turn. This is much faster with "dexdump -c", but that 53# flag was not available in 1.6 and earlier. 54# 55# The dexdump found in older builds does not stop on checksum failures and 56# will likely crash. 57for file in $files; do 58 echo $file 59 errout=`adb shell "dexdump /data/dalvik-cache/$file > dev/null"` 60 errcount=`echo $errout | wc -w` > /dev/null 61 if [ $errcount != "0" ]; then 62 echo " Failure in $file: $errout" 63 failure=1 64 fi 65done 66 67exit $failure 68