parse-community / Parse-SDK-Android

The Android SDK for Parse Platform
https://parseplatform.org/
Other
1.88k stars 739 forks source link

IllegalArgumentException when initializing Parse #1194

Closed hej2010 closed 10 months ago

hej2010 commented 1 year ago

New Issue Checklist

Issue Description

The app crashes when initializing Parse with the latest Gradle/Android Studio version when using Proguard/R8 with minifyEnabled true and 'com.android.tools.build:gradle:8.0.0'.

Steps to reproduce

Initialize Parse at app startup with Parse.initialize(new Parse.Configuration.Builder(...));

Actual Outcome

The app crashes.

Expected Outcome

The app does not crash.

Environment

Parse Android SDK

Logs

Caused by java.lang.IllegalArgumentException: Cannot register a type that does not implement the default constructor!
       at com.parse.ParseObjectSubclassingController.registerSubclass(ParseObjectSubclassingController.java:95)
       at com.parse.ParseObject.registerSubclass(ParseObject.java:291)
       at com.parse.ParseObject.registerParseSubclasses(ParseObject.java:1032)
       at com.parse.Parse.initialize(Parse.java:169)
       at com.parse.Parse.initialize(Parse.java:140)

I do not have any custom subclasses registered.

Fixed by

Keeping all classes that are registered in registerParseSubclasses() by adding the line -keep @com.parse.ParseClassName class com.parse.* to proguard-rules.pro.

parse-github-assistant[bot] commented 1 year ago

Thanks for opening this issue!

mtrezza commented 1 year ago

In other words, gradle 8 is not supported OOTB by the Parse SDK, is that correct?

hej2010 commented 1 year ago

In other words, gradle 8 is not supported OOTB by the Parse SDK, is that correct?

Yes (if you are using minifyEnabled).

mtrezza commented 1 year ago

Pre gradle 8 minify would work, right?

hej2010 commented 1 year ago

Yes, everything worked until I updated to Gradle 8

mtrezza commented 1 year ago

Thanks for clarifying, do you have an idea how to fix it? Would you want to open a PR?

hej2010 commented 1 year ago

I fixed it by adding -keep @com.parse.ParseClassName class com.parse.* to proguard-rules.pro, then it no longer crashes.

I´m not sure which file in this project to add it to, maybe https://github.com/parse-community/Parse-SDK-Android/blob/master/parse/release-proguard.pro

mtrezza commented 1 year ago

@azlekov, any idea how we could fix this?

azlekov commented 1 year ago

No clue, @mtrezza. I will check upcoming days. Maybe is related with latest version of AGP and R8.

tSquaredd commented 1 year ago

Experiencing this as well. Proposed fix did not resolve it for us. Any ideas?

riccardoch commented 1 year ago

Same issue after upgrading Gradle to version 8. The proposed fix worked for me.

Like @hej2010 I do not have any custom subclasses registered and minifyEnabled true for release build.

SOGAPPS commented 1 year ago

Currently experiencing this. Proposed fix did not resolve it for us. We've custom subclasses registered.

@tSquaredd Did you find a fix?

tSquaredd commented 1 year ago

@SOGAPPS we ended up adding this to our proguard rules

-keepclassmembers public class * extends com.parse.** {
   public <init>(...);
}
SOGAPPS commented 1 year ago

Thanks @tSquaredd

Using this worked for us - both "keep" & "keepclassmembers".

We added the two lines of code below to our apps "proguard-rules.pro" file.

-keep @com.parse.ParseClassName class com.parse.* -keepclassmembers public class * extends com.parse.** { public <init>(...); }

hej2010 commented 1 year ago

Gradle 8.0 switches to using R8 in "full mode" by default: https://r8.googlesource.com/r8/+/refs/heads/master/compatibility-faq.md#r8-full-mode "R8 performs more aggressive optimizations, meaning additional ProGuard configuration rules may be required."

It can be disabled by adding android.enableR8.fullMode=false to gradle.properties

mtrezza commented 1 year ago

Does this comment already provide the solution?

@SOGAPPS In your comment did you mean one has to replace ParseClassName with the custom classes a developer is using in their app?

SOGAPPS commented 1 year ago

@mtrezza

No, for clarity, we added the two lines of code below to our apps "proguard-rules.pro" file.

Doing this resolved our issue.

-keep @com.parse.ParseClassName class com.parse.* -keepclassmembers public class * extends com.parse.** { public <init>(...); }

mtrezza commented 1 year ago

@azlekov do you think a PR with these lines could fix this issue?

azlekov commented 1 year ago

I will compare and adjust mine in few days.

parseplatformorg commented 10 months ago

🎉 This change has been released in version 4.2.1