constraintlayout icon indicating copy to clipboard operation
constraintlayout copied to clipboard

MotionLayout is not compatible with R8 full mode (without proguard rules)

Open h6ah4i opened this issue 4 years ago • 5 comments

I faced an app crash when using R8 full mode which removes constructors more aggressively.

MotionLayout is using getConstructor() method in the KeyFrames class here :point_down: and it cause the problem. https://github.com/androidx/constraintlayout/blob/eb540e400fd01d6c4e3f795343a8f548d83aef3f/constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/widget/KeyFrames.java#L50

The following proguard rule resolves the issue, but I think this should be bundled in consumerProguard by default.

-keepclassmembers class * extends androidx.constraintlayout.motion.widget.Key {
  public <init>();
}

h6ah4i avatar Oct 15 '21 16:10 h6ah4i

Would this not cause people simply using ConstraintLayout to have their APK increase in size? The majority of people using ConstraintLayout are not using MotionLayout (An argument for it being 2 libraries )

The AndroidStudio should add this to your proguard rules. We am not very familiar with the capabilities of progard.txt and we will be looking into it more

jafu888 avatar Oct 15 '21 18:10 jafu888

This should be fixed ASAP as since Gradle 8.0 R8 full mode is on per default

https://developer.android.com/build/releases/gradle-plugin

Nailik avatar Apr 25 '23 10:04 Nailik

I'm also running into this issue. My KeyFrames do not work - they are ingored, no crashes so far - if R8 full mode is enabled

GSala avatar May 04 '23 10:05 GSala

We will directly link in the future. We will move away from use of Java Reflection APIs.

jafu888 avatar May 04 '23 23:05 jafu888

I had the same issue and I solved the problem by moving <KeyFrame> features to <ConstraintSet>.

oguzhanaslann avatar Feb 15 '24 08:02 oguzhanaslann