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

[Bug]: dependency conflict on Android #1545

Closed
2 of 3 tasks
CrashingTheCode opened this issue Aug 30, 2023 · 14 comments
Closed
2 of 3 tasks

[Bug]: dependency conflict on Android #1545

CrashingTheCode opened this issue Aug 30, 2023 · 14 comments

Comments

@CrashingTheCode
Copy link

CrashingTheCode commented Aug 30, 2023

What happened?

The android build fails with this error:
Duplicate class androidx.work.OneTimeWorkRequestKt found in modules work-runtime-2.8.0-runtime (androidx.work:work-runtime:2.8.0) and work-runtime-ktx-2.7.1-runtime (androidx.work:work-runtime-ktx:2.7.1)
Duplicate class androidx.work.PeriodicWorkRequestKt found in modules work-runtime-2.8.0-runtime (androidx.work:work-runtime:2.8.0) and work-runtime-ktx-2.7.1-runtime (androidx.work:work-runtime-ktx:2.7.1)

Go to the documentation to learn how to Fix dependency resolution errors.

Steps to reproduce?

1. Install react-native-onesignal 5.0.0
2. build on android

What did you expect to happen?

I expected a successful build

React Native OneSignal SDK version

Release 5.0.0

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

Duplicate class androidx.work.OneTimeWorkRequestKt found in modules work-runtime-2.8.0-runtime (androidx.work:work-runtime:2.8.0) and work-runtime-ktx-2.7.1-runtime (androidx.work:work-runtime-ktx:2.7.1)
Duplicate class androidx.work.PeriodicWorkRequestKt found in modules work-runtime-2.8.0-runtime (androidx.work:work-runtime:2.8.0) and work-runtime-ktx-2.7.1-runtime (androidx.work:work-runtime-ktx:2.7.1)

Go to the documentation to learn how to Fix dependency resolution errors.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@jennantilla
Copy link
Contributor

@CrashingTheCode thanks for reaching out! We'll investigate this and get back to you as soon as possible.

@KodyKendall
Copy link

I am running into this same issue, I believe it's a "transitive dependency conflict" where I have another package in my react-native project that is pulling in androidx.work:work-runtime, and they have conflicting versions.

It's the com.onesignal:notifications:5.0.0 package that has this dependency.

+--- project :react-native-onesignal
|    +--- com.onesignal:OneSignal:5.0.0
|    |    +--- com.onesignal:core:5.0.0
|    |    |    +--- androidx.legacy:legacy-support-v4:{require [1.0.0, 1.0.99]; prefer 1.0.0} -> 1.0.0 (*)
|    |    |    +--- androidx.appcompat:appcompat:{require [1.0.0, 1.3.99]; prefer 1.3.1} -> 1.6.1 (*)
|    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10 -> 1.8.10 (*)
|    |    |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4 (*)
|    |    |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4 (*)
|    |    +--- com.onesignal:notifications:5.0.0
|    |    |    +--- com.google.firebase:firebase-messaging:{require [19.0.0, 23.0.99]; prefer 23.0.0} -> 22.0.0 (*)
**|    |    |    +--- **androidx.work:work-runtime:{require [2.1.0, 2.7.99]; prefer 2.7.1} -> 2.8.0 (*)****
|    |    |    +--- com.onesignal:core:5.0.0 (*)
|    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10 -> 1.8.10 (*)
|    |    |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4 (*)
|    |    |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4 (*)
|    |    |    +--- androidx.work:work-runtime-ktx:2.7.1
|    |    |    |    +--- androidx.work:work-runtime:2.7.1 -> 2.8.0 (*)
|    |    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.5.30 -> 1.8.10 (*)
|    |    |    |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0 -> 1.6.4 (*)

And in my case, it's conflicting with:

+--- project :notifee_react-native
|    +--- com.facebook.react:react-native:+ -> com.facebook.react:react-android:0.72.4 (*)
|    +--- app.notifee:core:+ -> 202108261754
|    +--- androidx.concurrent:concurrent-futures:1.1.0 (*)
|    +--- com.google.android.gms:play-services-tasks:18.0.1
|    |    \--- com.google.android.gms:play-services-basement:18.0.0
|    |         +--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
|    |         +--- androidx.core:core:1.2.0 -> 1.9.0 (*)
|    |         \--- androidx.fragment:fragment:1.0.0 -> 1.5.7 (*)
**|    +--- androidx.work:work-runtime:2.8.0**

@KodyKendall
Copy link

KodyKendall commented Sep 8, 2023

I was able to resolve this by going into my android/app/build.gradle file adding the following lines:

android {
    namespace "com.yourapp.package"
    ...

    configurations.all {
         resolutionStrategy.force 'androidx.work:work-runtime:2.7.1' //<-- this came from the notifee library having a dependency on androidx.work:work-runtime:2.8.0' and OneSignal having a dependency on androidx:work:work-runtime:2.7.1
    }
}

@aryalprakash
Copy link

I was able to resolve this by going into my android/app/build.gradle file adding the following lines:

android {
    namespace "com.yourapp.package"
    ...

    configurations.all {
         resolutionStrategy.force 'androidx.work:work-runtime:2.7.1' //<-- this came from the notifee library having a dependency on androidx.work:work-runtime:2.8.0' and OneSignal having a dependency on androidx:work:work-runtime:2.7.1
    }
}

This worked. Thanks @KodyKendall

@jwhenshaw
Copy link

For anyone else who comes across this but would like to ensure the use of androidx.work:work-runtime:2.8.0, as I wanted this patch w.r.t to using Notifee, then I used the below snippet within my app build.gradle to force the resolution.

    // Force androidx.work:work-runtime andwork-runtime-ktx  to use version 2.8.0
    // due to transitive dependancy conflict between notifee and OneSignal
    api(group: "androidx.work", name: "work-runtime") {
        version {
            strictly "2.8.0"
        }
    }
        api(group: "androidx.work", name: "work-runtime-ktx") {
        version {
            strictly "2.8.0"
        }
    }

