superwall / Superwall-Flutter

Remotely configure every aspect of your paywall and double your revenue.
MIT License
12 stars 7 forks source link

[docs] Require users to use AGP 8 if using the latest Flutter SDK #18

Closed joshuadeguzman closed 2 months ago

joshuadeguzman commented 2 months ago

Description

We're currently using Android Gradle Plugin (AGP) 7.6.3. When we try to run flutter build apk, it throws a build error for having a nullable R8 issue, related to the AGP v8 migration in the Android SDK.

Attachments

Here's the error logs that we get:

ERROR:/Users/joshua/.gradle/caches/transforms-3/737b2f8aceb183fbf88a8d49781f16d3/transformed/jetified-appcompat-re
sources-1.7.0-runtime.jar: R8: java.lang.NullPointerException
[  +1 ms] FAILURE: Build failed with an exception.
[    ] * What went wrong:
[    ] Execution failed for task ':app:minifyDevReleaseWithR8'.
[    ] > A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
[    ]  > Compilation failed to complete, origin:
/Users/joshua/.gradle/caches/transforms-3/737b2f8aceb183fbf88a8d49781f16d3/transformed/jetified-appcompat-resource
s-1.7.0-runtime.jar:androidx/appcompat/graphics/drawable/DrawableContainerCompat$1.class
[    ] * Try:
[    ] > Run with --debug option to get more log output.
[    ] > Run with --scan to get full insights.
[    ] * Exception is:
[    ] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:minifyDevReleaseWithR8'.
[    ] at
org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecu
ter.java:142)
[    ] at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)

It throws an unrelated R8 error but somehow it didn't expose the actual issue. So we went ahead and check the SDK changelog, and crossmatch it with the native SDKs.

NOTE: However, we were unable to use the latest Flutter 1.2.0 just yet because there are at least two plugins that needs to support AGP 8 like image_gallery_saver and facebook_app_events.

Proposal

I propose we update the docs and remind the users to use the latest AGP version in the Installing SDK step:

distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip

I went through the Android SDK PR changes, and saw that the AGP was using the 8.5 version. Good thing is that the Flutter SDK Changelog does match the changes happening on the native plugins so I was able to see the changes.

Thanks!

joshuadeguzman commented 2 months ago

We are able to build using superwall_flutter: 1.1.8:

[+1232 ms] ✓  Built build/app/outputs/flutter-apk/app-dev-release.apk (135.5MB).
[        ] "flutter apk" took 141,327ms.
[ +162 ms] ensureAnalyticsSent: 114ms
[        ] Running 0 shutdown hooks
[        ] Shutdown hooks complete
[   +1 ms] exiting with code 0
ianrumac commented 2 months ago

Hey @joshuadeguzman ! Thanks for the suggestion, added it to docs and will be live soon!

Regarding not being able to update due to image_gallery_saver and facebook_app_events, you can try something similar to the following in your build.gradle:

subprojects {

   ...
    afterEvaluate { project ->
            if (project.hasProperty("android")) {
                android {
                    compileSdk = 34
                    compileOptions {
                        sourceCompatibility JavaVersion.VERSION_17
                        targetCompatibility JavaVersion.VERSION_17
                    }
                    if (project.plugins.hasPlugin("kotlin-android"))
                        tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
                            kotlinOptions.jvmTarget = "17"
                        }
                }
          }
    }
}

While not a perfect solution, it could help until the library owners update their respective targets.

ianrumac commented 2 months ago

Resolving the issue as new docs are live!

joshuadeguzman commented 2 months ago

Thank you @ianrumac !! I saw the doc changes, it's pretty neat! I hope this will help more developers who will integrate Superwall!

https://superwall.com/docs/installation-via-pubspec#android-configuration