Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] [Android] Kotlin error on Unity 2021.3.41f1 #703

Closed
victor-kallai opened this issue Aug 4, 2024 · 15 comments
Closed

[Bug] [Android] Kotlin error on Unity 2021.3.41f1 #703

victor-kallai opened this issue Aug 4, 2024 · 15 comments
Labels
needs-attention Need Googler's attention type: bug

Comments

@victor-kallai
Copy link

victor-kallai commented Aug 4, 2024

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2021.3.41f1
  • External Dependency Manager version: 1.2.182
  • Source you installed EDM4U: UMP
  • Features in External Dependency Manager in use: Android Resolver
  • Plugins SDK in use: Firebase 12.1.0, Admob, Facebook, GoogleSignIn, GoogleMobileAds
  • Platform you are using the Unity editor on: Windows

[REQUIRED] Please describe the issue here:

I'm raising this issue for better visibility. I know you are already aware of this issue from [here].(#699 (comment))

When building on Android with Unity 1.2.182 the build fails with ERROR:D8: com.android.tools.r8.kotlin.H.
The temporary fix is to change the minSdkVersion from 22 to 24, but that is not desirable.

I have in the project Firebase 12.1.0, Admob, Facebook, GoogleSignIn, GoogleMobileAds.

Please answer the following, if applicable:

What's the issue repro rate? 100%

What happened? How can we make the problem occur?
apk build fail with error:
ERROR:D8: com.android.tools.r8.kotlin.H

@argzdev argzdev removed the new to be triaged label Aug 5, 2024
@argzdev
Copy link
Collaborator

argzdev commented Aug 5, 2024

Thanks for bringing this up, @victor-kallai. Yeah, that's interesting, the AGP versions should be independent of the minSdkVersion, so the new changes shouldn't affect this, but looks like this isn't the case. We'll investigate this more and come back here once we have updates to share.

@vladyslav-androshchuk
Copy link

@argzdev Hello! I'm sure you guys working on your maximum, but is it there any status update?

Deadline for Google Play is August 31 to increase the target SDK to v34. We managed to build the project with 2021.3.42f1 and min SDK 24, but increasing min version is almost not possible in our case, due to big amount of users on that versions.

@argzdev
Copy link
Collaborator

argzdev commented Aug 8, 2024

Sorry, we're still investigating this, @vladyslav-androshchuk.

While waiting for a fix, regarding the deadline for Google Play, you may request an extension as discussed in the Unity forum:

The deadline for targeting API 34 is August 31 - what if I don’t have enough time?

  • We have informed Google about the impact of this AGP issue to Unity Creators. You are allowed to request an extension until November using the usual Google Play Console / Policy pages 16. Usually this opens around the beginning of August. Please mention Unity 2021 and AGP/Legacy Library issues in your extension request.

@vladyslav-androshchuk
Copy link

Sorry, we're still investigating this, @vladyslav-androshchuk.

While waiting for a fix, regarding the deadline for Google Play, you may request an extension as discussed in the Unity forum:

The deadline for targeting API 34 is August 31 - what if I don’t have enough time?

  • We have informed Google about the impact of this AGP issue to Unity Creators. You are allowed to request an extension until November using the usual Google Play Console / Policy pages 16. Usually this opens around the beginning of August. Please mention Unity 2021 and AGP/Legacy Library issues in your extension request.

Thank you! We'll make request for all our apps.

@argzdev
Copy link
Collaborator

argzdev commented Aug 9, 2024

I did a bit of testing, and I noticed something odd. Whenever I export the project, and open it in Android Studio, the issue goes away. With a little bit of tinkering around in the Unity Editor settings, I noticed that enabling Project Settings > Publishing Settings > Minify > Release/Debug somehow corrects this issue.

I believe the underlying cause could be that the r8 tool with this version of AGP might be faulty.
Let me know if this workaround helps!

@argzdev argzdev added the needs-info Need information for the developer label Aug 9, 2024
@RaulLpg
Copy link

RaulLpg commented Aug 11, 2024

I did a bit of testing, and I noticed something odd. Whenever I export the project, and open it in Android Studio, the issue goes away. With a little bit of tinkering around in the Unity Editor settings, I noticed that enabling Project Settings > Publishing Settings > Minify > Release/Debug somehow corrects this issue.

I believe the underlying cause could be that the r8 tool with this version of AGP might be faulty. Let me know if this workaround helps!

Just tried this and it worked! even keeping min api SDK to 22 :D

Thanks a lot for taking the time with this, really helped!

@DevSean
Copy link

DevSean commented Aug 13, 2024

I did a bit of testing, and I noticed something odd. Whenever I export the project, and open it in Android Studio, the issue goes away. With a little bit of tinkering around in the Unity Editor settings, I noticed that enabling Project Settings > Publishing Settings > Minify > Release/Debug somehow corrects this issue.

I believe the underlying cause could be that the r8 tool with this version of AGP might be faulty. Let me know if this workaround helps!

Unfortunately, this work around does not work for us. Our binary builds and runs but only shows a black screen after the initial splash screen.

