googleads / googleads-mobile-flutter

A Flutter plugin for the Google Mobile Ads SDK
Apache License 2.0
341 stars 286 forks source link

Missing Class in google_mobile_ads: androidx.appcompat.widget.AppCompatButton not Found #1194

Open vacating opened 5 days ago

vacating commented 5 days ago

The issue arises when using the google_mobileads. During the build process, a layout file (gnt medium_template_view.xml) references the androidx.appcompat.widget.AppCompatButton class. However, this class is not found in the project or the libraries, resulting in the error: i didnt use any layout in native side what so ever. am using pure dart.
@malandr2


[REQUIRED] Step 1: Describe your environment

Flutter (Channel stable, 3.24.3, locale en-US) • Flutter version 3.24.3 on channel stable • Framework revision 2663184aa7 (5 weeks ago), 2024-09-11 • Engine revision 36335019a8 • Dart version 3.5.3 • DevTools version 2.37.3

Plugin Version

google_mobile_ads: ^5.2.0

[REQUIRED] Step 2: Describe the problem

after running build the ./gradlew build i get the error following error:

Error: Class referenced in the layout file, androidx.appcompat.widget.AppCompatButton, was not found in the project or the libraries [MissingClass]

C:\Users\Pc\AppData\Local\Pub\Cache\hosted\pub.dev\google_mobile_ads-5.2.0\android\src\main\res\layout\gnt_medium_template_view.xml:207: Error: Class referenced in the layout file, androidx.appcompat.widget.AppCompatButton, was not found in the project or the libraries [MissingClass] <androidx.appcompat.widget.AppCompatButton ^

note:

Analyzing the Dependency Tree:

probability:

Multiple versions of androidx.appcompat:appcompat are being referenced, specifically version 1.7.0 and 1.2.0.

`+--- androidx.appcompat:appcompat:1.2.0 -> 1.7.0

Some dependencies might be bringing in older or conflicting versions of appcompat.

The google_mobile_ads plugin is using a layout file (gnt_medium_template_view.xml) that references AppCompatButton.

second topper issue:

Task :google_mobile_ads:processDebugManifest package="io.flutter.plugins.googlemobileads" found in source AndroidManifest.xml: C:\Users\Pc\AppData\Local\Pub\Cache\hosted\pub.dev\google_mobile_ads-5.2.0\android\src\main\AndroidManifest.xml. Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported, and the value is ignored. Recommendation: remove package="io.flutter.plugins.googlemobileads" from the source AndroidManifest.xml: C:\Pc\AppData\Local\Pub\Cache\hosted\pub.dev\google_mobile_ads-5.2.0\android\src\main\AndroidManifest.xml.

when i do flutter run i get this:

Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: C:\Users\Pc\AppData\Local\Pub\Cache\hosted\pub.dev\google_mobile_ads-5.2.0\android\src\main\java\io\flutter\plugins\googlemobileads\AdMessageCodec.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details.

`

Steps to Reproduce

  1. Add google_mobile_ads package to your Flutter project:

  2. Ensure that you have the google_mobile_ads version 5.2.0 in your pubspec.yaml file under dependencies.

  3. Run flutter pub get to install the dependencies.

  4. Set up Android dependencies:

  5. Verify that your project includes the necessary Android dependencies like androidx.appcompat:appcompat.

  6. Create or build your Flutter project:

  7. Run flutter build to compile the project.

  8. Encounter the Error:

  9. The error should occur during the build process, where you will see the message related to the missing class:

  10. Error: Class referenced in the layout file, androidx.appcompat.widget.AppCompatButton, was not found in the project or the libraries [MissingClass]

  11. Check the gnt_medium_template_view.xml:

  12. The error originates from a layout file within the google_mobile_ads package, referencing AppCompatButton, which is missing from the dependencies.

    Run ./gradlew clean build.

