Gradle fails on manifest merging for "targetApi"

Viewed 7316

My project contains activity declarations in the manifest that use the tools:targetApi attribute to ignore some warnings. Specifically:

    <activity
        android:name=".activities.ProtocolActivity"
        android:label="@string/title_activity_protocols"
        android:parentActivityName=".activities.InformationActivity"
        tools:targetApi="jelly_bean">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".activities.InformationActivity" />
    </activity>

Out of the blue, however, for instance after switching branches, I get the following compilation error:

Error:/home/paul/git/ally-v2-app/app/src/main/AndroidManifest.xml:67:9-80:20: Error: Invalid instruction 'targetApi', valid instructions are : REMOVE,REPLACE,STRICT
...
Error:java.lang.IllegalArgumentException: No enum constant com.android.manifmerger.AttributeOperationType.TARGETAPI

I'm using the following:

  • Gradle 2.10
  • Gradle plugin 2.0.0-beta6
  • Android Studio 2.0 beta 6
  • Both on an Ubuntu 15.10 machine and a Windows 10 machine

It seems I can get things working again by clearing the cache and restarting Android Studio, or removing the attributes, building, then adding them again.

3 Answers

I am posting this late, but probably will help someone..

Find the manifest.xml file described by error in the temp folder, copy it and past in the assets->plugins->android directory and rename it to AndroidManifest.xml

Then edit it and find the <application...> and inside it paste the suggested solution.

For example, I had to paste tools:replace="android:label" so it would look like <application ... tools:replace="android:label">

ps: I spent a whole day on this, if this worked for you, upvote so others can find it. If it didn't please comment.

Related