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

Proguard (R8) : A type variable is not in scope (Xamarin.Kotlin.StdLib + keepattributes Signature) #7008

Open
vyacheslav-volkov opened this issue May 17, 2022 · 70 comments
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects.

Comments

@vyacheslav-volkov
Copy link

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)
@vyacheslav-volkov vyacheslav-volkov added Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned. labels May 17, 2022
@jonathanpeppers
Copy link
Member

@vyacheslav-volkov it looks like you would probably hit this same issue in a Java/Kotlin app in Android Studio?

We redistribute r8.jar from Google, and it looks like they are printing this error due to -keepattributes Signature.

Could you give some info about what you're trying to do? Thanks!

@jonathanpeppers jonathanpeppers added need-info Issues that need more information from the author. and removed needs-triage Issues that need to be assigned. labels May 18, 2022
@jonathanpeppers jonathanpeppers added this to the Under Consideration milestone May 18, 2022
@vyacheslav-volkov
Copy link
Author

vyacheslav-volkov commented May 18, 2022

I use a native library (kotlin) that uses gson package. Gson proguard.cfg requires -keepattributes Signature to work with generic without it I get this message: java.lang.RuntimeException: Missing type parameter

Gson uses generic type information stored in a class file when working with fields. Proguard removes such information by default, so configure it to keep all of it.
-keepattributes Signature

@jonathanpeppers
Copy link
Member

Maybe you can somehow specify -keepattributes Signature and skip the kotlin.jvm.* package? So you apply the rule for most types, but not the ones above that cause an error?

@vyacheslav-volkov
Copy link
Author

I've tried but it looks like -keepattributes doesn't support filters. I'll try with a native Java/Kotlin app in Android Studio and let you know if it works.

@vyacheslav-volkov
Copy link
Author

I checked a native Java/Kotlin application in Android Studio and it works with -keepattributes Signature and com.google.android.material:material:1.6.0. I can build release apk without any errors

@Macjon
Copy link

Macjon commented May 25, 2022

I'm having the same issue. But my build output doesn't contain which package is causing the problem.

@ghost
Copy link

ghost commented Jun 1, 2022

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.

@ghost ghost closed this as completed Jun 1, 2022
@Macjon
Copy link

Macjon commented Jun 15, 2022

@jonathanpeppers I still have this issue and I'm currently blocked on my project because of this bug. Should I open a new one?

@jonathanpeppers jonathanpeppers removed the need-info Issues that need more information from the author. label Jun 15, 2022
@jonathanpeppers
Copy link
Member

@Macjon can you share a diagnostic MSBuild log of your issue? Or a sample project hitting it? Thanks!

@Macjon
Copy link

Macjon commented Jun 16, 2022

@jonathanpeppers this is the build log of my test project. https://gist.github.com/Macjon/a15676f9199fbf6779fe519256f9fa7e

@MarnusStoop
Copy link

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

@themronion
Copy link

Yeap, experiencing this one as well. Mine are these:

