android: Proguard (R8) : A type variable is not in scope (Xamarin.Kotlin.StdLib + keepattributes Signature)
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
- Install Xamarin.Google.Android.Material 1.6.0 package
- Add proguard.cfg with single line -keepattributes Signature
- Build project in release configuration with r8 code shrinker
Did you find any workaround?
No response
Relevant log output
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.
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/MutablePropertyReference2.class: (TaskId:792)
4> Invalid signature '(TD;TE;)TV;' for method java.lang.Object kotlin.jvm.internal.MutablePropertyReference2.get(java.lang.Object, 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/MutablePropertyReference2.class: (TaskId:792)
4> Invalid signature '(TD;TE;TV;)V' for method void kotlin.jvm.internal.MutablePropertyReference2.set(java.lang.Object, java.lang.Object, 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/MutablePropertyReference.class: (TaskId:792)
4> Invalid signature '()Lkotlin/reflect/KMutableProperty$Setter<TV;>;' for method kotlin.reflect.KMutableProperty$Setter kotlin.jvm.internal.MutablePropertyReference.getSetter(). (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/MutablePropertyReference.class: (TaskId:792)
4> Invalid signature '()Lkotlin/reflect/KProperty$Getter<TV;>;' for method kotlin.reflect.KProperty$Getter kotlin.jvm.internal.MutablePropertyReference.getGetter(). (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/PropertyReference2.class: (TaskId:792)
4> Invalid signature '(TD;TE;)TV;' for method java.lang.Object kotlin.jvm.internal.PropertyReference2.get(java.lang.Object, 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/MutablePropertyReference0.class: (TaskId:792)
4> Invalid signature '()TV;' for method java.lang.Object kotlin.jvm.internal.MutablePropertyReference0.get(). (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/MutablePropertyReference0.class: (TaskId:792)
4> Invalid signature '(TV;)V' for method void kotlin.jvm.internal.MutablePropertyReference0.set(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/MutablePropertyReference1.class: (TaskId:792)
4> Invalid signature '(TT;)TV;' for method java.lang.Object kotlin.jvm.internal.MutablePropertyReference1.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/MutablePropertyReference1.class: (TaskId:792)
4> Invalid signature '(TT;TV;)V' for method void kotlin.jvm.internal.MutablePropertyReference1.set(java.lang.Object, 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/PropertyReference.class: (TaskId:792)
4> Invalid signature '()Lkotlin/reflect/KProperty$Getter<TV;>;' for method kotlin.reflect.KProperty$Getter kotlin.jvm.internal.PropertyReference.getGetter(). (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)
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 5
- Comments: 70 (17 by maintainers)
Commits related to this issue
- Fix R8 Message processing to remove false positives. (#9298) Context #7008 (comment) When building with certain libraries we are seeing the following errors 4> Invalid signature '(TT;)TV;' for... — committed to dotnet/android by dellis1972 2 years ago
- Fix R8 Message processing to remove false positives. (#9298) Context #7008 (comment) When building with certain libraries we are seeing the following errors 4> Invalid signature '(TT;)TV;' for met... — committed to dotnet/android by dellis1972 2 years ago
Any progress here? Now the steps to reproduce are there.
@jonathanpeppers steps to reproduce:
proguard.cfgfilePR #9298 has been merged. So it will be in .net 9. I will talk it over with my boss to see if we can get this into a .net 8 service release.
Hi all,
I was finally able to solve this issue against .NET 7 Android with the latest r8 (8.1.56) with the following proguard.cfg and confirm the sample app launches (if anyone else would like to confirm). The main culprit (as above) in the r8 issue was related to some of the androidx.core.util.** libraries being kept with their signatures (which were invalid according to r8). By sort of painstakingly finding out all my androidx references instead of just keeping all androidx.** { *; }, I was able to solve any resulting runtime issues. Google Android Material itself wasn’t really the problem it just conveniently references the majority of the AndroidX support packages that r8 objected to. I think the reason this affected Xamarin Android so hard has to do with the proguard.cfg that Xamarin was including, but .NET Android doesn’t appear to be including the same ruleset. Anyway it would be great if other people could confirm if this works for them:
Here was the rule I had previously set that was causing me all the grief (and reproduces this issue):
-keep class androidx.** { *; }I downloaded Xamarin.Android 12.0, and pulled out
r8.jarfrom it: r8.zipCan you unzip this somewhere, and try using in a project, such as:
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.
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)
It’s listed in the release notes:
This is being worked on https://github.com/dotnet/android/pull/9298
This issue is blocking us. Any updates on a fix?
will it be fixed at some point?
Quarterly prompt? 😃
Hi @vyacheslav-volkov. We have added the “need-info” label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
The source code for r8 is here: https://r8.googlesource.com/r8
If someone would like to file an issue here, maybe Google would respond?
@AndrewNeuronation if you read the comments above, we are now looking for a sample project that hits this issue, so we can investigate further. Thanks!
Using the custom/old r8.jar workaround solves the problem for now.
Hello @jonathanpeppers. Somehow I though about “upgrading” r8 but not downgrading it. I can confirm that it fixed the issue. Thanks for this one !
Still, it’s a bit weird that it occurs only on Xamarin applications.
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.
BuildError.zip Here is my build log, I am getting the same error but it is coming from androidx.core.util.lrucache.
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