为 testAndroid 设置与主应用程序不同的 minSdkVersion [英] Set different minSdkVersion for testAndroid than for main app

查看:30
本文介绍了为 testAndroid 设置与主应用程序不同的 minSdkVersion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以为测试设置与应用程序本身不同的 minSdkVersion?我问是因为我想使用新的测试支持库和 UI Automator 进行测试.但是,这仅适用于 API 18+.同时,我仍然希望支持旧版本的 Android,尽管没有经过彻底的测试.为了做到这一点,我需要在 build.gradle 文件中添加什么?

Is it possible to set a different minSdkVersion for tests than for the app itself? I ask because I want to use the new Test Support Library and UI Automator for testing. However, this is only available on API 18+. At the same time, I still want to support older versions of Android, albeit not as thoroughly tested. What do I need to add to my build.gradle file in order to do this?

澄清一下,我使用的是 Android Studio 和新的"基于 Gradle 的项目结构.

To clarify, I am using Android Studio and the "new" Gradle-based project structure.

推荐答案

我从 来自 Google 的新测试模板.

在您的 testandroidTest 文件夹中创建一个新的 AndroidManifest.xml 文件.

Create a new AndroidManifest.xml file in your test or androidTest folder.

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:tools="http://schemas.android.com/tools"
    package="your.package.name">

    <uses-sdk tools:overrideLibrary="android.support.test.uiautomator.v18"/>
</manifest>

这篇关于为 testAndroid 设置与主应用程序不同的 minSdkVersion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