Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndroidManifest in androidTest directory being ignored

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

test directory structure

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?

like image 887
jwir3 Avatar asked Oct 07 '14 20:10

jwir3


People also ask

What directory holds the AndroidManifest XML file?

Every Android project has an AndroidManifest. xml file, which is kept in the root directory of the project hierarchy. The manifest file is a crucial component of our program since it specifies the metadata, needs, and application structure.

How do I add permission to AndroidManifest file?

If you're using Android Studio, hover over the code that requires the permission and click "Add Permission .." Then you can check the changes in AndroidManifest.

What is AndroidManifest XML file and why do you need this?

Every app project must have an AndroidManifest. xml file (with precisely that name) at the root of the project source set. The manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.


1 Answers

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.

like image 95
user3286293 Avatar answered Oct 04 '22 03:10

user3286293