@argzdev
Copy link
Collaborator

argzdev commented Aug 13, 2024

Hi @DevSean, could you share your stacktrace so we can investigate this further? Also any chance you could share an MCVE, it'll help us out a lot investigating this issue.

@DevSean
Copy link

DevSean commented Aug 13, 2024

Hi @argzdev, we don’t actually use Unity-jar-resolver internally, we export to Android studio and then build from there (so no MCVE).

We are seeing the same r8 error:
ERROR:D8: com.android.tools.r8.kotlin.H

Additionally, changing the minimum sdk version does work (certainly not an ideal solution).

As you mentioned, I believe this is the actual issue:

I believe the underlying cause could be that the r8 tool with this version of AGP might be faulty.

As for the minify errors, the game is (unsurprisingly) unable to find specific classes as they have been stripped.

My company has opened a premium support ticket with Unity regarding this issue, if there are any updates I’ll happily share them here.

@argzdev
Copy link
Collaborator

argzdev commented Aug 13, 2024

Thanks for the additional information, @DevSean. From my testing, the ERROR:D8: com.android.tools.r8.kotlin.H is only present when using AGP 7.4.2 and Gradle 7.5.1 (This is the version that is tied up with the Unity Editor 2021 and 2022). Since you've exported your project, you could try using the Tools > AGP Upgrade Assistant from the menu section of Android Studio, which will update your AGP and Gradle to version 8+ onwards. I believe that should resolve your issue without the need to enable minify.

@DevSean
Copy link

DevSean commented Aug 13, 2024

@argzdev Thanks for the suggestion, I had considered manually increasing the template versions to see if the issue gets resolved, previously we were able to build targeting API 34 with an older Unity version and an older Gradle version.

For obvious reasons we would prefer to match the versions provided by Unity if possible.

Either way, I hope this all gets resolved soon. Thank you for your investigations and findings also.

@RaulLpg
Copy link

RaulLpg commented Aug 13, 2024

Hi @argzdev, we don’t actually use Unity-jar-resolver internally, we export to Android studio and then build from there (so no MCVE).

We are seeing the same r8 error: ERROR:D8: com.android.tools.r8.kotlin.H

Additionally, changing the minimum sdk version does work (certainly not an ideal solution).

As you mentioned, I believe this is the actual issue:

I believe the underlying cause could be that the r8 tool with this version of AGP might be faulty.

As for the minify errors, the game is (unsurprisingly) unable to find specific classes as they have been stripped.

My company has opened a premium support ticket with Unity regarding this issue, if there are any updates I’ll happily share them here.

After I enabled minify debug/release we also had runtime errors for missing classes.

I didn't mention it in my previous post but you probably need to add a custom proguard file to prevent those classes from being stripped.

Project settings -> Player (Android) -> Custom Proguard File

And depending on what classes are missing you will have to add them. For me it was regarding google ads and ump so I added :


-keep public class com.google.android.ump.**{
   public *;
}

-keep class com.google.unity.** {
   *;
}

-keep public class com.google.android.gms.ads.**{
   public *;
}

-keep public class com.google.ads.**{
   public *;
}

You might be already aware of this and your error might be something else, but just incase someone else finds this

@victor-kallai
Copy link
Author

@argzdev Thank you for the fix, enabling the Project Settings > Publishing Settings > Minify > Release works.

Setting the minSdkVersion to 22 is still not possible due to Firebase 12.2.0 requiring at least version 23, here is the known issue.

But I'm happy that it works with minSdkVersion 23.

To not have any classes stripped by proguard I set this in the custom proguard-users.txt as a quick fix.

-dontobfuscate
-dontshrink
-dontoptimize

# Keep all classes
-keep class ** { *; }

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Aug 15, 2024
@argzdev
Copy link
Collaborator

argzdev commented Aug 16, 2024

Awesome, glad that works @victor-kallai. Thanks for sharing your update and extra details for the fix!

Since the r8 tooling is embedded in this version of AGP, we can only rely on this workaround until the AGP and Gradle version is raised to version 8+, which isn't anytime soon. That said, there's not much we can do on the unity-jar-resolver side.

I'll go ahead and close this thread for now. If anyone has better mitigations, feel free to share! Thanks!

@argzdev argzdev closed this as completed Aug 16, 2024
@manugildev
Copy link

manugildev commented Aug 19, 2024

In case it helps someone, this is another workaround that can be tried:

  1. Create a custom baseProjectTemplate.gradle
    • Player Settings > Publishing > Create Custom Base Gradle Template
  2. Open newly created Assets/Plugins/Android/baseProjectTemplate.gradle.
  3. Force use of a newer r8 version
buildscript {
    repositories {
        maven {
            url = uri("https://storage.googleapis.com/r8-releases/raw")
        }
    }
    dependencies {
        classpath("com.android.tools:r8:8.3.37")
    }
}

source: https://stackoverflow.com/a/78795333

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-attention Need Googler's attention type: bug
Projects
None yet
Development

No branches or pull requests

7 participants