I have an app written in flutter and published it on App Store and Play Store. I just want to use in app purchase with iOS only and I don’t want to use it with android. And I don’t want the generated APK and app bundle contains com.android.vending.BILLING permission in manifest file. Ideally generated APK and app bundle should not include any billing library for Google Play Store. How can I achieve this? If I use only in_app_purchase_storekit and in_app_purchase_platform_interface packages, and not use in_app_purchase package, can I implement it? When I try to add this code, it fails. Because InAppPurchase is defined in in_app_purchase package.
final InAppPurchase inAppPurchase = InAppPurchase.instance;
2
Answers
In Android, when the project is built, the various AndroidManifest.xml files are merged together to ensure a single Application AndroidManifest.xml file. Thus resulting in this permission being added to your final binary. Fortunately there is a way to exclude this permission definition to achieve your desired result. This is discussed on the Android Docs Manage Manifest Files.
It is best to use Android Studio to do this as there is a way to view the Merged Manifest before the final APK is built. Android Studio has a view called Merged Manifest.
In your app’s AndroidManifest.xml, you will want to add the following lines.
At the top of the manifest, edit the line to look like this:
Explicitly you will want to add the line
xmlns:tools="http://schemas.android.com/tools"
. This gives the AndroidManifest the ability to access the tools.Then where you have your other permissions defined, include the BILLING permission like so:
<uses-permission android:name="com.android.vending.BILLING" tools:node="remove"/>
The specific piece is
tools:node="remove"
which tells the merger tools to REMOVE this permission if it is found. The resulting merged AndroidManifest will no longer have the BILLING permission. This can be verified in the MergedManifest view in Android Studio or in the final AndroidManifest.xml when you build your APK/AppBundle.The Dart/Flutter code and Android Billing library will still exist but because you have told Android you are not doing Billing by removing the permission, you should be okay to submit.
If not, please let me know in a comment and I can try to assist further.
It’s totally possible to use only the iOS part of the in_app_purchase package. Like you guessed, you must only add in_app_purchase_storekit to your dependencies.
You can find working example in the repo of the project.