androidTest目录中的AndroidManifest被忽略 [英] AndroidManifest in androidTest directory being ignored

查看:319
本文介绍了androidTest目录中的AndroidManifest被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下目录结构(由Android Studio设置)进行测试:

我可以很好地运行 some 测试,即使AllTests.java也可以运行,甚至没有AndroidManifest.xml文件也可以.问题是,对于我的一项新测试,我需要android.permission.INTERNET权限.因此,我将以下内容添加到androidTest目录中的AndroidManifest.xml文件中:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.core"
          android:versionCode="2"
          android:versionName="2.0" >

    <uses-sdk android:minSdkVersion="8" />

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

不幸的是,这不起作用.运行我的一项测试时,我仍然收到以下错误:

E/RestAPIRequestTest:权限被拒绝(缺少INTERNET权限?)

我尝试在AndroidManifest.xml文件中将package设置为com.example.core.test(因为这就是我的设置"->应用程序"列表中显示的内容),但没有任何乐趣.

我认为它甚至无法识别AndroidManifest.xml文件,因为版本号也没有显示在测试应用程序的设置"中.

如何为测试项目注入正确的权限?

解决方案

我需要做类似的事情.我在androidTest旁边创建了一个名为"debug"的文件夹,该文件夹对应于该应用程序的debug变体,然后将具有权限的AndroidManifest.xml放入该文件夹中.然后,由于测试应用程序使用debug变体,因此该权限在测试中起作用.这是不理想的,因为它模糊了测试和调试之间的界限,而这并不是完全一样的.

我认为这是正在发生的事情,尽管实际上尚不存在两个不同的APK或其他内容,但我不确定100%知道androidTest/AndroidManifest.xml中的权限将转到测试应用程序,而不是目标应用程序. >

I'm trying to test using the following directory structure (which was setup by Android Studio):

I can run some tests just fine, and even the AllTests.java runs fine without the AndroidManifest.xml file even being there. The thing is, for one of my new tests, I need the android.permission.INTERNET permission. So, I added the following to the AndroidManifest.xml file located within the androidTest directory:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.core"
          android:versionCode="2"
          android:versionName="2.0" >

    <uses-sdk android:minSdkVersion="8" />

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

Unfortunately, this doesn't work. I'm still getting the following error when I run one of my tests:

E/RestAPIRequestTest﹕ Permission denied (missing INTERNET permission?)

I've tried setting the package to be com.example.core.test in my AndroidManifest.xml file (since that is what it shows up as in my Settings->Apps list), but with no joy.

I'm thinking it's not even recognizing the AndroidManifest.xml file, since the version number doesn't show in the Settings for the test app, either.

How can I inject the correct permissions for my test project?

解决方案

I needed to do something similar. I created a folder named "debug" next to androidTest, which corresponds to the debug variant of the app, and put an AndroidManifest.xml with the permission in that folder. Then the permission works under test since the test app uses the debug variant. It's not ideal because it blurs the line between test and debug, which aren't quite the same thing.

I think what's happening is that the permissions in androidTest/AndroidManifest.xml are going to the test app, not the target app, although it's not 100% clear to me if there are actually two different APKs or what.

这篇关于androidTest目录中的AndroidManifest被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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