Reputation: 4415
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'
}
}
Upvotes: 16
Views: 5112
Reputation: 1957
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.
Upvotes: 11
Reputation: 226
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).
Upvotes: 0
Reputation: 4069
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
Upvotes: -2