Error with namespace not specified
Description
When trying to run on Android, I have the following error:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':react-native-iap'.
> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
> Namespace not specified. Please specify a namespace in the module's build.gradle file like so:
android {
namespace 'com.example.namespace'
}
If the package attribute is specified in the source AndroidManifest.xml, it can be migrated automatically to the namespace value in the build.gradle file using the AGP Upgrade Assistant; please refer to https://developer.android.com/studio/build/agp-upgrade-assistant for more information.
I am not suprised as declaring the namespace in build.gradle is mandatory from RN 0.72. I am surprised, however, that RNIAP still hasn't made this change, and no one is complaining about it. Do you all use patch-package or fork RNIAP?
Environment:
- react-native-iap: 13.0.0
- react-native: 0.72.17
- Platforms (iOS, Android, emulator, simulator, device): Android
I've just hit this issue while updating our target SDK to 35 which is mandatory starting August 30. I see this library is still using gradle 7.4.2 so that's why they didn't have to update it yet. I'm going to patch it for now and wait to see if it gets updated 😄
Thanks for reporting this!
@Jmaguerre You're absolutely right — starting from RN 0.72 and AGP 8.0+, declaring namespace is mandatory.
The react-native-iap package hasn’t been updated recently since we’ve shifted development over to [expo-iap](https://github.com/hyochan/expo-iap), which fully supports the new namespace format and modern Android Gradle Plugin.
If you're still using react-native-iap, you can either:
- Add the
namespacemanually in yourbuild.gradle, or - Use a patch (as you mentioned), or
- Consider migrating to
[expo-iap](https://github.com/hyochan/expo-iap)which is actively maintained.
Let me know if you'd like help migrating — happy to assist!
Thanks for the reply @hyochan. I'll leave it patched for now and soon work on migrating to expo-iap since we already have a bunch of expo libraries in use.
Thanks for the answer. Do we need to use Expo in order to use the expo-iap?
Thanks for the answer. Do we need to use Expo in order to use the expo-iap?
In a react-native-cli project, you can install and use expo-modules-core without Expo.
Closes since this may be resolved in v14.+