16

Is there a way to specify an additional AndroidManifest.xml file for a gradle test aplication? I need it to specify additional permissions and activities for my unit tests.

UPD: I've tried to add instrumnetTest section in the build.gradle file, but it didn't help and I still get Unable to resolve activity for: Intent error

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }
    instrumentTest {
        manifest.srcFile 'src/instrumentTest/AndroidManifest.xml'
        java.srcDir 'src/instrumentTest/Java'
    }
}
Ivan Gromov
  • 4,195
  • 9
  • 41
  • 57
  • have you been able to work this around? I am running into this problem at the moment and am afraid there is no way to make this work because AndroidManifest.xml is automatically generated for instrumentTest: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Basics-and-Configuration It is really restrictive :( – Y2i Dec 24 '13 at 08:14
  • I've managed to work around this but only by changing the Android gradle plugin itself - I don't believe this is possible to achieve without doing that. – ZoFreX Jan 09 '14 at 20:41
  • I'd like to do this too, to override the icon and app name in the test app. Pity it's not supported. @ZoFreX, where did you make the change, and/or have you contacted the Google folks? – Jeff Brateman Jun 25 '14 at 23:04

3 Answers3

11

You can specify an special AndroidManifest.xml for Android Tests (formerly called Instrument Tests) if you are able to use the 0.13.0 (or later) release of the Android Gradle Plugin.

Simply put the file at src/androidTest/AndroidManifest.xml - the manifest merger will take care of the file when you run the gradle test task.

There's an example in the official documentation "gradle-samples-0.13.zip\gradle-samples-0.13\androidManifestInTest" - as one can see there's no special configuration needed to have the test manifest included.

Briareos386
  • 1,927
  • 18
  • 34
0

I have made separate 'android-library' project for testing purposes and added all required components (Activities, Services, etc.) into ./src/main/AndroidManifest.xml

According the documentation http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Testing-Android-Libraries

The manifest of the Library is merged into the manifest of the test app (as is the case for any project referencing this Library).

Andrey Grebnev
  • 226
  • 2
  • 3
-2

Yes you can, in your build.gradle when you define your sourceSets, you can specify the path of your manifest :

 sourceSets {
        main {
            manifest.srcFile 'src/main/AndroidManifest.xml'
            java.srcDir 'src/main/src'
            res.srcDir 'src/main/res'
            assets.srcDir 'src/main/assets'
            resources.srcDir 'src/main/src'
            aidl.srcDir 'src/main/src'
        }

 instrumentTest {
            manifest.srcFile 'src/instrumentTest/AndroidManifest.xml'
            java.srcDir 'src/instrumentTest/src'
            res.srcDir 'src/instrumentTest/res'
            assets.srcDir 'src/instrumentTest/assets'
            resources.srcDir 'src/instrumentTest/src'
            aidl.srcDir 'src/instrumentTest/src'
        }
}

you can checkout on this documentation : http://tools.android.com/tech-docs/new-build-system/user-guide

Andros
  • 4,069
  • 1
  • 22
  • 30
  • The manifest is ignored for tests. According to the [docs](http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Basics-and-Configuration): > The sourceSet should not contain an AndroidManifest.xml as it is automatically generated. – Jeff Brateman Jun 25 '14 at 23:01