Expected results: The project should build successfully without any missing class errors Actual results: Error: Class referenced in the layout file, androidx.appcompat.widget.AppCompatButton, was not found in the project or the libraries [MissingClass]

``` Logs C:\Users\Pc\AppData\Local\Pub\Cache\hosted\pub.dev\google_mobile_ads-5.2.0\android\src\main\res\layout\gnt_medium_template_view.xml:207: Error: Class referenced in the layout file, androidx.appcompat.widget.AppCompatButton, was not found in the project or the libraries [MissingClass] ``` ``` Flutter (Channel stable, 3.24.3, locale en-US) • Flutter version 3.24.3 on channel stable • Framework revision 2663184aa7 (5 weeks ago), 2024-09-11 • Engine revision 36335019a8 • Dart version 3.5.3 • DevTools version 2.37.3 [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Platform android-34, build-tools 34.0.0 • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11) • All Android licenses accepted. [√] Chrome - develop for the web [!] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.5) • Missing components: MSVC v142 - VS 2019 C++ x64/x86 build tools, C++ CMake tools for Windows, Windows 10 SDK [√] Android Studio (version 2024.2) • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11) [√] VS Code (version 1.94.2) [√] Connected device (4 available) ``` ```
malandr2 commented 3 days ago

Hi @vacating, I tried to follow your steps using the BannerExample in the repo but was able to run the project just fine. Are you able to? I'm using a Pixel 4 API 34.

Have you tried invalidating the cache and restarting?

vacating commented 3 days ago

hi @malandr2 pls Bear in mind that solely running ./gradlew build throws mentioned error. i just now came across similar issue and solution over here

using pixel 4 api 29

but still after flutter run i get this the following error:

Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: C:\Users\Pc\AppData\Local\Pub\Cache\hosted\pub.dev\google_mobile_ads-5.2.0\android\src\main\java\io\flutter\plugins\googlemobileads\AdMessageCodec.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details.

i did that too "invalidating the cache and restarting" but still the same issue after flutter run:

looking at my current set ups the only major issues are with transitive packages where i have no idea how the am going to solve that, would that cuz the issue?

Screenshot (661)

malandr2 commented 2 days ago

Hi @vacating, glad to see you found a viable solution.

For the warning you've mentioned, it's just a deprecation warning. The google_mobile_ads plugin is referencing code that's now deprecated. There's nothing you need to do on your end. This will be resolved in a future release.

vacating commented 2 days ago

Hello @malandr2 Thank you for clarifying the deprecation.

However, I have a question regarding transitive packages. It might not be the right place to ask about other packages, but in your view, how should I approach fixing these transitive packages? I've been waiting for an update for two months. Should I take matters into my own hands and resolve them, or wait for an official update? I’d appreciate your input.

kind regard.

malandr2 commented 1 day ago

Hi @vacating, it depends on the package and the impact it has on your app. There might be a reason the package hasn't updated it's immediate dependency yet due to incompatibility reasons. But if you must manually update, proceed with caution when doing so. I would also recommend reaching out to the owner of that package

vacating commented 1 day ago

hello @malandr2

one of the issue that is being caused is from google_mobile_ads 5.2.0

steps to produce:

dependencies:
  flutter:
    sdk: flutter
  google_mobile_ads: ^5.2.0
  webview_flutter_android: ^4.0.0

OUTPUT: After Flutter Pub Get / Flutter Pub Outdated

> `Because google_mobile_ads 5.2.0 depends on webview_flutter_android ^3.15.0 and no versions of google_mobile_ads match >5.2.0 <6.0.0, google_mobile_ads ^5.2.0 requires webview_flutter_android ^3.15.0. So, because EXAMPLEAPP depends on both google_mobile_ads ^5.2.0 and webview_flutter_android ^4.0.0, version solving failed.

malandr2 commented 21 hours ago

Hi @vacating, got it. You can manually update but proceed with caution when doing so. We will take a look at updating that immediate dependency in a future release.