Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.
This repository was archived by the owner on May 20, 2025. It is now read-only.

Failed to run android on React Native 0.71 #2418

Closed

Description

Steps to Reproduce

  1. Upgrade react native version to 0.71 following the upgrade helper
  2. Install dependencies
  3. Run yarn android

Expected Behavior

App builds and runs under debug mode

Actual Behavior

After upgraded to React Native 0.71, the android build fails with the following message:

* What went wrong:
Could not determine the dependencies of task ':app:generateBundledResourcesHashDebug'.
> Task with path 'bundleDebugJsAndAssets' not found in project ':app'.

Environment

  • react-native-code-push version: 7.0.5
  • react-native version: 0.71.0
  • iOS/Android/Windows version: Android 11
  • Does this reproduce on a debug build or release build? debug
  • Does this reproduce on a simulator, or only on a physical device? simulator

Other Attempts

After removing the following lines from android/build.gradle the build seems to work fine (w/o codepush of course)

apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"

Activity

  1. johnf commented on Jan 13, 2023

    @johnf
    Contributor

    I have the start of a fix here #2419

    You can use patch-package with

    iff --git a/node_modules/react-native-code-push/android/codepush.gradle b/node_modules/react-native-code-push/android/codepush.gradle
    index 22be273..8eff668 100644
    --- a/node_modules/react-native-code-push/android/codepush.gradle
    +++ b/node_modules/react-native-code-push/android/codepush.gradle
    @@ -25,6 +25,11 @@ gradle.projectsEvaluated {
         }
         
         android.applicationVariants.all { variant ->
    +        // skip debug build variant
    +        if (variant.buildType.name == "debug") {
    +            return;
    +        }
    +
             def nodeModulesPath;
             if (config.root) {
                 nodeModulesPath = Paths.get(config.root, "/node_modules");
    @@ -48,10 +53,10 @@ gradle.projectsEvaluated {
             // Make this task run right after the bundle task
             def generateBundledResourcesHash;
     
    -        if (variant.hasProperty("bundleJsAndAssets")) {
    -            def reactBundleTask = variant.bundleJsAndAssets
    -            jsBundleDir = reactBundleTask.generatedAssetsFolders[0].absolutePath
    -            resourcesDir = reactBundleTask.generatedResFolders[0].absolutePath
    +        def reactBundleTask = tasks.findByName("createBundle${targetName}JsAndAssets")
    +        if (reactBundleTask) {
    +            jsBundleDir = reactBundleTask.property('jsBundleDir').asFile.get()
    +            resourcesDir = reactBundleTask.property('resourcesDir').asFile.get()
                 jsBundleFile = file("$jsBundleDir/$bundleAssetName")
     
                 generateBundledResourcesHash = tasks.create(
    @@ -107,7 +112,7 @@ gradle.projectsEvaluated {
                 generateBundledResourcesHash.dependsOn("recordFilesBeforeBundleCommand${targetName}")
             }
     
    -        generateBundledResourcesHash.dependsOn("bundle${targetName}JsAndAssets")
    +        generateBundledResourcesHash.dependsOn("createBundle${targetName}JsAndAssets")
             runBefore("processArmeabi-v7a${targetName}Resources", generateBundledResourcesHash)
             runBefore("processX86${targetName}Resources", generateBundledResourcesHash)
             runBefore("processUniversal${targetName}Resources", generateBundledResourcesHash)
  2. hengkx commented on Jan 17, 2023

    @hengkx

    same error

  3. lifeoasis-chudee commented on Jan 17, 2023

    @lifeoasis-chudee

    same error

  4. arlovip commented on Jan 17, 2023

    @arlovip

    The same issue.

  5. DmitriyKirakosyan commented on Jan 17, 2023

    @DmitriyKirakosyan
    Contributor

    John Ferlito (@johnf) Thank you for your contribution! Please add the link to this issue in your PR.

  6. tindn commented on Jan 18, 2023

    @tindn

    having the same issue, your suggested patch works John Ferlito (@johnf), thank you for the help.

  7. added a commit that references this issue on Jan 19, 2023
    c89c1d8
  8. added a commit that references this issue on Jan 20, 2023
    8ea841f
  9. clovisrodriguez commented on Jan 24, 2023

    @clovisrodriguez

    I started a new project, on react-native 0.71.1, but when I ran the patch it threw me an error saying it couldn't be applied

    yarn install v1.22.19
    [1/4] 🔍  Resolving packages...
    success Already up-to-date.
    $ patch-package
    patch-package 6.5.1
    Applying patches...
    
    **ERROR** Failed to apply patch for package react-native at path
      
        node_modules/react-native
    
      This error was caused because patch-package cannot apply the following patch file:
    
        patches/react-native+0.71.1.patch
    
      Try removing node_modules and trying again. If that doesn't work, maybe there was
      an accidental change made to the patch file? Try recreating it by manually
      editing the appropriate files and running:
      
        patch-package react-native
      
      If that doesn't work, then it's a bug in patch-package, so please submit a bug
      report. Thanks!
    
        https://github.com/ds300/patch-package/issues
        
    
    ---
    
  10. johnf commented on Jan 24, 2023

    @johnf
    Contributor

    The patch needs an update since the last release. Check the PR here #2419

  11. clovisrodriguez commented on Jan 25, 2023

    @clovisrodriguez

    Thanks, I applied the newest patch using the PR above, but I'm getting a message with the flavour used during the build time

    * What went wrong:
    Could not determine the dependencies of task ':app:generateBundledResourcesHashQaDebug'.
    > Task with path 'bundleQaDebugJsAndAssets' not found in project ':app'.
    

    I applied the patch react-native-code-push.patch

    From c89c1d806bb035d06e5866f6caff8dcbbe2e9075 Mon Sep 17 00:00:00 2001
    From: John Ferlito <johnf@inodes.org>
    Date: Fri, 13 Jan 2023 19:14:43 +1100
    Subject: [PATCH] Support RN 0.71.0 (Closes #2418)
    
    React native now uses react-native-gradle-plugin, which works a bit
    differently.
    ---
     README.md               |  3 ++-
     android/codepush.gradle | 46 ++++++++++++++++++++++++-----------------
     2 files changed, 29 insertions(+), 20 deletions(-)
    
    diff --git a/README.md b/README.md
    index 8e8b25026..6fadc5e90 100644
    --- a/README.md
    +++ b/README.md
    @@ -75,7 +75,8 @@ We try our best to maintain backwards compatibility of our plugin with previous
     | v0.59                   | v5.6+ *(RN refactored js bundle loader code)*         |
     | v0.60-v0.61             | v6.0+ *(RN migrated to Autolinking)*                  |
     | v0.62-v0.64             | v6.2+ *(RN removed LiveReload)*                       |
    -| v0.65-v0.69             | v7.2+ *(RN updated iPhone-target-version)*            |
    +| v0.65-v0.69             | v7.0+ *(RN updated iPhone-target-version)*            |
    +| v0.71                   | v7.2+ *(RN moved to react-native-gradle-plugin)*      |
     
     *NOTE: `react-native-code-push` versions lower than **[v5.7.0](https://github.com/microsoft/react-native-code-push/releases/tag/v5.7.0)** will stop working in the near future. You can find more information in our [documentation](https://github.com/microsoft/code-push/blob/master/migration-notice.md).*
     
    diff --git a/android/codepush.gradle b/android/codepush.gradle
    index 78134d358..bc44ee199 100644
    --- a/android/codepush.gradle
    +++ b/android/codepush.gradle
    @@ -2,8 +2,8 @@
     
     import java.nio.file.Paths;
     
    -def config = project.hasProperty("react") ? project.react : [];
    -def bundleAssetName = config.bundleAssetName ?: "index.android.bundle"
    +def config = project.extensions.findByName("react") ?: []
    +def bundleAssetName = config.bundleAssetName.get() ?: "index.android.bundle"
     
     // because elvis operator
     def elvisFile(thing) {
    @@ -23,11 +23,20 @@ android.buildTypes.each { buildType ->
         buildType.resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())
     }
     
    -gradle.projectsEvaluated { 
    +
    +gradle.projectsEvaluated {
    +
    +    def debuggableVariants = config.debuggableVariants.get() ?: ['debug']
    +
         android.applicationVariants.all { variant ->
    +        // No code push for debuggable variants
    +        if (debuggableVariants.contains(variant.name)) {
    +            return;
    +        }
    +
             def nodeModulesPath;
             if (config.root) {
    -            nodeModulesPath = Paths.get(config.root, "/node_modules");
    +            nodeModulesPath = Paths.get(config.root.asFile.get().absolutePath, "/node_modules");
             } else if (project.hasProperty('nodeModulesPath')) {
                 nodeModulesPath = project.nodeModulesPath
             } else {
    @@ -42,16 +51,16 @@ gradle.projectsEvaluated {
             def jsBundleFile;
     
             // Additional node commandline arguments
    -        def nodeExecutableAndArgs = config.nodeExecutableAndArgs ?: ["node"]
    -        def extraPackagerArgs = config.extraPackagerArgs ?: []
    +        def nodeExecutableAndArgs = config.nodeExecutableAndArgs.get() ?: ["node"]
    +        def extraPackagerArgs = config.extraPackagerArgs.get() ?: []
     
             // Make this task run right after the bundle task
             def generateBundledResourcesHash;
     
    -        if (variant.hasProperty("bundleJsAndAssets")) {
    -            def reactBundleTask = variant.bundleJsAndAssets
    -            jsBundleDir = reactBundleTask.generatedAssetsFolders[0].absolutePath
    -            resourcesDir = reactBundleTask.generatedResFolders[0].absolutePath
    +        def reactBundleTask = tasks.findByName("createBundle${targetName}JsAndAssets")
    +        if (reactBundleTask) {
    +            jsBundleDir = reactBundleTask.property('jsBundleDir').asFile.get()
    +            resourcesDir = reactBundleTask.property('resourcesDir').asFile.get()
                 jsBundleFile = file("$jsBundleDir/$bundleAssetName")
     
                 generateBundledResourcesHash = tasks.create(
    @@ -59,23 +68,21 @@ gradle.projectsEvaluated {
                         type: Exec) {
                     commandLine (*nodeExecutableAndArgs, "${nodeModulesPath}/react-native-code-push/scripts/generateBundledResourcesHash.js", resourcesDir, jsBundleFile, jsBundleDir)
     
    -                enabled config."bundleIn${targetName}" ||
    -                config."bundleIn${variant.buildType.name.capitalize()}" ?:
    -                targetName.toLowerCase().contains("release")
    +                enabled !debuggableVariants.contains(variant.name) ?: targetName.toLowerCase().contains("release")
                 }
    -            
    +
                 runBefore("merge${targetName}Resources", generateBundledResourcesHash)
    -            runBefore("merge${targetName}Assets", generateBundledResourcesHash)   
    +            runBefore("merge${targetName}Assets", generateBundledResourcesHash)
             } else {
                 def jsBundleDirConfigName = "jsBundleDir${targetName}"
    -            jsBundleDir = elvisFile(config."$jsBundleDirConfigName") ?:
    +            jsBundleDir = elvisFile(config."$jsBundleDirConfigName").get() ?:
                         file("$buildDir/intermediates/assets/${targetPath}")
     
                 def resourcesDirConfigName = "resourcesDir${targetName}"
    -            resourcesDir = elvisFile(config."${resourcesDirConfigName}") ?:
    +            resourcesDir = elvisFile(config."${resourcesDirConfigName}").get() ?:
                         file("$buildDir/intermediates/res/merged/${targetPath}")
     
    -            // In case version of 'Android Plugin for Gradle'' is lower than 1.3.0 
    +            // In case version of 'Android Plugin for Gradle'' is lower than 1.3.0
                 // '$buildDir' has slightly different structure - 'merged' folder
                 // does not exists so '${targetPath}' folder contains directly in 'res' folder.
                 if (!resourcesDir.exists() && file("$buildDir/intermediates/res/${targetPath}").exists()) {
    @@ -107,7 +114,8 @@ gradle.projectsEvaluated {
                 generateBundledResourcesHash.dependsOn("recordFilesBeforeBundleCommand${targetName}")
             }
     
    -        generateBundledResourcesHash.dependsOn("bundle${targetName}JsAndAssets")
    +        generateBundledResourcesHash.dependsOn("createBundle${targetName}JsAndAssets")
    +
             runBefore("processArmeabi-v7a${targetName}Resources", generateBundledResourcesHash)
             runBefore("processX86${targetName}Resources", generateBundledResourcesHash)
             runBefore("processUniversal${targetName}Resources", generateBundledResourcesHash)
    
  12. johnf commented on Jan 25, 2023

    @johnf
    Contributor

    Thanks, I applied the newest patch using the PR above, but I'm getting a message with the flavour used during the build time

    * What went wrong:
    Could not determine the dependencies of task ':app:generateBundledResourcesHashQaDebug'.
    > Task with path 'bundleQaDebugJsAndAssets' not found in project ':app'.
    

    Can you share the section of your android/app/build.grade where qa is defined.

    I assume you are using flavours where as I am using variants, might need some changes to support that

  13. clovisrodriguez commented on Jan 25, 2023

    @clovisrodriguez

    Sure, here you go:

    apply plugin: "com.android.application"
    apply plugin: "com.facebook.react"
    apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
    
    import com.android.build.OutputFile
    
    /**
     * This is the configuration block to customize your React Native Android app.
     * By default you don't need to apply any configuration, just uncomment the lines you need.
     */
    react {
        /* Folders */
        //   The root of your project, i.e. where "package.json" lives. Default is '..'
        // root = file("../")
        //   The folder where the react-native NPM package is. Default is ../node_modules/react-native
        // reactNativeDir = file("../node_modules/react-native")
        //   The folder where the react-native Codegen package is. Default is ../node_modules/react-native-codegen
        // codegenDir = file("../node_modules/react-native-codegen")
        //   The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
        // cliFile = file("../node_modules/react-native/cli.js")
    
        /* Variants */
        //   The list of variants to that are debuggable. For those we're going to
        //   skip the bundling of the JS bundle and the assets. By default is just 'debug'.
        //   If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
        // debuggableVariants = ["liteDebug", "prodDebug"]
    
        /* Bundling */
        //   A list containing the node command and its flags. Default is just 'node'.
        // nodeExecutableAndArgs = ["node"]
        //
        //   The command to run when bundling. By default is 'bundle'
        // bundleCommand = "ram-bundle"
        //
        //   The path to the CLI configuration file. Default is empty.
        // bundleConfig = file(../rn-cli.config.js)
        //
        //   The name of the generated asset file containing your JS bundle
        // bundleAssetName = "MyApplication.android.bundle"
        //
        //   The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
        // entryFile = file("../js/MyApplication.android.js")
        //
        //   A list of extra flags to pass to the 'bundle' commands.
        //   See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
        // extraPackagerArgs = []
    
        /* Hermes Commands */
        //   The hermes compiler command to run. By default it is 'hermesc'
        // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
        //
        //   The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
        // hermesFlags = ["-O", "-output-source-map"]
    }
    
    /**
     * Set this to true to create four separate APKs instead of one,
     * one for each native architecture. This is useful if you don't
     * use App Bundles (https://developer.android.com/guide/app-bundle/)
     * and want to have separate APKs to upload to the Play Store.
     */
    def enableSeparateBuildPerCPUArchitecture = false
    
    /**
     * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
     */
    def enableProguardInReleaseBuilds = false
    
    /**
     * The preferred build flavor of JavaScriptCore (JSC)
     *
     * For example, to use the international variant, you can use:
     * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
     *
     * The international variant includes ICU i18n library and necessary data
     * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
     * give correct results when using with locales other than en-US. Note that
     * this variant is about 6MiB larger per architecture than default.
     */
    def jscFlavor = 'org.webkit:android-jsc:+'
    
    /**
     * Private function to get the list of Native Architectures you want to build.
     * This reads the value from reactNativeArchitectures in your gradle.properties
     * file and works together with the --active-arch-only flag of react-native run-android.
     */
    def reactNativeArchitectures() {
        def value = project.getProperties().get("reactNativeArchitectures")
        return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
    }
    
    android {
        ndkVersion rootProject.ext.ndkVersion
    
        compileSdkVersion rootProject.ext.compileSdkVersion
    
        namespace "com.tbitmobile"
        defaultConfig {
            applicationId "com.tbitmobile"
            minSdkVersion rootProject.ext.minSdkVersion
            targetSdkVersion rootProject.ext.targetSdkVersion
            versionCode 1
            versionName "1.0"
        }
    
        flavorDimensions "default"
    
        productFlavors {
            qa {
                minSdkVersion rootProject.ext.minSdkVersion
                applicationIdSuffix ".qa"
                targetSdkVersion rootProject.ext.targetSdkVersion
                resValue "string", "app_name", "T-BIT QA"
                resValue "string", "CodePushDeploymentKey", (CODEPUSH_KEY)
                manifestPlaceholders = [...]
            }
            pr {
                minSdkVersion rootProject.ext.minSdkVersion
                applicationIdSuffix ".prod"
                targetSdkVersion rootProject.ext.targetSdkVersion
                resValue "string", "app_name", "T-BIT"
                resValue "string", "CodePushDeploymentKey", (CODEPUSH_KEY)
                manifestPlaceholders = [...]
            }
        }
    
        splits {
            abi {
                reset()
                enable enableSeparateBuildPerCPUArchitecture
                universalApk false  // If true, also generate a universal APK
                include (*reactNativeArchitectures())
            }
        }
        signingConfigs {
            debug {
                storeFile file('debug.keystore')
                storePassword 'android'
                keyAlias 'androiddebugkey'
                keyPassword 'android'
            }
        }
        buildTypes {
            debug {
                signingConfig signingConfigs.debug
            }
            release {
                // Caution! In production, you need to generate your own keystore file.
                // see https://reactnative.dev/docs/signed-apk-android.
                signingConfig signingConfigs.debug
                minifyEnabled enableProguardInReleaseBuilds
                proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            }
        }
    
        // applicationVariants are e.g. debug, release
        applicationVariants.all { variant ->
            variant.outputs.each { output ->
                // For each separate APK per architecture, set a unique version code as described here:
                // https://developer.android.com/studio/build/configure-apk-splits.html
                // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
                def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
                def abi = output.getFilter(OutputFile.ABI)
                if (abi != null) {  // null for the universal-debug, universal-release variants
                    output.versionCodeOverride =
                            defaultConfig.versionCode * 1000 + versionCodes.get(abi)
                }
    
            }
        }
    }
    
    dependencies {
        // The version of react-native is set by the React Native Gradle Plugin
        implementation("com.facebook.react:react-android")
    
        implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")
    
        debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
        debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
            exclude group:'com.squareup.okhttp3', module:'okhttp'
        }
    
        debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
        if (hermesEnabled.toBoolean()) {
            implementation("com.facebook.react:hermes-android")
        } else {
            implementation jscFlavor
        }
    }
    
    apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
    
  14. ko-devHong commented on Jan 27, 2023

    @ko-devHong

    If you run the patch in the way of John Ferlito (@johnf), it builds normally, but it doesn't actually reflect it.

    스크린샷 2023-01-27 오후 7 28 49

  15. 26 remaining items

  16. arnaud9145 commented on Mar 6, 2023

    @arnaud9145

    John Ferlito (@johnf) I tried my best to reproduce it here : https://github.com/arnaud9145/DebugCodePushRn071

    Tell me if you need anything else :)

    I included install and launch instructions in the README. Note : I only setup android since my problem is android only. if you need it, I can setup ios too.

    What should happen :

    When you launch the app in android studio (work in CLI too with yarn android:uat:release), the build will fail with error "Duplicate resources" in :app:mergeUatreleaseResources step. The asset "node_modules_reactnative_libraries_newappscreen_components_logo.png" is duplicated

    Why :

    The asset is copied twice, once in ./android/app/build/generated/res/react/uat/release/drawable-mdpi/node_modules_reactnative_libraries_newappscreen_components_logo.png and another time in ./android/app/build/generated/res/react/uatRelease/drawable-mdpi/node_modules_reactnative_libraries_newappscreen_components_logo.png

    You can check that after the build, the file should be in both folders.

    Thanks for your help !

  17. johnf commented on Mar 6, 2023

    @johnf
    Contributor

    Arnaud Dufour (@arnaud9145) Thanks that helped. The problem was this line isn't needed https://github.com/arnaud9145/DebugCodePushRn071/blob/main/android/app/build.gradle#L69

    I had neglected to update the README, which I've done now with the new instructions cba29a8

  18. arnaud9145 commented on Mar 7, 2023

    @arnaud9145

    John Ferlito (@johnf) That fixed my problem! Thanks a lot 😄

  19. stefan-schweiger commented on Mar 15, 2023

    @stefan-schweiger

    For anyone struggling with this and expo 48, here is how I'm doing it:

    I'm using this patch #2418 (comment) with patch-package and then I've written a plugin for expo to do the other code push stuff (click to expand):

    plugins/expo-codepush/android/codepush.js
    const { AndroidConfig, withStringsXml, withSettingsGradle, withAppBuildGradle, withMainApplication } = require('@expo/config-plugins');
    
    const setStrings = (strings, name, value) => {
      // Helper to add string.xml JSON items or overwrite existing items with the same name.
      return AndroidConfig.Strings.setStringItem(
        [
          // XML represented as JSON
          { $: { name, translatable: 'false', moduleConfig: 'true' }, _: value },
        ],
        strings,
      );
    };
    
    const applySettings = (gradleSettings) => {
      // Make sure the project does not have the settings already
      if (!gradleSettings.includes(`include ':app', ':react-native-code-push'`)) {
        return (
          gradleSettings +
          `include ':app', ':react-native-code-push'
    project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')`
        );
      }
    
      return gradleSettings;
    };
    
    const applyAppBuildGradle = (appGradleBuild) => {
      // Make sure the project does not have the settings already
      if (!appGradleBuild.includes(`codepush.gradle`)) {
        return appGradleBuild.replace(
          /applyNativeModulesAppBuildGradle\(project\)/g,
          `apply from: new File(projectRoot, "node_modules/react-native-code-push/android/codepush.gradle")
    applyNativeModulesAppBuildGradle(project)`,
        );
      }
    
      return appGradleBuild;
    };
    
    const applyMainApplication = (mainApplication) => {
      // Make sure the project does not have the code already
      if (!mainApplication.includes(`import com.microsoft.codepush.react.CodePush;`)) {
        let app = mainApplication.replace(
          /import com\.facebook\.react\.PackageList;/g,
          `import com.microsoft.codepush.react.CodePush;
    
    import com.facebook.react.PackageList;`,
        );
    
        app = app.replace(
          /new DefaultReactNativeHost\(this\) \{/g,
          `new DefaultReactNativeHost(this) {
          @Override
          protected String getJSBundleFile() {
              return CodePush.getJSBundleFile();
          }
    `,
        );
    
        return app;
      }
    
      return mainApplication;
    };
    
    const withAndroidCodePush = (nativeConfig, deploymentKey) => {
      let config = withSettingsGradle(nativeConfig, (config) => {
        config.modResults.contents = applySettings(config.modResults.contents);
        return config;
      });
    
      config = withAppBuildGradle(config, (config) => {
        config.modResults.contents = applyAppBuildGradle(config.modResults.contents);
        return config;
      });
    
      config = withMainApplication(config, (config) => {
        config.modResults.contents = applyMainApplication(config.modResults.contents);
        return config;
      });
    
      config = withStringsXml(config, (config) => {
        config.modResults = setStrings(config.modResults, 'CodePushDeploymentKey', deploymentKey);
        return config;
      });
    
      return config;
    };
    
    module.exports = { withAndroidCodePush };
    
    plugins/expo-codepush/ios/codepush.js
    const { withAppDelegate, withInfoPlist } = require('@expo/config-plugins');
    
    const applyAppDelegate = (contents) => {
      // Add import
      if (!contents.includes('#import <CodePush/CodePush.h>')) {
        contents = contents.replace(
          /#import "AppDelegate.h"/g,
          `#import "AppDelegate.h"
    #import <CodePush/CodePush.h>`,
        );
      }
    
      // Add new bundle loading
      contents = contents.replace(
        /return \[\[NSBundle mainBundle\] URLForResource:@"main" withExtension:@"jsbundle"\];/g,
        'return [CodePush bundleURL];',
      );
    
      return contents;
    };
    
    const withIosCodePush = (nativeConfig, deploymentKey) => {
      let config = withAppDelegate(nativeConfig, (config) => {
        config.modResults.contents = applyAppDelegate(config.modResults.contents);
        return config;
      });
    
      config = withInfoPlist(config, (config) => {
        config.modResults.CodePushDeploymentKey = deploymentKey;
        return config;
      });
    
      return config;
    };
    
    module.exports = { withIosCodePush };
    
    plugins/expo-codepush/index.js
    const { withPlugins } = require('@expo/config-plugins');
    const { withAndroidCodePush } = require('./android/codepush');
    const { withIosCodePush } = require('./ios/codepush');
    
    const withCodepush = (config, { iosDeploymentKey, androidDeploymentKey }) => {
      return withPlugins(config, [
        // iOS
        [withIosCodePush, iosDeploymentKey],
        // Android
        [withAndroidCodePush, androidDeploymentKey],
      ]);
    };
    
    module.exports = withCodepush;
    

    and then use it like this in App.json/app.config.js:

    {
      expo: {
        // ...
        plugins: [
          [
            './plugins/expo-codepush',
            {
              iosDeploymentKey: '<your-ios-deployment-key>',
              androidDeploymentKey: '<your-android-deployment-key>',
            },
          ]
        ]
      }
    }
    

    expo prebuild should now handle everything else for you and you should be able to build without error and working code push (in release mode). Just be aware that the plugin uses unsafe manipulation, meaning that you might need to change the replacement code a bit if you also have other plugins manipulating the same files and that it can break in a future version of expo/react-native.

  20. vjerryv commented on Mar 15, 2023

    @vjerryv

    still waiting for the official release

  21. arlovip commented on Mar 15, 2023

    @arlovip

    I've been waiting about 2 months for the official release. So when will the new version be released to fix that?

  22. added a commit that references this issue on Mar 21, 2023
    cdca0be
  23. bmaluff commented on Mar 28, 2023

    @bmaluff
    Contributor

    +def config = project.extensions.findByName("react") ?: []

    Hi Luiz Felipe Laviola (@luizfelipelaviola), I'm new at this environment, but I think there is a typo in the line above, since it returns an ArrayList, which doesn't have the method get(), rather it has get(int).
    So I think it should be fixed returning a map object like this [:], which does support get() method.

  24. chenop commented on Apr 11, 2023

    @chenop

    Seems from here that only version 8.x.x supports RN 0.71.

    run:

    yarn upgrade react-native-code-push --latest
    

    to get it

    Also note that the following line was moved to the end of app/build.gradle:

    apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
    
  25. bhavya-thrivase commented on Apr 20, 2023

    @bhavya-thrivase

    My react-native version is 0.71.5 and the react-native-code-push version is 8.0.1 (updated today). I had successfully implemented and tested the codepush functionality 2 weeks before. But suddenly today, its broken.

    I was able to identify the cause of the problem being the URL of the maven repository which was initially located at: https://repo.maven.apache.org/maven2/net/minidev/json-smart/maven-metadata.xml, is inaccessible and not reachable. The package although is still trying to access from here.

    I was able to figure out the updated URL for the maven-metadata.xml:
    https://repo1.maven.org/maven2/net/minidev/json-smart/maven-metadata.xml.

    I tried to make changes to the node_modules but was unsuccessful and thought that changes made to the node_modules would not hold for new app installs.

    Can someone please resolve this issue?

    Thanks in advance

  26. johnf commented on Apr 20, 2023

    @johnf
    Contributor

    I think maven might have been having issues, their DNS seems to be broken right now

  27. bhavya-thrivase commented on Apr 20, 2023

    @bhavya-thrivase

    I think maven might have been having issues, their DNS seems to be broken right now

    Thanks for the reply. Then I think all we can do is be patient and wait for it to be fixed

  28. bhavya-thrivase commented on Apr 20, 2023

    @bhavya-thrivase

    I think maven might have been having issues, their DNS seems to be broken right now

    They have fixed the URL. Will try it and let you know.

  29. added a commit that references this issue on Feb 6, 2024
    d26464b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions