AAPT:错误:在 <manifest> 中发现了意外元素 <queries>。将 admob 广告添加到我的应用时出错

Posted

技术标签:

【中文标题】AAPT:错误:在 <manifest> 中发现了意外元素 <queries>。将 admob 广告添加到我的应用时出错【英文标题】:AAPT: error: unexpected element <queries> found in <manifest>. error when I add admob ads to my app 【发布时间】:2021-06-13 23:00:57 【问题描述】:

我的 Flutter 应用在​​ android 上运行良好,但是当我想使用 google admob 添加广告时,我按照此处的说明进行操作 here 但在我添加了所有要求之后,当我运行我的应用时,它给出了这个错误

Launching lib\main.dart on SM A515F in debug mode...
lib\main.dart:1

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource linking failed
     C:\Users\husam\.gradle\caches\transforms-3\41205c7bc612f206229dc6e7d7c5af46\transformed\play-services-ads-lite-19.7.0\AndroidManifest.xml:27:5-43:15: AAPT: error: unexpected element <queries> found in <manifest>.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2m 44s
The build failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetifier to solve the incompatibility.
Building plugin firebase_admob...

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_admob-0.9.3+4\android\build.gradle' line: 22

* What went wrong:
A problem occurred evaluating root project 'firebase_admob'.
> Failed to apply plugin [id 'com.android.library']
   > Minimum supported Gradle version is 5.1.1. Current version is 4.10.2. If using the gradle wrapper, try editing the distributionUrl in C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_admob-0.9.3+4\android\gradle\wrapper\gradle-wrapper.properties to gradle-5.1.1-all.zip

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 30s
2

Exception: The plugin firebase_admob could not be built due to the issue above.

我尝试将 gradle 版本更改为 5.1.1,但同样的错误预计将涉及其他 gradle 发行版,我也尝试运行 flutter cleanflutter pub cache repair 如果需要,我将分享我的代码的某些部分 此外,当我尝试添加 admob 插件和代码中所需的代码时,我遇到了这个错误

E/flutter ( 1088): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: MissingPluginException(No implementation found for method loadBannerAd on channel plugins.flutter.io/firebase_admob)
E/flutter ( 1088): #0      MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:156
E/flutter ( 1088): <asynchronous suspension>
E/flutter ( 1088): #1      _invokeBooleanMethod (package:firebase_admob/firebase_admob.dart:612:23)
E/flutter ( 1088): <asynchronous suspension>
E/flutter ( 1088):
E/flutter ( 1088): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: MissingPluginException(No implementation found for method showAd on channel plugins.flutter.io/firebase_admob)
E/flutter ( 1088): #0      MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:156
E/flutter ( 1088): <asynchronous suspension>
E/flutter ( 1088): #1      _invokeBooleanMethod (package:firebase_admob/firebase_admob.dart:612:23)

这是颤振医生命令的结果

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.0.2, on Microsoft Windows [Version 10.0.19042.746], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[√] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.8.3)
[√] Android Studio (version 4.1.0)
[√] IntelliJ IDEA Community Edition (version 2020.3)
[√] VS Code (version 1.54.3)
[√] Connected device (3 available)

! Doctor found issues in 1 category.

【问题讨论】:

您的应用是什么时候创建的?是新项目吗?此外,MissingPluginException 通常可以通过重建应用程序来修复。 我三个月前创建的新项目还有其他问题吗? 【参考方案1】:

我通过删除 android 文件夹解决了这个问题,然后运行以下命令 flutter create . 因为我发现了类似的问题 here 然后我根据 admob 的要求修改了 android 文件夹,之后我用广告测试了我的应用程序和它工作正常,但它给了我一些错误

Plugin project :firebase_core_web not found. Please update settings.gradle.

答案是通过像这样编辑本期here中的setting.gradle文件

include ':app'

def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()

def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) 
    pluginsFile.withReader('UTF-8')  reader -> plugins.load(reader) 


plugins.each  name, path ->
    def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
    include ":$name"
    project(":$name").projectDir = pluginDirectory

【讨论】:

以上是关于AAPT:错误:在 <manifest> 中发现了意外元素 <queries>。将 admob 广告添加到我的应用时出错的主要内容,如果未能解决你的问题,请参考以下文章

Flutter AAPT:错误:在 <manifest> 中发现了意外的元素 <appliation>

AAPT:错误:在 <manifest> 中发现了意外元素 <queries>。将 admob 广告添加到我的应用时出错

Android Studio 报出此错AAPT: error: unexpected element <intent-filter> found in <manifest><application>.

AAPT:错误:未绑定的前缀。在 XML 安卓中

我的错误“在 <manifest> 中发现了意外的元素 <queries>”,如何解决? [关闭]

AAPT 错误不匹配的标签到目前为止已经尝试了所有方法做错了啥