Coder Social home page Coder Social logo

TypeToken must be created with a type argument: new TypeToken<...>() {}; When using code shrinkers (ProGuard, R8, ...) make sure that generic signatures are preserved. about adaptysdk-react-native HOT 18 CLOSED

SergiOnGit avatar SergiOnGit commented on June 16, 2024
TypeToken must be created with a type argument: new TypeToken<...>() {}; When using code shrinkers (ProGuard, R8, ...) make sure that generic signatures are preserved.

from adaptysdk-react-native.

Comments (18)

vladd-g avatar vladd-g commented on June 16, 2024

hi @SergiOnGit!

It is really bad that we have to install @adapty/react-native-ui even if we don't use it

No, you don't have to.

from adaptysdk-react-native.

vladd-g avatar vladd-g commented on June 16, 2024

@SergiOnGit what rules do you currently have in the proguard config?

from adaptysdk-react-native.

SergiOnGit avatar SergiOnGit commented on June 16, 2024

@vladd-g I had -keep class com.adapty.** { *; } in proguard, Then I removed it and fixed with android.enableR8.fullMode=false in gradle.properties. But what is correct solution? I don't want to have ui lib installed. Also you don't mention anything in docs about proguard. Guide me please.

from adaptysdk-react-native.

vladd-g avatar vladd-g commented on June 16, 2024

@SergiOnGit

Then I removed it and fixed with android.enableR8.fullMode=false

Do you mean it works well now?

I don't want to have ui lib installed

You can simply remove the @adapty/react-native-ui dependency if you don't use the Paywall Builder feature

I don't want to have ui lib installed. Also you don't mention anything in docs about proguard.

Actually, only -keep class com.adapty.** { *; } is sufficient in most cases. If disabling full mode prevented obfuscation-related crashes, that's okay too. We'll check and add all the necessary info to the docs if anything is missing. Thank you!

from adaptysdk-react-native.

SergiOnGit avatar SergiOnGit commented on June 16, 2024

Yes it works now. So I can remove ui module and should add -keep class com.adapty.** { *; } rule to proguard. And should leave full mode disabled right? Would be great if you add all the necessary info in docs. Also cases where app may still crash with possible fix.

from adaptysdk-react-native.

vladd-g avatar vladd-g commented on June 16, 2024

Yes it works now. So I can remove ui module and should add -keep class com.adapty.** { *; } rule to proguard. And should leave full mode disabled right?

If everything works fine, why not

from adaptysdk-react-native.

SergiOnGit avatar SergiOnGit commented on June 16, 2024

@vladd-g I added -keep class com.adapty.** { *; } and removed ui lib. Also leave full mode disabled and now build fails. See the log:

ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /Users/warlock/Desktop/Mobile/movebody/android/app/build/outputs/mapping/release/missing_rules.txt. ERROR: R8: Missing class com.adapty.ui.AdaptyUI$Action$Close (referenced from: void com.adapty.internal.crossplatform.AdaptyUIActionTypeAdapterFactory$create$result$1.write(com.google.gson.stream.JsonWriter, com.adapty.ui.AdaptyUI$Action)) Missing class com.adapty.ui.AdaptyUI$Action$Custom (referenced from: void com.adapty.internal.crossplatform.AdaptyUIActionTypeAdapterFactory$create$result$1.write(com.google.gson.stream.JsonWriter, com.adapty.ui.AdaptyUI$Action)) Missing class com.adapty.ui.AdaptyUI$Action$OpenUrl (referenced from: void com.adapty.internal.crossplatform.AdaptyUIActionTypeAdapterFactory$create$result$1.write(com.google.gson.stream.JsonWriter, com.adapty.ui.AdaptyUI$Action)) Missing class com.adapty.ui.AdaptyUI$Action (referenced from: com.adapty.ui.AdaptyUI$Action com.adapty.internal.crossplatform.AdaptyUIActionTypeAdapterFactory$create$result$1.read(com.google.gson.stream.JsonReader) and 3 other contexts)

from adaptysdk-react-native.

vladd-g avatar vladd-g commented on June 16, 2024

@SergiOnGit please try adding -dontwarn com.adapty.ui.** to the proguard rules

from adaptysdk-react-native.

SergiOnGit avatar SergiOnGit commented on June 16, 2024

-dontwarn com.adapty.ui.** made it work, But only after I removed -keep class com.adapty.** { *; }

Also, I know you have mentioned in docs to add multidex true but I removed it and it still works. Should I expect errors on some stage with disabled multidex?

from adaptysdk-react-native.

vladd-g avatar vladd-g commented on June 16, 2024

But only after I removed -keep class com.adapty.** { *; }

What was the error before you removed it?

Should I expect errors on some stage with disabled multidex?

If it compiled with success, you don't need it

Unlike obfuscation issues that can occur at runtime, so I'd try keeping -keep class com.adapty.** { *; }

from adaptysdk-react-native.

SergiOnGit avatar SergiOnGit commented on June 16, 2024

I managed to figure it out. This two rule together

-keep class com.adapty.** { *; } -dontwarn com.adapty.ui.**

Works when I removed android.enableR8.fullMode=false
No matter if you enable multidex or not.

Also no need to install ui lib. Looks like, it just needed correct proguard rules. App builds and starts.

from adaptysdk-react-native.

SergiOnGit avatar SergiOnGit commented on June 16, 2024

Looks like I made a mistake, android.enableR8.fullMode=false is still needed, without it app startup ends with error:

Fatal Exception: java.lang.IllegalStateException: TypeToken must be created with a type argument: new TypeToken<...>() {}; When using code shrinkers (ProGuard, R8, ...) make sure that generic signatures are preserved. at com.google.gson.reflect.TypeToken.getTypeTokenTypeArgument(TypeToken.java:100) at com.google.gson.reflect.TypeToken.<init>(TypeToken.java:70)...

from adaptysdk-react-native.

vladd-g avatar vladd-g commented on June 16, 2024

This two rule together

-keep class com.adapty.** { *; } -dontwarn com.adapty.ui.**

Works when I removed android.enableR8.fullMode=false

What error did you see before removing android.enableR8.fullMode=false?

from adaptysdk-react-native.

SergiOnGit avatar SergiOnGit commented on June 16, 2024

This two rule together
-keep class com.adapty.** { *; } -dontwarn com.adapty.ui.**
Works when I removed android.enableR8.fullMode=false

What error did you see before removing android.enableR8.fullMode=false?

I don't clearly understand what you mean before removing, I I don't remove it, there is no error app works with this configs:

-keep class com.adapty.** { *; }
-dontwarn com.adapty.ui.**
android.enableR8.fullMode=false

But I noticed that disabling full mode increases app size dramatically, 21mb app download size is 56mb on play store. Can you fix it for full mode? Without it, app starts at startup with this log:

Fatal Exception: java.lang.IllegalStateException: TypeToken must be created with a type argument: new TypeToken<...>() {}; When using code shrinkers (ProGuard, R8, ...) make sure that generic signatures are preserved. at com.google.gson.reflect.TypeToken.getTypeTokenTypeArgument(TypeToken.java:100) at com.google.gson.reflect.TypeToken.<init>(TypeToken.java:70)...

Let me know if you need any additional info.

from adaptysdk-react-native.

vladd-g avatar vladd-g commented on June 16, 2024

Could you please try adding these rules? (If they are not sufficient for correct functioning, also add these)

from adaptysdk-react-native.

SergiOnGit avatar SergiOnGit commented on June 16, 2024

@vladd-g Checked. These rules made it work without disabling full mode

-keep class com.adapty.** { *; }
-dontwarn com.adapty.ui.**
-keepattributes Signature
-keep class com.google.gson.reflect.TypeToken { *; }
-keep class * extends com.google.gson.reflect.TypeToken

from adaptysdk-react-native.

vladd-g avatar vladd-g commented on June 16, 2024

@SergiOnGit, so now everything works fine?

from adaptysdk-react-native.

SergiOnGit avatar SergiOnGit commented on June 16, 2024

@vladd-g Sorry for late reply. Yes, everything works fine.

from adaptysdk-react-native.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.