-
Notifications
You must be signed in to change notification settings - Fork 533
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
Proguard (R8) : A type variable is not in scope (Xamarin.Kotlin.StdLib + keepattributes Signature) #7008
Comments
@vyacheslav-volkov it looks like you would probably hit this same issue in a Java/Kotlin app in Android Studio? We redistribute Could you give some info about what you're trying to do? Thanks! |
I use a native library (kotlin) that uses gson package. Gson proguard.cfg requires
|
Maybe you can somehow specify |
I've tried but it looks like |
I checked a native Java/Kotlin application in Android Studio and it works with |
I'm having the same issue. But my build output doesn't contain which package is causing the problem. |
Hi @vyacheslav-volkov. Due to inactivity, we will be closing this issue. Please feel free to re-open this issue if the issue persists. For enhanced visibility, if over 7 days have passed, please open a new issue and link this issue there. Thank you. |
@jonathanpeppers I still have this issue and I'm currently blocked on my project because of this bug. Should I open a new one? |
@Macjon can you share a diagnostic MSBuild log of your issue? Or a sample project hitting it? Thanks! |
@jonathanpeppers this is the build log of my test project. https://gist.github.com/Macjon/a15676f9199fbf6779fe519256f9fa7e |
BuildError.zip It is a serious blocking issue for my company. @jonathanpeppers do you have any advice on how to workaround this? I cant remove the keepattributes Signature from the config because removing it causes a crash in the hms library at runtime |
Yeap, experiencing this one as well. Mine are these:
|
@jonathanpeppers we checked the r8 version that we are using in AppCenter where it builds successfully, the one that came with XA 12.0.0.3 works, while the latest doesn't. I will be glad if it helps |
I found out I'm facing the same exact issue when compiling an Android project on release mode and set the following configuration: The proguard.cfg file has the following content:
I am able to replicate the issue on Xamarin.Android 12.3.3.3 and 13.0.0.0. Update 1: It worked using Xamarin.Android 11.3.0.4 or 12.0.0.3 (just like our friend @themronion mentioned above) |
We have exactly the same problem with Hms library. -keepattribute Signature cannot be removed or it causes a crash at runtime. If you keep it, the application does not compile anymore. That's quite a blocking one. |
I downloaded Xamarin.Android 12.0, and pulled out Can you unzip this somewhere, and try using in a project, such as: <PropertyGroup>
<AndroidR8JarPath>/path/to/your/r8.jar</AndroidR8JarPath>
</PropertyGroup> If the problem is r8, I'm not sure what we can do? We can downgrade it? We're using the latest on maven: https://mvnrepository.com/artifact/com.android.tools/r8/3.3.28 And we should have dependabot setup to update it. |
Hello @jonathanpeppers. Somehow I though about "upgrading" r8 but not downgrading it. Still, it's a bit weird that it occurs only on Xamarin applications. |
Any updates on this one? We are currently keeping a pinned version of R8, which works, but doesn't look like the best solution. |
We took the newer version of Does it solve the problem? This will be in Xamarin.Android 13.1, but you could try these builds:
@deyupopp if you can share a minimal repro, we could see if we can port the sample to Java so we can report upstream to Google. |
@jonathanpeppers any info when XA 13.1 will be released? |
Awesome! I too have been battling trying to get a proguard ruleset as I was also having a global 'keep all of androidx' and trying to add Your rules are looking promising, but I've still got some dependencies. How did you manage to figure out all the references you needed to keep? I'm getting an odd one on our handling of photo picking
Its odd as its inside the activity namespace which is allready kept, trying to work out what steps you did to build that list to see if I can figure out what I need to re-add for this example |
Also - i'm tantalisingly close, its just that one class now for me to resolve with proguard 🤔 |
Oh, spotted it. Theres a typo in your example @alexanderdibenedetto ! activity is spelt wrong. However when correcting the spelling, more R8 error throw up - so think I need to drill down more into activity namespace similar to your core one 👍 |
-keep class androidx.activity.result.** { *; } Might be it 🤞 |
@jonathanpeppers I'm still facing this problem using net-8.0. I can't use the old r8 file which worked fine for net-7.0. Please help us find a solution or a workaround. I'm using a library that requires this proguard configuration:
And it always fails, there is no way to change proguard.cfg to avoid this problem. I tried a native project from Android Studio with this configuration and it works fine. Here are the simple steps to reproduce it:
I'm working on a large project with many dependencies and without r8 the size of the application will be large and there is no known way to solve this problem, someone from the xamarin team should check and find the reason why the same config is working from Android Studio but not working from Xamarin. |
@jonathanpeppers I run the similar project in android studio with the |
@vyacheslav-volkov both the
Do you know how we might tell the difference between a real error and one we should ignore such as the one mentioned here? Does it seem like we could look for |
@jonathanpeppers yes I think we should use
|
@jonathanpeppers any updates? as this is a critical issue for large applications, could you fix it in the next release and backport to net8.0? |
@jonathanpeppers |
@jonathanpeppers 1> Error in Command line: Or am I doing something wrong with the workaround? If I'm reading the log correctly then MSBuild appears to be finding my pinned R8.jar: Task "Error" skipped, due to false condition; ( !Exists('$(AndroidR8JarPath)') ) was evaluated as ( !Exists('/PeppersR8/r8.jar') ). Any help greatly appreciated, including any further workarounds. We really need to get this release out before 31/8. David |
@jonathanpeppers @dellis1972 any updates, should we expect a fix? |
For me, this issue is happening in net9-pre7 and net9-rc1. No issue in net9-pre6. |
@tranb3r We have identified a critical bug in the MSBuild task that needs to be addressed. Currently, the MSBuild task incorrectly interprets certain conditions as errors when they are not actually errors. Can you confirm whether this fix will be included in .NET 9.0? This is a highly critical issue, and it seems to be overlooked at the moment. @jonathanpeppers @dellis1972 @jonpryor |
I tried #7008 (comment) under .net9 preview 7 and it did not fail with any errors. Is this the correct sample to repo the issue? |
@dellis1972 please check this sample #7008 (comment) |
Looks like this might be caused by the default MSBuild error checking code. |
I'm having this issue as well, hope there is a fix soon! |
@dellis1972 any updates? |
This is being worked on #9298 |
Context #7008 (comment) When building with certain libraries we are seeing the following errors 4> Invalid signature '(TT;)TV;' for method java.lang.Object kotlin.jvm.internal.PropertyReference1.get(java.lang.Object). (TaskId:792) 4>R8 : Validation error : A type variable is not in scope. 4> Signature is ignored and will not be present in the output. (TaskId:792) 4> Info in ...\.nuget\packages\xamarin.kotlin.stdlib\1.6.20.1\buildTransitive\monoandroid12.0\..\..\jar\org.jetbrains.kotlin.kotlin-stdlib-1.6.20.jar:kotlin/jvm/internal/PropertyReference0.class: (TaskId:792) 4> Invalid signature '()TV;' for method java.lang.Object kotlin.jvm.internal.PropertyReference0.get(). (TaskId:792) 4>R8 : Validation error : A type variable is not in scope. If you look carefully these are Info messages not errors. It turns out the call to base.LogEventsFromTextOutput (singleLine, messageImportance); is also including the default MSBuild error processing. This is mistaking this output for actual errors. So lets get around this by NOT calling base.LogEventsFromTextOutput (singleLine, messageImportance);. So lets add a new meethod CheckForError which does the actual check. By default LogEventsFromTextOutput will call this and base.LogEventsFromTextOutput . However to R8 and D8 we override LogEventsFromTextOutput and only call CheckForError and Log.LogMessage. This fixing this issue. Add a unit test which covers the error case.
PR #9298 has been merged. So it will be in .net 9. |
Context #7008 (comment) When building with certain libraries we are seeing the following errors 4> Invalid signature '(TT;)TV;' for method java.lang.Object kotlin.jvm.internal.PropertyReference1.get(java.lang.Object). (TaskId:792) 4>R8 : Validation error : A type variable is not in scope. 4> Signature is ignored and will not be present in the output. (TaskId:792) 4> Info in ...\.nuget\packages\xamarin.kotlin.stdlib\1.6.20.1\buildTransitive\monoandroid12.0\..\..\jar\org.jetbrains.kotlin.kotlin-stdlib-1.6.20.jar:kotlin/jvm/internal/PropertyReference0.class: (TaskId:792) 4> Invalid signature '()TV;' for method java.lang.Object kotlin.jvm.internal.PropertyReference0.get(). (TaskId:792) 4>R8 : Validation error : A type variable is not in scope. If you look carefully these are Info messages not errors. It turns out the call to base.LogEventsFromTextOutput (singleLine, messageImportance); is also including the default MSBuild error processing. This is mistaking this output for actual errors. So lets get around this by NOT calling base.LogEventsFromTextOutput (singleLine, messageImportance);. So lets add a new meethod CheckForError which does the actual check. By default LogEventsFromTextOutput will call this and base.LogEventsFromTextOutput . However to R8 and D8 we override LogEventsFromTextOutput and only call CheckForError and Log.LogMessage. This fixing this issue. Add a unit test which covers the error case.
@dellis1972: was this finally released into a service release? |
Yes. |
@Picao84: Thanks. Do you know in which specific version? |
It's listed in the release notes: |
Android application type
Classic Xamarin.Android (MonoAndroid12.0, etc.)
Affected platform version
VS 2022 17.2.0
Description
A simple android project with a reference to Xamarin.Google.Android.Material package 1.6.0 and a proguard file with single line
-keepattributes Signature
fails.Steps to Reproduce
Did you find any workaround?
No response
Relevant log output
The text was updated successfully, but these errors were encountered: