Skip to content

added namespace for AGP version 7+. This should fix compatibility iss… #666

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nhoffmann-fts
Copy link

…ues with gradle 8.

this fixes issue #665

@unstoo
Copy link

unstoo commented Aug 8, 2024

Hi @nhoffmann-fts
I saw that in the @shopify/flashlist package the same issue solved this way:

// Conditional for compatibility with AGP <4.2.
if (project.android.hasProperty("namespace")) {
    namespace = "com.shopify.reactnative.flash_list"
}

Looks a bit cleaner. WDYT?

@nhoffmann-fts
Copy link
Author

@unstoo
Im not sure I quite understand. Is this checking for the whether AGP supports the namespace property? If namespace isn't declared, does the android object automatically contain the namespace property?

@nhoffmann-fts
Copy link
Author

@friederbluemle Would it be possible to get this reviewed and pulled? Its a blocker on a project im working right now.

@friederbluemle
Copy link
Member

@nhoffmann-fts - Apologies for the delay! I definitely want to get this fixed if there is an issue.
For some strange reason I am unable to reproduce the error. I'm pretty sure initially (~ 1+ year ago?) this was an issue for many projects, but now I'm not sure if this was "fixed" somewhere else..

I've tried:

  • RN 0.65 (Gradle 6.9; AGP 4.2.1)
  • RN 0.67 (Gradle 7.2; AGP 4.2.2)
  • RN 0.70 (Gradle 7.5.1; AGP 7.2.1)
  • RN 0.71 (Gradle 7.5.1; AGP 7.3.1)
  • RN 0.72 (Gradle 8.0.1; AGP 7.4.2)
  • RN 0.73 (Gradle 8.3; AGP 8.1.1)
  • RN 0.74 (Gradle 8.6; AGP 8.2.1)
  • RN 0.75 (Gradle 8.8; AGP 8.5.0)

RN 0.71 and RN 0.72 show the following warning:

> Task :react-native-linear-gradient:processDebugManifest
package="com.BV.LinearGradient" found in source AndroidManifest.xml: ./android/src/main/AndroidManifest.xml.
Setting the namespace via a source AndroidManifest.xml's package attribute is deprecated.
Please instead set the namespace (or testNamespace) in the module's build.gradle file, as described here: https://developer.android.com/studio/build/configure-app-module#set-namespace
This migration can be done automatically using the AGP Upgrade Assistant, please refer to https://developer.android.com/studio/build/agp-upgrade-assistant for more information.

RN 0.73+ shows a slightly different warning:

> Task :react-native-linear-gradient:processDebugManifest
package="com.BV.LinearGradient" found in source AndroidManifest.xml: ./android/src/main/AndroidManifest.xml.
Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported, and the value is ignored.
Recommendation: remove package="com.BV.LinearGradient" from the source AndroidManifest.xml: ./android/src/main/AndroidManifest.xml.

Other than that, all projects listed above build without errors.

Can you please share some info on the project you're facing issues with? Even better would be an example project that fails. Thanks!

@nhoffmann-fts
Copy link
Author

RN: 0.72.15
Gradle: 8.2
AGP: 8.1.2

Here are the errors:
`1: Task failed with an exception.

  • What went wrong:
    A problem occurred configuring project ':react-native-image-resizer'.

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.`

`2: Task failed with an exception.

  • What went wrong:
    Failed to query the value of property 'buildFlowServiceProperty'.

Could not isolate value org.jetbrains.kotlin.gradle.plugin.statistics.BuildFlowService$Parameters_Decorated@6d91178f of type BuildFlowService.Parameters
A problem occurred configuring project ':react-native-image-resizer'.
> 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.`

@Ali-Oliaee
Copy link

Hi guys
I also have this issue in my project
I opened pull request for other libraries and I think the cleaner way is to set a check function to detect gradle version and apply namespace based on gradle version, because this change is applied in gradle version 7.3 and above.
you can find this method on react-native-webview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants