A common method to protect this kind of attack is to to
confuse the apk file to make it hard locate the attack point. If it
can’t find the attack point then no effective attack will be
happened. One way is to add a shell for the file and this will
confuse the byte code then the file’s structure is the not well
known format, or encrypt the file and decrypt it while loading.
But some of those kinds of protections have one vulnerability
that it can’t protect the mapped memory so it can’t resist
dynamic attack. Another way is using C/C++ to write critical
code then build as a native library. The native library is more
hard to be hacked and using confuse technology will make it
more hard.