Is it possible to secure an apk file by encrypting it to prevent decompilation. I just want to prevent the hackers from editing the source code of apk and re-uploading it to www.attacker-websites.com.
Suggestions are also appreciated.
If you encrypt an APK, the system must have a key to decrypt it so that it can run. However, the attacker could root the device to obtain the key and then decrypt it. After the app is decrypted, Java is not difficult to reverse engineer. Unfortunately, there is no fool-proof way of preventing the reverse engineering of Android apps. The best option is currently to make the attacker's life miserable by using obfuscation (even though this goes against Kerckhoffs's principle). Tools such as ProGuard help to make your application more difficult to reverse engineer (but again, not impossible).
In short, unfortunately encrypting the APK will not be advantageous when the attackers likely have root access to their device and can find the key.