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

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

问题描述

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

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

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

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:权限被拒绝(缺少互联网权限?)

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

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

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.

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

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?

推荐答案

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

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.

我认为发生的事情是 androidTest/AndroidManifest.xml 中的权限将转到测试应用程序,而不是目标应用程序,尽管我不是 100% 清楚是否真的有两个不同的 APK 或什么.

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天全站免登陆