Android - Adding Licensing to Your App

I am trying to add licensing to my app that will be available on Google Play. I am trying to add the code to the AppActivity.java file in my project but I get an error saying:

package R does not exist

I am using the sample code from the android sdk:
sdk\extras\google\play_licensing\sample\src\com\example\android\market\licensing\MainActivity.java

Do I have to put the license checking code in the activity source file of the cocos2d-x engine:
\platform\android\java\src\org\cocos2dx\lib\Cocos2dxActivity.java

If anyone could give me a tip on how to do it I would be forever grateful. I suck at java coding it seems.
I am using cocos2d-x-3.1.1.