Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tools:overrideLibrary is not working [duplicate]

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. So the app would also run on old devices but the automatic tests would be performed on new devices.

Therefore I have created a new project with Android Studio and added the UiAutomator test libraries:

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:appcompat-v7:23.0.1'
  androidTestCompile 'com.android.support:support-annotations:23.0.1'
  androidTestCompile 'com.android.support.test:runner:0.3'
  androidTestCompile 'com.android.support.test:rules:0.3'
  androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
}

When compiling it I get the error

Error:Execution failed for task ':app:processDebugAndroidTestManifest'.
> java.lang.RuntimeException: Manifest merger failed : uses-sdk:minSdkVersion 4 cannot be smaller than version 8 declared in library [com.android.support.test:runner:0.3] /Users/dom/Entwicklung/MacBookPro/git/GradleTest/app/build/intermediates/exploded-aar/com.android.support.test/runner/0.3/AndroidManifest.xml
    Suggestion: use tools:overrideLibrary="android.support.test" to force usage

Adding

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

to the AndroidManifest.xml causes another error to occur:

Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 4 cannot be smaller than version 7 declared in library [com.android.support:appcompat-v7:23.0.1] /Users/dom/Entwicklung/MacBookPro/git/GradleTest/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.1/AndroidManifest.xml
    Suggestion: use tools:overrideLibrary="android.support.v7.appcompat" to force usage

Changing it to

<uses-sdk tools:overrideLibrary="android.support.test, android.support.v7.appcompat"/>

causes the first error again:

Error:Execution failed for task ':app:processDebugAndroidTestManifest'.
> java.lang.RuntimeException: Manifest merger failed : uses-sdk:minSdkVersion 4 cannot be smaller than version 8 declared in library [com.android.support.test:runner:0.3] /Users/dom/Entwicklung/MacBookPro/git/GradleTest/app/build/intermediates/exploded-aar/com.android.support.test/runner/0.3/AndroidManifest.xml
    Suggestion: use tools:overrideLibrary="android.support.test" to force usage

I am using the latest Android Studio and build tools. The gradle command that Android Studio uses to build the app is

Gradle tasks [clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:compileDebugSources, :app:compileDebugAndroidTestSources]

so the problem can be reproduced e.g. with

gradle :app:generateDebugAndroidTestSources :app:compileDebugAndroidTestSources

What is the correct syntax to specify multiple libraries in tools:overrideLibrary ? I have read that a comma and a space would be correct, but it doesn't seem to work. I have read a lot about it here on StackOverflow and elsewhere but unfortunately I couldn't find a solution so far (aside from commenting out the tests).

like image 834
Dominique Avatar asked Oct 02 '15 13:10

Dominique


People also ask

How do I fix a failed manifest merger?

Go to manifest file. And click on Merged Manifest. There you can find the suggestions just click on replace the error will be solved.

How to check merged manifest?

Inspect the merged manifest and find conflicts xml file in Android Studio, and then clicking the Merged Manifest tab at the bottom of the editor. The Merged Manifest view shows the results of the merged manifest on the left and information about each merged manifest file on the right, as shown in figure 2.

How do I fix manifest merger failed with multiple errors see logs?

The initial process would be to open the manifest application known as the AndroidManifest. xml and then click on the Merged Manifest tab below your edit pane. Following which, Click on the merged manifest option. An Error would be visible at the right column and then one must try to solve the error.


2 Answers

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.

like image 96
Dominique Avatar answered Sep 25 '22 09:09

Dominique


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.

like image 23
Gabriele Mariotti Avatar answered Sep 26 '22 09:09

Gabriele Mariotti