测试权限和Android应用程序清单文件 [英] Testing permissions and an Android apps Manifest file

查看:282
本文介绍了测试权限和Android应用程序清单文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有添加特定权限的方法的(或其它)到Android清单文件,但是这样它的仅在试运行期间使用 - 不是生产。我在寻找的东西编程,而不是剪切和粘贴时,我测试。

I'd like to know if there is a way to add certain permissions (or anything) to an android manifest file, but so that its only used during test runs - not production. I'm looking for something programmatic, not cutting and pasting when I'm testing.

我读这篇文章: http://developer.android.com /training/location/location-testing.html ,运行应用程序测试中使用已创造了一个测试应用程序不过与Android演播室我们现在不是要创建一个新的应用程序的最佳实践 - 所有的测试应通过应用程序来完成。 (谢谢摇篮)

I'm reading this article: http://developer.android.com/training/location/location-testing.html, the best practice for test running an app used to be creating a 'test-app' however with android studio we now are not meant to create a new app - all testing should be done through the app. (Thank you gradle)

问题是,这篇文章是写在它测试的权限( ACCESS_MOCK_LOCATION ),我不希望坐在我的应用程序 - 如果有一个这样做的很好的方式,我想做到这一点。

The issue is that this article is written with a testing permission (ACCESS_MOCK_LOCATION) in it, and I don't want that sitting in my app - and if there's a good way of doing it, I'd like to do that.

更新:我有这个问题的原因是因为自从移植到Android的摇篮建筑工作室的设置了一个误区。
我没有意识到,构建共享型的androidTest和主要源文件夹。所以在测试或运行未完成的应用程序时,它需要调试文件(如有),将所有生产的东西给它。所以在我的情况下,我加入调试空清单文件,并简单地添加两个权限的话。当我运行或测试,增加的gradle我的所有应用程序的东西从它的其他清单给它这个骨骼文件(或相反,我不确定)。

UPDATE: The reason I had this problem was because of a misunderstanding of the set up of android studio architecture since the migration to Gradle. I didn't realize that the build types shared the 'androidTest' and 'main' source folders. And so when testing or running the unfinished app, it takes the debug files (if any) and adds all the production stuff to it. So in my case, I added a empty manifest file in debug and simply added the two permissions to it. When I run or test, gradle adds all of my apps things from its other manifest to it this skeletal file (or vice versa, I'm uncertain).

所以最终我们并不需要修改androidTest文件夹(其实我不认为我们被允许添加一个清单在这里)作为其完全基于生成了一个用户是否在调试或部署运行。干杯! : - )

So in the end we don't need to modify the androidTest folder (in fact I don't think we are allowed to add a manifest here) as its completely generated based off of whether a user is running on debug or deployment. Cheers! :-)

推荐答案

让我们假设你使用默认的调试发布生成类型和您运行针对调试版本型式试验。
在这种情况下,你可以创建一个的src /调试/ AndroidManifest.xml中并添加您在调试所需要的其他权限建立:

Let's say you use the default debug and release build types and you run your tests against the debug build type. In this case you can create a src/debug/AndroidManifest.xml and add the additional permissions you need in your debug builds:

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

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

</manifest>

这篇关于测试权限和Android应用程序清单文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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