ult*_*eek 2 android android-manifest aapt2
今天我升级到 Android Studio 3.1.4 出现第一个错误
The option 'android.enableAapt2' is deprecated and should not be used anymore.
Use 'android.enableAapt2=true' to remove this warning.
It will be removed at the end of 2018..
Run Code Online (Sandbox Code Playgroud)
然后我android.enableAapt2按照它的建议将 the 更改为 true 。
之后我有新的错误 AAPT2 错误
error: unknown element <intent-filter> found.
Message{kind=ERROR, text=error: unknown element <intent-filter> found., sources=[C:\FILE\Android Studio\UltraGreek\UltraGreekv.4.7\app\build\intermediates\manifests\full\debug\AndroidManifest.xml:37], original message=, tool name=Optional.of(AAPT)}
Run Code Online (Sandbox Code Playgroud)
我在 app/srs/main/AndroidManifest.xml 中的清单是
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ultragreek.ultragreek">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ultrasidelogo"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".ActivitySecond"/>
<activity android:name=".ActivityAbout"/>
<activity android:name=".WebViewer"/>
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
<activity
android:name=".ActivityStats"
android:label="??????????">
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
AAPT2 是 AAPT 的替代品。如果你用谷歌搜索任何与 AAPT2 相关的东西,有人会建议你禁用它。不要这样做。它已被弃用并计划移除,这意味着您无论如何都会收到这些错误。
为了学习,我们把错误信息分解一下。它的格式为 JSON,这意味着每个等号标记一个新元素。这是两个相关的:
text=error: unknown element <intent-filter> found.
sources=[C:\FILE\Android Studio\UltraGreek\UltraGreekv.4.7\app\build\intermediates\manifests\full\debug\AndroidManifest.xml:37]
Run Code Online (Sandbox Code Playgroud)
这意味着您在第 37 行的清单中有一个与意图过滤器相关的异常。如果元素位于错误的位置,它会显示为未知元素。请参阅迁移指南。
现在,我没有行号,因为 Stack Overflow 不包括它们。但是如果你查看application标签内部,你会看到:
<activity android:name=".WebViewer"/>
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
问题是活动标签是关闭的,这意味着它实际上是这样的(伪代码):
<application ...>
<activity android:name=".WebViewer"/>
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
</application>
Run Code Online (Sandbox Code Playgroud)
<intent-filter> 仅在活动下允许,并且(来自之前链接的迁移指南):
在以前版本的 AAPT 中,嵌套在 Android 清单中不正确节点中的元素要么被忽略,要么导致警告。[...]
这意味着错误的节点现在会阻止编译。这就是为什么在激活 AAPT2 时会出现错误,但在 AAPT 时不会。
解决方案是移动<intent-filter>到支持节点,这意味着您需要将其包装在活动标签中。我不知道你想要哪个,所以我不会为此提供任何准确的代码。但是intent-filter标签需要在活动标签内,像这样:
<activity android:name="" android:label="">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7486 次 |
| 最近记录: |