简体   繁体   English

适用于Gradle instrumentTest的AndroidManifest.xml

[英]AndroidManifest.xml for Gradle instrumentTest

Is there a way to specify an additional AndroidManifest.xml file for a gradle test aplication? 有没有办法为gradle测试应用程序指定一个额外的AndroidManifest.xml文件? 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 UPD:我试图在build.gradle文件中添加instrumnetTest部分,但它没有帮助,我仍然Unable to resolve activity for: Intent错误

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'
    }
}

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. 如果您能够使用Android Gradle插件的0.13.0 (或更高版本)版本,则可以为Android测试(以前称为仪器测试)指定一个特殊的AndroidManifest.xml

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. 只需将文件放在src/androidTest/AndroidManifest.xml - 清单合并将在您运行gradle测试任务时处理该文件。

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. 在官方文档“gradle-samples-0.13.zip \\ gradle-samples-0.13 \\ androidManifestInTest”中有一个例子 - 正如人们可以看到,没有包含测试清单所需的特殊配置。

I have made separate 'android-library' project for testing purposes and added all required components (Activities, Services, etc.) into ./src/main/AndroidManifest.xml 我已经为测试目的制作了单独的'android-library'项目,并将所有必需的组件(活动,服务等)添加到./src/main/AndroidManifest.xml中

According the documentation http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Testing-Android-Libraries 根据文档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). 库的清单合并到测试应用程序的清单中(引用此库的任何项目都是如此)。

Yes you can, in your build.gradle when you define your sourceSets, you can specify the path of your manifest : 是的,您可以在build.Set中定义源集时,可以指定清单的路径:

 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 您可以查看此文档: http//tools.android.com/tech-docs/new-build-system/user-guide

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM