Skip to content
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

Unable to add private maven repo to the React native project directly #44535

Closed
rakesho-vel opened this issue May 11, 2024 · 6 comments
Closed
Labels
Newer Patch Available Resolution: Answered When the issue is resolved with a simple answer

Comments

@rakesho-vel
Copy link

rakesho-vel commented May 11, 2024

Description

I am building a react native sdk and for that, client react native apps who integrate my react native SDK also need a private maven repo to use some native functions from that package. Now when i add that package both in SDK as well as in example app, I need to add the private maven repo to the app/build.gradle and add its path and creds to the android/build.gradle. But when i try to sync the Android app tries to find this private repo from the pubic Maven and not from the private maven path i have shared and it cannot install the package.

android/build.gradle

repositories {
   …
   maven {
       url "https://maven.pkg.github.com/package" // added dummy url
       credentials {
           username props['username']
           password props['token']
       }
}

app/build.gradle

dependencies {
    // The version of react-native is set by the React Native Gradle Plugin
    implementation("com.facebook.react:react-android")
    implementation("com.facebook.react:flipper-integration")

    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }

  implementation("com.package:1.3.1") // added dummy name
}

I tried searching if there is any other way to enable downloading the package from private repo but could not find any.

When I debugged more in react native gradle plugin, i found a way to add the private repo using afterEvaluate block from app/build.gradle like -

project.afterEvaluate {
  project.repositories.maven { ->
    url = URI.create("https://maven.pkg.github.com/package")
    credentials { cred ->
      cred.username = System.getenv("MAVEN_USERNAME")
      cred.password = System.getenv("MAVEN_PASSWORD")
    }
  }
}

It looks like a patch to me, so i want to know if there is any right way to add the private repo to the react native android project?

Steps to reproduce

  1. Create a react native app that requires a private android repository
  2. Create its package and install in the react native project
  3. Add the private maven repo url and credentials in android/build.gradle
  4. Add the private package dependency to app/build.gradle
  5. try to sync the application

React Native Version

0.73.6

Affected Platforms

Runtime - Android

Output of npx react-native info

npx react-native info

  WARNING: You should run npx react-native@latest to ensure you're always using the most current version of the CLI. NPX has cached version (0.73.6) != current release (0.74.1)
  
info Fetching system and libraries information...
System:
  OS: macOS 14.4
  CPU: (8) x64 Apple M1
  Memory: 21.69 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.18.0
    path: ~/.nvm/versions/node/v18.18.0/bin/node
  Yarn:
    version: 3.6.1
    path: ~/.nvm/versions/node/v18.18.0/bin/yarn
  npm:
    version: 9.8.1
    path: ~/.nvm/versions/node/v18.18.0/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.13.0
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.0
      - iOS 17.0
      - macOS 14.0
      - tvOS 17.0
      - watchOS 10.0
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.3 AI-223.8836.35.2231.10811636
  Xcode:
    version: 15.0.1/15A507
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.3
    path: /Library/Java/JavaVirtualMachines/jdk-17.0.3.jdk/Contents/Home/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.6
    wanted: 0.73.6
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

info React Native v0.74.1 is now available (your project is running on v0.73.6).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.74.1
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.74.1
info For more info, check out "https://reactnative.dev/docs/upgrading?os=macos".

Stacktrace or Logs

error Failed to install the app. Command failed with exit code 1: ./gradlew app:installDebug -PreactNativeDevServerPort=8081 
FAILURE: Build failed with an exception. * What went wrong:
Could not determine the dependencies of task ':app:processDebugResources'.
> Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'. 
> Could not find com.xxx:xxx-core:1.3.1. Searched in the following locations: - https://oss.sonatype.org/content/repositories/snapshots/com/xxx/xxx-core/1.3.1/xxx-core-1.3.1.pom 
- https://repo.maven.apache.org/maven2/com/xxx/xxx-core/1.3.1/xxx-core-1.3.1.pom 
- file:/Users/xxx/Projects/xxx/xxx-rn-sdk/example/node_modules/jsc-android/dist/com/xxx/xxx-core/1.3.1/xxx-core-1.3.1.pom 
- https://dl.google.com/dl/android/maven2/com/xxx/xxx-core/1.3.1/xxx-core-1.3.1.pom 
- https://www.jitpack.io/com/xxx/xxx-core/1.3.1/xxx-core-1.3.1.pom 
Required by: project :app > project :react-native-xxx

Reproducer

https:github.com/rakesho-vel

Screenshots and Videos

No response

Copy link

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - 0.73.8. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

Copy link

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

@github-actions github-actions bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels May 11, 2024
@rakesho-vel
Copy link
Author

I cannot share the reproducible example as the dependency i am adding are private maven repo.

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. Needs: Author Feedback and removed Needs: Author Feedback labels May 11, 2024
@cortinico
Copy link
Contributor

cortinico commented May 11, 2024

The code you shared in your first snippet is the correct way to specify a private maven repository. Your project is failing for other reasons.

I've created for you a sample project here:
https://github.com/cortinico/reproducer-private-maven-repo

Specifically look at this commit:
cortinico/reproducer-private-maven-repo@8af94f7

As you can see from the CI, it's failing with:

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not resolve my.random.package:library:+.
     Required by:
         project :app
      > Failed to list versions for my.random.package:library.
         > Unable to load Maven meta-data from https://maven.pkg.github.com/package/my/random/package/library/maven-metadata.xml.
            > Could not GET 'https://maven.pkg.github.com/package/my/random/package/library/maven-metadata.xml'. Received status code 401 from server: Unauthorized

@cortinico
Copy link
Contributor

You can also run the task with --info to verify that the build task is effectively attempting to fetch the library from the provided URL.

@cortinico cortinico added Resolution: Answered When the issue is resolved with a simple answer and removed Needs: Triage 🔍 Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Attention Issues where the author has responded to feedback. labels May 11, 2024
@rakesho-vel
Copy link
Author

Okay, @cortinico Thanks for confirming, wanted to make sure, we are doing it right way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Newer Patch Available Resolution: Answered When the issue is resolved with a simple answer
Projects
None yet
Development

No branches or pull requests

2 participants