简体   繁体   中英

Android Product Flavors Manifests

I'm working on my first android app, and I'm just getting started with product flavors. I have a free version in beta, and I'm starting to make aa paid version. I'm a bit confused about the manifests.

The paid version will have one activity that the free version does not, and the two will have different permissions. I'm thinking that I will remove the permissions from the main manifest, that the free manifest will have nothing in it but its permissions, and the paid manifest will have nothing in it but its permissions and the extra activity.

For example, the free manifest might be

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app">

    <uses-permission android:name="android.permission.INTERNET"/>
    </uses-permission>

</manifest>

Is this correct?

That's correct, however, I would recommend you put all common Manifest information in the main , as CommonsWare mentioned.

Also, as a tip, if you do need to replace a value in the main Manifest for any reason (debugging for example), I would use the tools:replace tag like so:

Free flavor:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      package="com.example">

    <application
        android:name=".FreeApp"
        android:allowBackup="false"
        tools:replace="allowBackup,name"/>

</manifest>

This would replace the tags name and allowBackup from main with what you have in this manifest.

I recommend you check out the following link for more information about flavoring and variants, in case you haven't already:

https://developer.android.com/studio/build/build-variants.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM