md5sum output is different than md5 on mac
the result of the md5 apk calculation must only be the md5 hash, it should not include any extra notations like white space or the file name.
suggest moving to an open ssl command phrase like :
$(openssl dgst -md5 $i | sed 's/^.* //')
in place of the $(md5sum $i)
phrase