google/webcrypto.dart

Support for Gradle 8

Closed this issue · 4 comments

hi, I am getting this error when I import the plugin and try to run Android in the emulator (the other targets work)

* What went wrong:
A problem occurred configuring project ':webcrypto'.
> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
   > Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.

If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.

which from what I remember a couple of months back, indicates that the plugin does not have namespace specified in their build.gradle - it is a requirement for Gradle 8 for all subprojects.

Without this, I dont I have any workaround other than downgrading gradle, which is something I'd like to avoid.

My gradle dependency: com.android.tools.build:gradle:8.2.0

@gourgouris reproduction steps please?

We have integration tests for android:

android:
name: webcrypto on Android emulator
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '11'
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
architecture: x64
- name: Configure Flutter
run: |
flutter config --no-analytics
- run: flutter pub get
- name: Run flutter test integration_test/webcrypto_test.dart -d android
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 28
working-directory: ./example
script: flutter test integration_test/webcrypto_test.dart -d android

Could we reproduce this by trying to build the example/ app in release mode?

Do we need to upgrade the example/ app to reproduce this?

I could probably use some help here.


What are the changes required here? (happy to take PRs, ping me on any PRs)

Will those changes have implications on people using an older gradle version? (if so this needs to be documented in the CHANGELOG before we ship any changes).

hi @jonasfj, can't really test it right now, but my thinking is the following:

replication steps

  1. in example/
  2. in android/build.gradle change classpath 'com.android.tools.build:gradle:7.1.2' to 'com.android.tools.build:gradle:8.2.2'
  3. in android/gradle/wrapper/gradle-wrapper.properties change distributionUrl=https://services.gradle.org/distributions/gradle-7.4-all.zip to distributionUrl=https://services.gradle.org/distributions/gradle-8.2-all.zip

compiling now should give you the same error.

To fix it, the first I'd do would be to add a namespace line in the android/build.gradle of the plugin AND the example (eg like here: https://github.com/flutter/packages/blob/0af905d779d52fc81ffc239c211e8c5956154f34/packages/path_provider/path_provider_android/android/build.gradle#L27)
And that should theoritically get rid of the error

Okay, still unclear if it'll affect people using older versions of gradle.

I see new flutter templates have android/build.gradle with:

    if (project.android.hasProperty("namespace")) {
        namespace 'com.example.mypkg'
    }

We should probably investigate this further.

Yes, this is because older versions of gradle (<4.2) do not support the namespace property and thus would fail to build (unknown property 'namespace').

From the offically maintained flutter packages, I can understand this is the way to go now.
Relevant PRs:
flutter/packages@6284c2d
(bulk adds namespace to all packages)

flutter/packages@a86beaf
(bulk conditionalizes namespace, 3 days apart)

My point is it looks safe, since all flutter packages do it anyway, but that's as far I can help I think.