I have an android app which is build with android studio/gradle so that there is a free and a pro build.
The free version needs two extra permissions, INTERNET and ACCESS_NETWORK_STATE, to support advertising. I want my pro edition to not need these permissions.
I have set up a separate manifest file for the free edition, with the extra permissions, but when I built the pro version, it still said it needed those permissions.
Only when I changed my gradle file to no longer use com.google.android.gms:play-services-ads did it build without the extra two permissions.
I changed the gradle file from:
compile 'com.google.android.gms:play-services-ads:8.4.0'
to:
freeCompile 'com.google.android.gms:play-services-ads:8.4.0'
But when I do that, I get errors in my code, because the following imports cannot be resolved:
import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdView;
I need this because I need to initialize the ads in the free version:
if (!isPro) { AdView mAdView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); }
In C I would use a pre-processor macro and have no problems, but Java is much much more advanced and so doesn't have that useful feature. ;-)
How do I compile this library only into my free version, but still refer to these classes in my code to set up the ads?
Another problem is that there are IDs on the free layout that are not in the pro layout. This generates an error in the pro version because R.id.adView is not found. To get around this, I created an empty, invisible text box on the pro layout, and named it adview. Is there a better way?