Skip to content

IllegalArgumentException when initializing Parse #1194

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

Closed
4 tasks done
hej2010 opened this issue Apr 16, 2023 · 20 comments · Fixed by #1196
Closed
4 tasks done

IllegalArgumentException when initializing Parse #1194

hej2010 opened this issue Apr 16, 2023 · 20 comments · Fixed by #1196
Labels
state:released Released as stable version type:feature New feature or improvement of existing feature

Comments

@hej2010
Copy link
Contributor

hej2010 commented Apr 16, 2023

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

  • SDK version: 4.2.0
  • Operating system version: Android 12

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
Copy link

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

@mtrezza mtrezza added the type:feature New feature or improvement of existing feature label Apr 16, 2023
@mtrezza
Copy link
Member

mtrezza commented Apr 16, 2023

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

@hej2010
Copy link
Contributor Author

hej2010 commented Apr 16, 2023

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

Yes (if you are using minifyEnabled).

@mtrezza
Copy link
Member

mtrezza commented Apr 16, 2023

Pre gradle 8 minify would work, right?

@hej2010
Copy link
Contributor Author

hej2010 commented Apr 16, 2023

Yes, everything worked until I updated to Gradle 8

@mtrezza
Copy link
Member

mtrezza commented Apr 16, 2023

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

@hej2010
Copy link
Contributor Author

hej2010 commented Apr 16, 2023

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
Copy link
Member

mtrezza commented Apr 16, 2023

@azlekov, any idea how we could fix this?

@azlekov
Copy link
Contributor

azlekov commented Apr 18, 2023

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

@tSquaredd
Copy link

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

@riccardoch
Copy link

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
Copy link

SOGAPPS commented May 15, 2023

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

@tSquaredd Did you find a fix?

@tSquaredd
Copy link

@SOGAPPS we ended up adding this to our proguard rules

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

@SOGAPPS
Copy link

SOGAPPS commented May 18, 2023

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
Copy link
Contributor Author

hej2010 commented Jun 17, 2023

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
Copy link
Member

mtrezza commented Jun 17, 2023

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
Copy link

SOGAPPS commented Jun 18, 2023

@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
Copy link
Member

mtrezza commented Jun 18, 2023

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

@azlekov
Copy link
Contributor

azlekov commented Jun 18, 2023

I will compare and adjust mine in few days.

@parseplatformorg
Copy link

🎉 This change has been released in version 4.2.1

@parseplatformorg parseplatformorg added the state:released Released as stable version label Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:released Released as stable version type:feature New feature or improvement of existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants