aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.12k forks source link

amazon-cognito-identity-js: missing namespace information required by Gradle 8 #12306

Closed adolfogc closed 10 months ago

adolfogc commented 12 months ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Authentication

Amplify Categories

auth

Environment information

```json "dependencies": { "@aws-amplify/auth": "^5.6.5", "@aws-amplify/core": "^5.8.5", "@react-native-masked-view/masked-view": "^0.3.0", "@react-navigation/native": "^6.0.16", "@react-navigation/stack": "^6.0.11", "@rescript/react": "^0.11.0", "@sentry/react-native": "^5.11.1", "amazon-cognito-identity-js": "^6.3.6", "jsc-android": "^250231.0.0", "react": "18.2.0", "react-native": "0.72.6", "react-native-gesture-handler": "^2.13.2", "react-native-gradle-plugin": "^0.71.19", "react-native-safe-area-context": "^4.7.2", "react-native-screens": "^3.25.0", "rescript-react-native": "^0.72.0", "rescript-react-navigation": "^6.0.3" }, "devDependencies": { "@babel/core": "^7.23.2", "@babel/preset-env": "^7.23.2", "@babel/runtime": "^7.23.2", "@react-native-community/cli-platform-android": "^11.3.9", "@react-native-community/cli-platform-ios": "^11.3.9", "@react-native/eslint-config": "^0.72.2", "@react-native/gradle-plugin": "^0.74.0", "@react-native/metro-config": "^0.72.11", "@rnx-kit/align-deps": "^2.2.5", "@rnx-kit/babel-preset-metro-react-native": "^1.1.5", "@rnx-kit/cli": "^0.16.17", "@rnx-kit/metro-config": "^1.3.9", "@rnx-kit/metro-plugin-cyclic-dependencies-detector": "^1.1.2", "@rnx-kit/metro-plugin-duplicates-checker": "^2.1.2", "@rnx-kit/metro-resolver-symlinks": "^0.1.33", "@rnx-kit/metro-serializer": "^1.0.12", "@rnx-kit/tools-react-native": "^1.3.3", "@tsconfig/react-native": "^3.0.2", "@types/react": "^18.2.28", "@types/react-test-renderer": "^18.0.3", "babel-jest": "^29.7.0", "eslint": "^8.51.0", "jest": "^29.7.0", "metro-react-native-babel-preset": "0.76.8", "prettier": "^2.8.8", "react-native-dotenv": "^3.4.9", "react-test-renderer": "18.2.0", "rescript": "^10.1.4", "typescript": "4.8.4" }, ```

Describe the bug

Building the Android version of a RN application fails when using Gradle 8 due to missing namespace information.

The error can be fixed by adding the following to build.gradle:

// ...
android {
  // ...
  namespace "com.amazonaws"
  // ...
}
// ...

Expected behavior

The package should work when using Gradle 8.

Reproduction steps

  1. Setup project using RN 0.72.6+
  2. Add amazon-cognito-identity-js as dependency
  3. Build Android version of the project

Code Snippet

// Not applicable.

Log output

```bash A problem occurred configuring project ':amazon-cognito-identity-js'. > 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. ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

cwomack commented 12 months ago

Hello, @adolfogc 👋. I've been able to reproduce the issue on my side and will review this with the team internally for next steps. Going to mark this as a bug and update this issue on progress as it's made! It look like Gradle 8 introduced a breaking change and we are going to work on adopting it/resolving it to fix the build issues tied to the namespace errors.

Just to confirm for other that find this until the fix is implemented, did the changes you made to your build.gradle file completely resolves the issue for you?

adolfogc commented 12 months ago

Hi @cwomack, thank you for your reply! Yes, just adding that line to the build.gradle fixed the error and allowed me to build the project.

HuiSF commented 12 months ago

Hi @adolfogc could you do my a favor, could you run the following command in your <project>/android directory and paste the output?

./gradlew --version
adolfogc commented 12 months ago

Hi @HuiSF, this is the output:

------------------------------------------------------------
Gradle 8.0.1
------------------------------------------------------------

Build time:   2023-02-17 20:09:48 UTC
Revision:     68959bf76cef4d28c678f2e2085ee84e8647b77a

Kotlin:       1.8.10
Groovy:       3.0.13
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.8.1 (Eclipse Adoptium 17.0.8.1+1)
OS:           Mac OS X 14.0 aarch64
adolfogc commented 11 months ago

Hi @HuiSF , @cwomack, this issue also affects other aws-amplify packages, such as @aws-amplify/pushnotification and @aws-amplify/rtn-push-notification, as well as some dependency packages like react-native-get-random-values. I will close the PR I submitted because the solution should probably fix the issue for all the aws-amplify packages at once.

adolfogc commented 11 months ago

Just for reference, how they are tackling this issue in react-native-get-random-values: https://github.com/LinusU/react-native-get-random-values/pull/48

HuiSF commented 11 months ago

Do you still have the logs of the build failure? @adolfogc

HuiSF commented 11 months ago

Didn't mean to close this issue with merging the PR. Reopen until the fix gets released.

adolfogc commented 11 months ago

Hi @HuiSF thank you for the fix, I looked at the PR (#12371) and wanted to bring to your attention that it seems like the pushnotification package was left behind (https://github.com/aws-amplify/amplify-js/blob/main/packages/pushnotification/android/src/main/AndroidManifest.xml)

HuiSF commented 11 months ago

Hi @adolfogc thanks for the callout! I think this legacy push notification package is being deprecated.

nadetastic commented 10 months ago

The fix for this has been released and is available 6.0.5 as welll as 5.3.12 . I'll go ahead and mark this issue as closed, thank you!