How to use tools:overrideLibrary with multiple libraries

前端 未结 2 1059
梦如初夏
梦如初夏 2020-12-25 11:39

I would like to create an Android project that is compatible to e.g. API level 4 but would still like to test it with UiAutomator that requires API level 18 on newer devices

相关标签:
2条回答
  • 2020-12-25 12:28

    According to official doc(section Merge conflict marker for imported libraries), it should be.

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="com.android.example.app"
       xmlns:tools="http://schemas.android.com/tools">
       ...
       <uses-sdk android:targetSdkVersion="22" android:minSdkVersion="2"
                 tools:overrideLibrary="com.example.lib1, com.example.lib2"/>
    

    where com.example.lib1, com.example.lib2 are the packages declared in the AndroidManifes inside the libraries.

    0 讨论(0)
  • I have found out that the solution is to create a second AndroidManifest.xml, just for the tests. It has to be saved into the tests directory and needs to contain only the overrideLibrary statement:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              package="${applicationId}">
        <uses-sdk tools:overrideLibrary="android.app, android.support.test, android.support.test.rule, android.support.test.espresso, android.support.test.espresso.idling, android.support.test.uiautomator.v18"/>
    </manifest>
    

    If you are using a different directory for your tasks, you can specify it this way in your gradle file:

    androidTest.setRoot('src_test_uiautomator')
    

    The AndroidManifest.xml file has to be in the root of that directory, the test sources in the "java" subdirectory.

    0 讨论(0)
提交回复
热议问题