Note, I'm not sure if this is the correct way to achieve this as I'm new to the world of ReactNative + Android but its working so far for me (and as it is a minor version bump I'm assuming it should be okay)

Hope this helps someone

@jennantilla
Copy link
Contributor

Hello all! Just a quick update that we have updated our androidx.work:work-runtime to prefer the latest version, 2.8.1. Version 5.0.3 of the React Native plugin reflects this.

Please let us know if you have any additional questions or concerns.

@getadapt
Copy link

Hi -- thanks for this, but not sure this is fixed in 5.0.3 as we're still getting the above build error. We use expo managed builds in our workflow so needed the above patch to be put into our android/app/build.gradle programmatically. If anyone finds this who is also on expo, we have things building smoothly again using the following (ugly!) expo mod:

    mods: {
      android: {
        appBuildGradle: (config) => {
          let appBuildGradleFile = config.modResults.contents as string;
          // if you change these lines, always run prebuild clean afterwards (npx expo prebuild --platform android --clean)
          const newLines = [
            "    // start mod fix for notifee onesignal clash",
            "    configurations.all {",
            "         resolutionStrategy.force 'androidx.work:work-runtime:2.8.1' //<-- from mod",
            "         resolutionStrategy.force 'androidx.work:work-runtime-ktx:2.8.1' //<-- from mod",
            "    }",
            "    // end mod fix for notifee onesignal clash",
          ];

          const newLinesBlock = newLines.join("\n");

          // remove if already there lol
          appBuildGradleFile = appBuildGradleFile.replace(newLinesBlock, "");

          const lines = appBuildGradleFile.split("\n");

          // change line number as needed!
          lines.splice(114, 0, newLinesBlock);

          config.modResults.contents = lines.join("\n");

          return config;
        },
      },
    },

@SohelIslamImran
Copy link

Here is config plugin for expo.

const { withAppBuildGradle } = require("@expo/config-plugins");
const generateCode = require("@expo/config-plugins/build/utils/generateCode");

// https://github.com/OneSignal/react-native-onesignal/issues/1545
const onesignalAndroidXConflictWorkaroundCode = `
    configurations.all {
        resolutionStrategy.force 'androidx.work:work-runtime:2.8.1'
        resolutionStrategy.force 'androidx.work:work-runtime-ktx:2.8.1'
    }
`;

module.exports = (config) => {
  return withAppBuildGradle(config, async (config) => {
    const addCode = generateCode.mergeContents({
      newSrc: onesignalAndroidXConflictWorkaroundCode,
      tag: "onesignalAndroidXConflictWorkaroundCode",
      src: config.modResults.contents,
      anchor: /\s*namespace/i,
      comment: "//",
      offset: 1,
    });

    config.modResults.contents = addCode.contents;

    return config;
  });
};

@short-dsb
Copy link

Hi, @jennantilla! Thanks for investigating this. 🙂 Sorry to comment on a closed issue, but it’s still occurring in the latest release (5.0.4).

Now that the issue is fixed in 5.1.1, can we update the dependency in this project to resolve the build issue here?

I can confirm making this change locally in node_modules/react-native-onesignal/android/build.gradle results in a successful build:

- api 'com.onesignal:OneSignal:5.0.5'
+ api 'com.onesignal:OneSignal:5.1.1'

@Lurtroxx
Copy link

I can confirm still occurring in latest release! Just went to install today, and having this problem right now! @short-dsb

@jennantilla
Copy link
Contributor

@short-dsb we will be working on getting an update out for wrappers including React Native as soon as possible.

@Lurtroxx are you still experiencing this on 5.1.1 of the native Android SDK?

@Lurtroxx
Copy link

Yes both android and ios, the solution was to put this script given by @SohelIslamImran into the root and run it upon build.

Here is config plugin for expo.

const { withAppBuildGradle } = require("@expo/config-plugins");
const generateCode = require("@expo/config-plugins/build/utils/generateCode");

// https://github.com/OneSignal/react-native-onesignal/issues/1545
const onesignalAndroidXConflictWorkaroundCode = `
    configurations.all {
        resolutionStrategy.force 'androidx.work:work-runtime:2.8.1'
        resolutionStrategy.force 'androidx.work:work-runtime-ktx:2.8.1'
    }
`;

module.exports = (config) => {
  return withAppBuildGradle(config, async (config) => {
    const addCode = generateCode.mergeContents({
      newSrc: onesignalAndroidXConflictWorkaroundCode,
      tag: "onesignalAndroidXConflictWorkaroundCode",
      src: config.modResults.contents,
      anchor: /\s*namespace/i,
      comment: "//",
      offset: 1,
    });

    config.modResults.contents = addCode.contents;

    return config;
  });
};

@SohelIslamImran
Copy link

SohelIslamImran commented Jan 18, 2024

Yes both android and ios, the solution was to put this script given by @SohelIslamImran into the root and run it upon build.

I've faced this issue only on Android not ios.

@DLI0740-chaithanyaa
Copy link

I was able to resolve this by going into my android/app/build.gradle file adding the following lines:

android {
    namespace "com.yourapp.package"
    ...

    configurations.all {
         resolutionStrategy.force 'androidx.work:work-runtime:2.7.1' //<-- this came from the notifee library having a dependency on androidx.work:work-runtime:2.8.0' and OneSignal having a dependency on androidx:work:work-runtime:2.7.1
    }
}

This worked for me @KodyKendall 🥳 thank you...

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

No branches or pull requests

10 participants