llfbandit / app_links

Android App Links, Deep Links, iOs Universal Links and Custom URL schemes handler for Flutter.
https://pub.dev/packages/app_links
Apache License 2.0
220 stars 81 forks source link

Shrinker may have failed to optimize the Java bytecode #148

Closed asterion2nd closed 3 months ago

asterion2nd commented 3 months ago

After adding app_links to my project, I'm able to generate an Android apk only if -keepattributes InnerClasses,EnclosingMethod is added to proguard-rules.pro. Is this behavior expected?

Versions Flutter: 3.24.0 Dart: 3.5.0 compileSdkVersion 34 minSdkVersion 21 targetSdkVersion 34 app_links: ^6.2.0

settings.gradle:

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.3.0" apply false
    id "org.jetbrains.kotlin.android" version "1.8.0" apply false
    id "com.google.gms.google-services" version "4.4.2" apply false
    id "com.google.firebase.crashlytics" version "3.0.2" apply false
}
% flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.0, on macOS 14.6.1 23G93 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.2)
[✓] VS Code (version 1.92.2)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

proguard-rules.pro content before adding app_links: ^6.2.0 to pubspec.yaml

-dontwarn androidx.window.extensions.WindowExtensions
-dontwarn androidx.window.extensions.WindowExtensionsProvider
-dontwarn androidx.window.extensions.area.ExtensionWindowAreaPresentation
-dontwarn androidx.window.extensions.layout.DisplayFeature
-dontwarn androidx.window.extensions.layout.FoldingFeature
-dontwarn androidx.window.extensions.layout.WindowLayoutComponent
-dontwarn androidx.window.extensions.layout.WindowLayoutInfo
-dontwarn androidx.window.sidecar.SidecarDeviceState
-dontwarn androidx.window.sidecar.SidecarDisplayFeature
-dontwarn androidx.window.sidecar.SidecarInterface$SidecarCallback
-dontwarn androidx.window.sidecar.SidecarInterface
-dontwarn androidx.window.sidecar.SidecarProvider
-dontwarn androidx.window.sidecar.SidecarWindowLayoutInfo

After adding app_links: ^6.2.0 to pubspec.yaml, when trying to run % flutter build apk --release --obfuscate --split-debug-info=/Users/user/app_files/split_debug_info

The following error shows up

Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from ** to *** bytes (98.9% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
ERROR: R8: com.android.tools.r8.internal.Te: Attribute InnerClasses requires EnclosingMethod attribute. Check -keepattributes directive.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:minifyReleaseWithR8'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
   > Compilation failed to complete

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 29s
Running Gradle task 'assembleRelease'...                           30.2s

┌─ Flutter Fix ──────────────────────────────────────────────────────────────┐
│ [!] The shrinker may have failed to optimize the Java bytecode.            │
│ To disable the shrinker, pass the `--no-shrink` flag to this command.      │
│ To learn more, see: https://developer.android.com/studio/build/shrink-code │
└────────────────────────────────────────────────────────────────────────────┘
Gradle task assembleRelease failed with exit code 1

It works after adding -keepattributes InnerClasses,EnclosingMethod to proguard-rules.pro.

Does it related to

[x] App Links (Android)
[ ] Deep Links (Android)
[ ] Universal Links (iOS)
[ ] or Custom URL schemes? (iOS)

Does the example project work?

[ ] Yes
[ ] No
[x] Irrelevant here

Did you fully read the instructions for the targeted platform before submitting this issue?

Uploaded your files to webserver, HTTPS, direct connection, scheme pattern setup, ...

[x] Yes
[ ] No
[ ] Irrelevant here

llfbandit commented 3 months ago

Yes, this package requires microg/SafeParcel. So you may need additional rules. README_android.md updated.