R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\161\jl\bin\classes.jar:com/google/android/gms/internal/places/zzdg.class: (TaskId:960)
11>  Invalid signature '()Ljava/util/Iterator<Ljava/util/Map$Entry<TK;TV;>;>;' for method java.util.Iterator com.google.android.gms.internal.places.zzdg.iterator(). (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\145\jl\bin\classes.jar:com/google/android/gms/internal/gtm/zztd.class: (TaskId:960)
11>  Invalid signature 'Lcom/google/android/gms/internal/gtm/zztc<TFieldDescriptorType;Ljava/lang/Object;>;' for class com.google.android.gms.internal.gtm.zztd. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\161\jl\bin\classes.jar:com/google/android/gms/internal/places/zzde.class: (TaskId:960)
11>  Invalid signature 'Lcom/google/android/gms/internal/places/zzdb<TFieldDescriptorType;Ljava/lang/Object;>;' for class com.google.android.gms.internal.places.zzde. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\145\jl\bin\classes.jar:com/google/android/gms/internal/gtm/zzte.class: (TaskId:960)
11>  Invalid signature 'Ljava/lang/Object;Ljava/util/Iterator<Ljava/util/Map$Entry<TK;TV;>;>;' for class com.google.android.gms.internal.gtm.zzte. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\145\jl\bin\classes.jar:com/google/android/gms/internal/gtm/zzte.class: (TaskId:960)
11>  Invalid signature '()Ljava/util/Iterator<Ljava/util/Map$Entry<TK;TV;>;>;' for method java.util.Iterator com.google.android.gms.internal.gtm.zzte.zzrf(). (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\145\jl\bin\classes.jar:com/google/android/gms/internal/gtm/zzte.class: (TaskId:960)
11>  Invalid signature 'Ljava/util/Iterator<Ljava/util/Map$Entry<TK;TV;>;>;' for field java.util.Iterator com.google.android.gms.internal.gtm.zzte.zzbee. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\161\jl\bin\classes.jar:com/google/android/gms/internal/places/zzdd.class: (TaskId:960)
11>  Invalid signature 'Ljava/lang/Object;Ljava/util/Iterator<Ljava/util/Map$Entry<TK;TV;>;>;' for class com.google.android.gms.internal.places.zzdd. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\161\jl\bin\classes.jar:com/google/android/gms/internal/places/zzdd.class: (TaskId:960)
11>  Invalid signature '()Ljava/util/Iterator<Ljava/util/Map$Entry<TK;TV;>;>;' for method java.util.Iterator com.google.android.gms.internal.places.zzdd.zzde(). (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\161\jl\bin\classes.jar:com/google/android/gms/internal/places/zzdd.class: (TaskId:960)
11>  Invalid signature 'Ljava/util/Iterator<Ljava/util/Map$Entry<TK;TV;>;>;' for field java.util.Iterator com.google.android.gms.internal.places.zzdd.zzlz. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\145\jl\bin\classes.jar:com/google/android/gms/analytics/zzm.class: (TaskId:960)
11>  Invalid signature 'Ljava/util/concurrent/FutureTask<TT;>;' for class com.google.android.gms.analytics.zzm. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\145\jl\bin\classes.jar:com/google/android/gms/internal/gtm/zztl.class: (TaskId:960)
11>  Invalid signature 'Ljava/util/AbstractSet<Ljava/util/Map$Entry<TK;TV;>;>;' for class com.google.android.gms.internal.gtm.zztl. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\145\jl\bin\classes.jar:com/google/android/gms/internal/gtm/zztl.class: (TaskId:960)
11>  Invalid signature '()Ljava/util/Iterator<Ljava/util/Map$Entry<TK;TV;>;>;' for method java.util.Iterator com.google.android.gms.internal.gtm.zztl.iterator(). (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\145\jl\bin\classes.jar:com/google/android/gms/internal/gtm/zztj.class: (TaskId:960)
11>  Invalid signature 'Ljava/lang/Object;Ljava/lang/Comparable<Lcom/google/android/gms/internal/gtm/zztj;>;Ljava/util/Map$Entry<TK;TV;>;' for class com.google.android.gms.internal.gtm.zztj. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\145\jl\bin\classes.jar:com/google/android/gms/internal/gtm/zztj.class: (TaskId:960)
11>  Invalid signature '(Ljava/util/Map$Entry<TK;TV;>;)V' for method void com.google.android.gms.internal.gtm.zztj.<init>(com.google.android.gms.internal.gtm.zztc, java.util.Map$Entry). (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\145\jl\bin\classes.jar:com/google/android/gms/internal/gtm/zztj.class: (TaskId:960)
11>  Invalid signature '(TK;TV;)V' for method void com.google.android.gms.internal.gtm.zztj.<init>(com.google.android.gms.internal.gtm.zztc, java.lang.Comparable, java.lang.Object). (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\145\jl\bin\classes.jar:com/google/android/gms/internal/gtm/zztj.class: (TaskId:960)
11>  Invalid signature '()TV;' for method java.lang.Object com.google.android.gms.internal.gtm.zztj.getValue(). (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\145\jl\bin\classes.jar:com/google/android/gms/internal/gtm/zztj.class: (TaskId:960)
11>  Invalid signature '(TV;)TV;' for method java.lang.Object com.google.android.gms.internal.gtm.zztj.setValue(java.lang.Object). (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\145\jl\bin\classes.jar:com/google/android/gms/internal/gtm/zztj.class: (TaskId:960)
11>  Invalid signature 'TK;' for field java.lang.Comparable com.google.android.gms.internal.gtm.zztj.zzbei. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\145\jl\bin\classes.jar:com/google/android/gms/internal/gtm/zztj.class: (TaskId:960)
11>  Invalid signature 'TV;' for field java.lang.Object com.google.android.gms.internal.gtm.zztj.value. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\161\jl\bin\classes.jar:com/google/android/gms/internal/places/zzdm.class: (TaskId:960)
11>  Invalid signature 'Ljava/util/AbstractSet<Ljava/util/Map$Entry<TK;TV;>;>;' for class com.google.android.gms.internal.places.zzdm. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\161\jl\bin\classes.jar:com/google/android/gms/internal/places/zzdm.class: (TaskId:960)
11>  Invalid signature '()Ljava/util/Iterator<Ljava/util/Map$Entry<TK;TV;>;>;' for method java.util.Iterator com.google.android.gms.internal.places.zzdm.iterator(). (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\145\jl\bin\classes.jar:com/google/android/gms/internal/gtm/zztk.class: (TaskId:960)
11>  Invalid signature 'Ljava/lang/Object;Ljava/util/Iterator<Ljava/util/Map$Entry<TK;TV;>;>;' for class com.google.android.gms.internal.gtm.zztk. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\145\jl\bin\classes.jar:com/google/android/gms/internal/gtm/zztk.class: (TaskId:960)
11>  Invalid signature '()Ljava/util/Iterator<Ljava/util/Map$Entry<TK;TV;>;>;' for method java.util.Iterator com.google.android.gms.internal.gtm.zztk.zzrf(). (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\145\jl\bin\classes.jar:com/google/android/gms/internal/gtm/zztk.class: (TaskId:960)
11>  Invalid signature 'Ljava/util/Iterator<Ljava/util/Map$Entry<TK;TV;>;>;' for field java.util.Iterator com.google.android.gms.internal.gtm.zztk.zzbee. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\161\jl\bin\classes.jar:com/google/android/gms/internal/places/zzdj.class: (TaskId:960)
11>  Invalid signature 'Ljava/lang/Object;Ljava/util/Iterator<Ljava/util/Map$Entry<TK;TV;>;>;' for class com.google.android.gms.internal.places.zzdj. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\161\jl\bin\classes.jar:com/google/android/gms/internal/places/zzdj.class: (TaskId:960)
11>  Invalid signature '()Ljava/util/Iterator<Ljava/util/Map$Entry<TK;TV;>;>;' for method java.util.Iterator com.google.android.gms.internal.places.zzdj.zzde(). (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\161\jl\bin\classes.jar:com/google/android/gms/internal/places/zzdj.class: (TaskId:960)
11>  Invalid signature 'Ljava/util/Iterator<Ljava/util/Map$Entry<TK;TV;>;>;' for field java.util.Iterator com.google.android.gms.internal.places.zzdj.zzlz. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\161\jl\bin\classes.jar:com/google/android/gms/internal/places/zzdk.class: (TaskId:960)
11>  Invalid signature 'Ljava/lang/Object;Ljava/lang/Comparable<Lcom/google/android/gms/internal/places/zzdk;>;Ljava/util/Map$Entry<TK;TV;>;' for class com.google.android.gms.internal.places.zzdk. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\161\jl\bin\classes.jar:com/google/android/gms/internal/places/zzdk.class: (TaskId:960)
11>  Invalid signature '(Ljava/util/Map$Entry<TK;TV;>;)V' for method void com.google.android.gms.internal.places.zzdk.<init>(com.google.android.gms.internal.places.zzdb, java.util.Map$Entry). (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\161\jl\bin\classes.jar:com/google/android/gms/internal/places/zzdk.class: (TaskId:960)
11>  Invalid signature '(TK;TV;)V' for method void com.google.android.gms.internal.places.zzdk.<init>(com.google.android.gms.internal.places.zzdb, java.lang.Comparable, java.lang.Object). (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\161\jl\bin\classes.jar:com/google/android/gms/internal/places/zzdk.class: (TaskId:960)
11>  Invalid signature '()TV;' for method java.lang.Object com.google.android.gms.internal.places.zzdk.getValue(). (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\161\jl\bin\classes.jar:com/google/android/gms/internal/places/zzdk.class: (TaskId:960)
11>  Invalid signature '(TV;)TV;' for method java.lang.Object com.google.android.gms.internal.places.zzdk.setValue(java.lang.Object). (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\161\jl\bin\classes.jar:com/google/android/gms/internal/places/zzdk.class: (TaskId:960)
11>  Invalid signature 'TK;' for field java.lang.Comparable com.google.android.gms.internal.places.zzdk.zzme. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)
11>  Info in obj\Release\120\lp\161\jl\bin\classes.jar:com/google/android/gms/internal/places/zzdk.class: (TaskId:960)
11>  Invalid signature 'TV;' for field java.lang.Object com.google.android.gms.internal.places.zzdk.value. (TaskId:960)
11>R8 : Validation error : A type variable is not in scope.
11>  Signature is ignored and will not be present in the output. (TaskId:960)

@themronion
Copy link

@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

@vsimplea
Copy link

vsimplea commented Jul 25, 2022

I found out I'm facing the same exact issue when compiling an Android project on release mode and set the following configuration:
image

The proguard.cfg file has the following content:

# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all this information.
-keepattributes Signature

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)

@johnthiriet
Copy link

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.

@jonathanpeppers
Copy link
Member

I downloaded Xamarin.Android 12.0, and pulled out r8.jar from it: r8.zip

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.

@johnthiriet
Copy link

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.

@deyupopp
Copy link

Any updates on this one? We are currently keeping a pinned version of R8, which works, but doesn't look like the best solution.

@jonathanpeppers
Copy link
Member

We took the newer version of r8 here: 4defba2

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.

@PavloLukianets
Copy link

@jonathanpeppers any info when XA 13.1 will be released?

@jpobst jpobst removed the need-attention A xamarin-android contributor needs to review label Mar 20, 2024
@IainS1986
Copy link

@alexanderdibenedetto

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 -keepattributes Signature

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

Didn't find class "androidx.activity.result.contract.ActivityResultContracts$PickVisualMedia"

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

@IainS1986
Copy link

Also - i'm tantalisingly close, its just that one class now for me to resolve with proguard 🤔

@IainS1986
Copy link

Oh, spotted it. Theres a typo in your example @alexanderdibenedetto !
-keep class androidx.activitiy.** { *; }

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 👍

@IainS1986
Copy link

-keep class androidx.activity.result.** { *; }

Might be it 🤞

@vyacheslav-volkov
Copy link
Author

@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:

-keepattributes Signature

-keep class kotlinx.coroutines.channels.** { *; }

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:

  1. create a new android project
  2. change .csproj:
<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>net8.0-android</TargetFramework>
        <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
        <OutputType>Exe</OutputType>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <ApplicationId>com.companyname.AndroidAppR8</ApplicationId>
        <ApplicationVersion>1</ApplicationVersion>
        <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
        <AndroidLinkTool>r8</AndroidLinkTool>
        <RunAOTCompilation>false</RunAOTCompilation>
        <AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
    </PropertyGroup>
    
    <ItemGroup>
        <ProguardConfiguration Include="proguard.cfg" />
    </ItemGroup>
    
    <ItemGroup>
      <PackageReference Include="Xamarin.KotlinX.Coroutines.Android" Version="1.8.1.1" />
    </ItemGroup>
</Project>
  1. add the proguard.cfg file
-keepattributes Signature

-keep class kotlinx.coroutines.channels.** { *; }
  1. try compiling in release mode and you will get the errors.

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.

@vyacheslav-volkov
Copy link
Author

vyacheslav-volkov commented Jul 15, 2024

@jonathanpeppers I run the similar project in android studio with the --info flag and saw that in the android studio log the error is exactly the same, but it turns out that they ignore it, because the build is successful and the .apk file is generated, it looks like we can just ignore these errors.

@jonathanpeppers
Copy link
Member

@vyacheslav-volkov both the <D8/> and <R8/> use this Regex to log error messages:

const string CodeErrorRegExString = @"(?<file>.+\.java):(?<line>\d+):(?<error>.+)";

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 Info, Warning, Error?

@vyacheslav-volkov
Copy link
Author

vyacheslav-volkov commented Jul 16, 2024

@jonathanpeppers yes I think we should use Info, Warning, Error, here is part of the log from Android Studio, it starts with INFO and even the message states that it will be ignored::

INFO: /Users/user/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-core-jvm/1.8.1/bb0e192bd7c2b6b8217440d36e9758e377e450/kotlinx-coroutines-core-jvm-1.8.1.jar: R8: Invalid signature 'Lkotlin/coroutines/jvm/internal/SuspendLambda;Lkotlin/jvm/functions/Function2<Lkotlinx/coroutines/channels/ProducerScope<-Lkotlin/collections/IndexedValue<+TE;>;>;Lkotlin/coroutines/Continuation<-Lkotlin/Unit;>;Ljava/lang/Object;>;' for class kotlinx.coroutines.channels.ChannelsKt__DeprecatedKt$withIndex$1.
Validation error: A type variable is not in scope.
Signature is ignored and will not be present in the output.

@vyacheslav-volkov
Copy link
Author

@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?

@alexander-efremov
Copy link

@jonathanpeppers
it a critical fix for us. Currentely, the correcly tuned solution cannot be built due to this error. Is there any updates about the fix?

@suggyd
Copy link

suggyd commented Aug 14, 2024

@jonathanpeppers
Help! This issue is blocking our migration to MAUI. I tried using a pinned R8 from Android 12 as per the workaround above and that no longer appears to work? The issue appears to be the "--map-diagnostics" option that was added to the R8 build command in .NET 8. This doesn't appear to be supported in the older pinned version? The error I get is:

1> Error in Command line:
1> Unknown option: --map-diagnostics
1> R8 : Error in warning :
1> java.nio.file.NoSuchFileException: warning
1> Error in program input 'warning':
1> com.android.tools.r8.errors.b: Unsupported source file type
1> Error in info:
1> java.nio.file.NoSuchFileException: info
1> Error in program input 'info':
1> com.android.tools.r8.errors.b: Unsupported source file type
1> Compilation failed
1> C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.95\tools\Xamarin.Android.D8.targets(56,5): error MSB6006: "java.exe" exited with code 1.
1> Done executing task "R8" -- FAILED.

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

@vyacheslav-volkov
Copy link
Author

@jonathanpeppers @dellis1972 any updates, should we expect a fix?

@tranb3r
Copy link

tranb3r commented Sep 11, 2024

For me, this issue is happening in net9-pre7 and net9-rc1. No issue in net9-pre6.

@vyacheslav-volkov
Copy link
Author

@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

@dellis1972
Copy link
Contributor

@vyacheslav-volkov

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?

@vyacheslav-volkov
Copy link
Author

@dellis1972 please check this sample #7008 (comment)

@dellis1972
Copy link
Contributor

Looks like this might be caused by the default MSBuild error checking code.
None of our regex's are matching any of the output in the sample.

@Picao84
Copy link

Picao84 commented Sep 12, 2024

I'm having this issue as well, hope there is a fix soon!

@vyacheslav-volkov
Copy link
Author

@dellis1972 any updates?

@dellis1972
Copy link
Contributor

This is being worked on #9298

dellis1972 added a commit that referenced this issue Sep 19, 2024
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
Copy link
Contributor

PR #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.

jonathanpeppers pushed a commit that referenced this issue Sep 23, 2024
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.
@claudioredi
Copy link

@dellis1972: was this finally released into a service release?

@Picao84
Copy link

Picao84 commented Oct 24, 2024

Yes.

@claudioredi
Copy link

@Picao84: Thanks. Do you know in which specific version?

@jonathanpeppers
Copy link
Member

It's listed in the release notes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: App+Library Build Issues when building Library projects or Application projects.
Projects
None yet
Development

No branches or pull requests