Android的工作室分为两种不同的清单文件 [英] Android Studio two flavors with different manifest files

查看:371
本文介绍了Android的工作室分为两种不同的清单文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用定义为我的Andr​​oid工作室口味两种不同的清单文件的问题。这是我目前的项目结构:

的Andr​​oidManifest.xml 免费味是这样的:

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=se.example.package>
    <使用-权限的Andr​​oid:名称=android.permission.INTERNET对/>
    <使用-权限的Andr​​oid:名称=android.permission.ACCESS_NETWORK_STATE/>
    <使用-权限的Andr​​oid:名称=android.permission.ACCESS_WIFI_STATE/>
< /舱单>
 

的Andr​​oidManifest.xml 的味道没有用途,权限,但包含清单的其余部分code,它是所有口味之间共享。

的Andr​​oidManifest.xml PRO 味是这样的:

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=se.example.package>
    <使用-权限的Andr​​oid:名称=com.android.vending.CHECK_LICENSE/>
< /舱单>
 

build.gradle定义像

的两种口味

  productFlavors {
    自由 {
        的applicationIDse.example.package.free
        的minSdkVersion 14
        targetSdkVersion 21
        版本code 1
        VERSIONNAME'1.0'
    }
    亲{
        的minSdkVersion 14
        的applicationIDse.example.package.pro
        targetSdkVersion 21
        版本code 2
        VERSIONNAME'1.1'
    }
}
 

这我期待的结果是,在不同的口味定义不同用途-权限。 这是不是这样的结果是目前的两个口味只定义了<使用-权限的Andr​​oid:名称=com.android.vending.CHECK_LICENSE/&GT ; 如亲的味道定义的Andr​​oidManifest.xml

我曾尝试:

  • 清洁项目
  • 重建项目
  • 重新启动Android的工作室
  • 同步摇篮

但没有成功。我该怎么解决这个问题?任何帮助是AP preciated。

修改1

我改变了每个口味的位置的Andr​​oidManifest.xml 文件从每个 RES 文件夹免费 PRO 文件夹。这样做的结果是:

  1. 在临味显示了预期的许可权限。
  2. 免费风味显示了这两个权限的Andr​​oidManifest.xml 文件,许可和网络权限(应该是唯一的网络)

这感觉就像项目结构的问题。是什么,使这个?

编辑2

我把合并报告,Commonsware暗示,这些都是关于的报告采用-权限

是免费的:

 使用-许可#com.android.vending.CHECK_LICENSE
从qwknoteGIT增加:许可库:未指定:26:5
    机器人:名称
        从qwknoteGIT增加:许可库:未指定:26:22
 

临:

 使用-许可#com.android.vending.CHECK_LICENSE
从qwknoteGIT已合并:许可库:未指定:26:5
 

解决方案

高科技背景:

本链接,介绍了技术和参数,可以用于清单合并:<一href="http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger#TOC-tools:node-markers">http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger#TOC-tools:node-markers

在一个特定的工具:节点指向了XML如何某些节点上的表现应该表现,同时合并

解决方法:

要实现在一个有些permisions和其他明显的不同,添加你需要的所有权限和口味文件中体现删除那些你不需要的,如下面的例子:

免费删除检查许可

 &LT;许可
   机器人:名称=com.android.vending.CHECK_LICENSE
   工具:节点=删除/&GT;
 

I'm having issues with defining two different manifest files for my flavors in Android Studio. This is my current project structure:

The AndroidManifest.xml in the free flavor looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="se.example.package">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
</manifest>

The AndroidManifest.xml in the main flavor has no uses-permissions, but contains the rest of the manifest code that is shared between all flavors.

The AndroidManifest.xml in the pro flavor looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="se.example.package">
    <uses-permission android:name="com.android.vending.CHECK_LICENSE" />
</manifest>

build.gradle defines the two flavors like

productFlavors {
    free {
        applicationId 'se.example.package.free'
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName '1.0'
    }
    pro {
        minSdkVersion 14
        applicationId 'se.example.package.pro'
        targetSdkVersion 21
        versionCode 2
        versionName '1.1'
    }
}

The result that I am expecting is that the different flavors defines different uses-permissions. This is not the case. The result is currently that the both flavors only defines the <uses-permission android:name="com.android.vending.CHECK_LICENSE" /> as defined in AndroidManifest.xml in the pro flavor.

I have tried:

  • Clean project
  • Rebuild project
  • Restart Android Studio
  • Sync gradle

But without success. How am I to fix this? Any help is appreciated.

EDIT 1

I changed the location of each flavors AndroidManifest.xml file from each of the res folders to free and pro folder. The result of this:

  1. Pro flavor shows Licence permission as expected.
  2. Free flavor shows permissions from both AndroidManifest.xml files, License and network permissions (Should be only network)

This feels like an issue of project structure. What to make of this?

EDIT 2

I pulled the merge reports as Commonsware hinted, these are the reports regarding uses-permissions

Free:

uses-permission#com.android.vending.CHECK_LICENSE
ADDED from qwknoteGIT:licencing-library:unspecified:26:5
    android:name
        ADDED from qwknoteGIT:licencing-library:unspecified:26:22

Pro:

uses-permission#com.android.vending.CHECK_LICENSE
MERGED from qwknoteGIT:licencing-library:unspecified:26:5

解决方案

tech background:

on this link it explains the techniques and parameters that can be use for manifest merging: http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger#TOC-tools:node-markers

One in specific is the tools:node that points out how certain XML nodes on the manifest should behave whilst merging.

solution:

to achieve some permisions in one and different in other manifest, add ALL permissions you need to the main and in the flavours manifest remove the ones you don't need, like the example below:

free remove the check license

<permission
   android:name="com.android.vending.CHECK_LICENSE" 
   tools:node="remove"/>

这篇关于Android的工作室分为两种不同的清单文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