Today I want to share with you a method to remove any ads from an apk that should work on any Android version without root permissions.
You will need a minimum level of skills to understand the method and a computer (needed to edit the apk).
Obtain the apk
When you install an application, its apk will be placed in /data/app directory. However, you need a rooted phone to access that directory. Luckily, often there is a pre-installed system application to backup your apps (on Huawei there is Huawei Backup) that can access that folder. Thus, you don't need root permissions. You can use this backup pre-installed app to save your apk on the sd and transfer it on your computer.
Edit the apk and re-install it
I'm assuming that you're on Linux, but the same can be done with Windows or Mac. Continue with the following steps:
- An apk is just a zip file, thus extract it in a folder. On Linux: Code:
$ unzip com.example.apk
- Now, try to look at the strings, regarding ads, in plain text inside the file classes.dex (you don't need to extract it). For example: Code:
$ strings classes.dex | grep "ads"
- Keep note about all the ads urls contained in classes.dex (e.g. googleads.g.doubleclick.net)
- Use an hex editor as GHex or Bless to replace these ads urls with invalid urls (I suggest to use the same length). So, for example, you can transform: googleads.g.doubleclick.net into foobarfoo.b.arfoobarfoo.bar.
- Save overwriting the original classes.dex and zip all the files into a new apk (e.g. com.example_noads.apk)
- Sign the new apk. The process is easier using some tools (look for apk signer on google, there are one click tools).
- Transfer the new apk on your phone and install it (the phone should ask if you want to upgrade your app, say yes).
In this way, the application should work as always, but it will try to load the ads from invalid urls. Thus, it should not display any ads.
Note: I've tested this method and it works, however it's possible that some applications are encrypted thus there aren't plain text ads urls.
EDIT: I added a new step where you must sign the new apk. In fact, this is the rule. However, when I wrote this post I didn't talk about that, because in my case I found an application that I succesfully re-installed without re-sign the apk (bug? hash collision? I still don't know).