googleads / googleads-mobile-unity

Official Unity Plugin for the Google Mobile Ads SDK
https://developers.google.com/admob/unity
Apache License 2.0
1.34k stars 1.08k forks source link

why latest version always error #3198

Closed stickylab closed 3 months ago

stickylab commented 3 months ago

[REQUIRED] Step 1: Describe your environment

[REQUIRED] Step 2: Describe the problem

the problem is when i build the apk , it give me error like the screenshoot

image

image

image image image

Steps to reproduce:

to make the problem occured just simply import the latest project then use the latest sample , then build the apk

Relevant Code:

// TODO(you): code here to reproduce the problem
NVentimiglia commented 3 months ago

@stickylab

Downloading and configuring Android gradle dependencies can be difficult. There are ongoing issues specifically with older version of Unity which we talked about in our gradle update guide. I would recommend making sure that your android environment is set up correctly and seeing if you can get a Android gradle log of the issue.

VinceChimp commented 2 weeks ago

I am having the same issues, and looked through a ton of these old issues here. I have been working on it all day today. And half a day last week.

I have now tried a clean project, unity 2021, and 2022, clearing the gradle cache, clearing the library folder of the project, reboots, and the many suggestions online to various issues that seemed close enough to mine to try, everything.

I am basically pingponging between 3 or 4 different errors:

Either it fails to build with $actionFacade like this post. Or it fails to build because it can't find 'androidx.constraintlayout:constraintlayout:2.1.4' properly (being upset during linking it seems?) Or it builds perfectly fine, and then the startup of the SDK fails because a lot of code that should have been included can not be fines (java class not found)

Even if you explicitly set up a proguard giving it a blanket statement to com.google.** to just include all of it. Seems to make little difference. Likely because it somehow did compile, but still just doesn't have the actual library in the build. I can't find much else of an explanation.

And very rarely, it just works, and then after hitting build again IT MAGICALLY FAILS on one of these items again.

Force resolve sometimes magically makes it work, but again, only like once, and then it fails again.

I do not understand the android pipeline, i don't want to understand the pipeline, but i understood enough to at least try all the things i tried. What is going on with this library? Why is this all so difficult to set up, and why does nobody have a proper answer to this problem anywhere online? Everyone with one of the aforementioned problems start resorting to custom proguard mumbo-jumbo, and manual includes, overrides, hope, and prayers.

If i can't make a single consistent build, how can i expect it to not crash my build pipeline every other day?

vinkini commented 2 weeks ago

You are right in running Force Resolve to fix the dependency issues. Starting v1.2.179 of the External Dependency Manager, it uses Android's gradle for dependency management rather than resolving by itself. It does so by including the dependencies in the mainTemplate.gradle file under Assets > Plugins > Android. Checking this file has the following line: implementation 'androidx.constraintlayout:constraintlayout:2.1.4' will ensure you don't run into this issue again.

VinceChimp commented 2 weeks ago

Even though i have done that, i am not at all convinced that this actually solves the problem, because it will then just run into runtime issues, where it fails to find any of the java classes. Maybe i should go back to external dependency manager 1.2.178 then. Who would introduce such a breaking change and not increment the minor or mayor version number?

VinceChimp commented 2 weeks ago

Oh yeah and if i were to add this dumb manual override to "fix the resolver not resolving anything" the resolver also forgets to properly inject "use jetifier and use android x" so it still fails. So if i ALSO manually override that in the gradle template properties, i now can build, but at runtime calling initialize just does this:

2024/06/11 10:19:53.009 26781 26835 Error Unity AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.ads.initialization.OnInitializationCompleteListener 2024/06/11 10:19:53.009 26781 26835 Error Unity java.lang.ClassNotFoundException: com.google.android.gms.ads.initialization.OnInitializationCompleteListener 2024/06/11 10:19:53.009 26781 26835 Error Unity at java.lang.Class.classForName(Native Method) 2024/06/11 10:19:53.009 26781 26835 Error Unity at java.lang.Class.forName(Class.java:536) 2024/06/11 10:19:53.009 26781 26835 Error Unity at com.unity3d.player.UnityPlayer.nativeRender(Native Method)

As you can see, we are really making headway by doing the auto resolver's job for it. It's going great.