I have just decompile my signed apk using apkTool and resigned new apk with different keystore using the same decomplied class folder. And then tried to install and override the older apk with new apk in my device and it is working fine.
But now I don't want this apk to get resigned with different keystore. If someone resigned it with different keystore then it should not be override with the older one or it should not get installed.
Commands to create new signed apk :
1. java -jar apktool.jar d test.apk
2. java -jar apktool.jar B test
3. keytool -genkey -v -keystore testrelease.keystore -alias testrelease -keyalg RSA -keysize 2048 -validity 10000
4. jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore testrelease.keystore test_1.apk testrelease
Note : Here I am not using playstore to deploy apk I am just doing it in my device directly by sharing apk via mail.
I don't think you can prevent your app from resigning. Nothing can be 100% safe. Although you can verify your app's signature at runtime and perform some action when the signature doesn't match the original one. However this verification code can also be removed easily after decompiling the apk.
Use this to verify signature :
You can compare any signature (MD5,SHA1,SHA256) you want , here i just compared the "sha" of the app.