简体   繁体   English

Android:清单中无法识别targetApi

[英]Android: targetApi not recognized in the manifest

I have the following line in my manifest: 我的清单中有以下行:

<intent-filter  android:autoVerify="true">

but I get a lint warning: 但我得到一个lint警告:

Attribute autoVerify is only used in API 23 and higher (current min is 16)

so I changed it to look like this (as per the recommendation that android studio gives me): 所以我改变它看起来像这样(根据android studio给我的建议):

<intent-filter  android:autoVerify="true" tools:targetApi="M">

and I then receive this error when building the apk: 然后我在构建apk时收到此错误:

Error:java.lang.RuntimeException: [path_to_manifest]/AndroidManifest.xml:58:13-67:29: Error: Invalid instruction 'targetApi', valid instructions are : REMOVE,REPLACE,STRICT

Caused by: java.lang.IllegalArgumentException: No enum constant com.android.manifmerger.AttributeOperationType.TARGETAPI

How can I get rid of this error while still getting rid of the lint warning? 如何在摆脱棉绒警告的同时摆脱这个错误?

Edit: I tried both "clean project" and "invalidate cache and restart" - neither work to solve the error. 编辑:我尝试了“清理项目”和“使缓存无效并重新启动” - 无法解决错误。

Issue opened on the Issue Tracker: 问题跟踪器上打开的问题:

https://code.google.com/p/android/issues/detail?id=211805 https://code.google.com/p/android/issues/detail?id=211805

I found an answer here the gives a workaround for this issue. 我在这里找到了答案,为此问题提供了解决方法。

By using the line: 通过使用该行:

<intent-filter  android:autoVerify="true"
            tools:ignore="UnusedAttribute">

The lint error is solved and the apk can be built. 解决了lint错误并且可以构建apk。 I'm not going to mark this as the accepted answer though - I prefer if someone can explain how targetApi can be used (if it can be used)? 我不打算将此标记为已接受的答案 - 我更喜欢有人可以解释如何使用targetApi(如果可以使用)?

Proper syntax is 正确的语法是

<uses-sdk android:minSdkVersion="integer"
      android:targetSdkVersion="integer"
      android:maxSdkVersion="integer" />

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

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