I recently finished an android application that I put on the play store. I wish to put it on github / bitbucket in case anyone is interested by it.
There is an ad banner, so I stored my public key in the strings.xml file. How should I handle it ?
I already added a "flavour" in order to be able to generate an apk without ads.
Additionally what kind of similar precautions should I take before releasing it in the wild ?
You should not upload any API keys or alike to any GitHub repository since it's going to be against most of the Terms and Conditions of a lot of providers, including GitHub itself I think.
To solve this, you could put a placeholder in the place where the people should put their own API key and upload that file to the repository, for example:
<resources>
<string name="GOOGLE_MAPS_API_KEY">PUT YOUR API KEY HERE</string>
</resources>
You should also start thinking about licensing your code.
Open source licenses are licenses that comply with the Open Source Definition — in brief, they allow software to be freely used, modified, and shared. To be approved by the Open Source Initiative (also known as the OSI), a license must go through the Open Source Initiative's license review process.
There are a lot of different licenses, including:
Check out this link to see more about these licenses.
And, yes you can still benefit from your own ads using Open Source, as in the opensource.org website is mentioned:
Can Open Source software be used for commercial purposes?
Absolutely. All Open Source software can be used for commercial purpose; the Open Source Definition guarantees this. You can even sell Open Source software.