React-native-code-push: [CodePush] Unable to get the hash of the binary's bundled resources - "codepush.gradle" may have not been added to the build definition.

Created on 8 Mar 2019  路  4Comments  路  Source: microsoft/react-native-code-push

Steps to Reproduce

  1. ./gradlew assembleRelease
  2. adb install app-release.apk
  3. OR react-native run-android --variant=release

Expected Behavior

App should run with CodePush working

Actual Behavior

[CodePush] Unable to get the hash of the binary's bundled resources - "codepush.gradle" may have not been added to the build definition.

03-07 22:47:05.386 5738 5803 I ReactNativeJS: Running application "myapp" with appParams: {"rootTag":1}. __DEV__ === false, development-level warning are OFF, performance optimizations are ON
03-07 22:47:11.136 5738 5738 D ReactNative: ReactInstanceManager.detachViewFromInstance()
03-07 22:47:13.955 5841 5841 D ReactNative: [CodePush] Loading JS bundle from "assets://index.android.bundle"
03-07 22:47:13.956 5841 5841 D ReactNative: ReactInstanceManager.ctor()
03-07 22:47:13.969 5841 5841 D ReactNative: ReactInstanceManager.createReactContextInBackground()
03-07 22:47:13.970 5841 5841 D ReactNative: ReactInstanceManager.recreateReactContextInBackgroundInner()
03-07 22:47:13.970 5841 5841 D ReactNative: ReactInstanceManager.recreateReactContextInBackgroundFromBundleLoader()
03-07 22:47:13.970 5841 5841 D ReactNative: ReactInstanceManager.recreateReactContextInBackground()
03-07 22:47:13.970 5841 5841 D ReactNative: ReactInstanceManager.runCreateReactContextOnNewThread()
03-07 22:47:14.042 5841 5888 D ReactNative: ReactInstanceManager.createReactContext()
03-07 22:47:14.376 5841 5888 D ReactNative: [CodePush] Unable to get the hash of the binary's bundled resources - "codepush.gradle" may have not been added to the build definition.
03-07 22:47:14.430 5841 5888 D ReactNative: Initializing React Xplat Bridge.
03-07 22:47:14.437 5841 5888 D ReactNative: Initializing React Xplat Bridge before initializeBridge
03-07 22:47:14.449 5841 5888 D ReactNative: Initializing React Xplat Bridge after initializeBridge
03-07 22:47:14.450 5841 5888 D ReactNative: CatalystInstanceImpl.runJSBundle()
.
.
.

My app gradle build is as follows:

apply plugin: "com.android.application"
apply plugin: "com.google.firebase.firebase-perf"
apply plugin: 'io.fabric'

import com.android.build.OutputFile

project.ext.react = [
  entryFile: "index.js"
]

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

def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
  compileSdkVersion 26
  buildToolsVersion "26.0.2"

  defaultConfig {
      applicationId "com.myapp.myapp"
      minSdkVersion 16
      targetSdkVersion 26
      versionCode 20
      versionName "1.144"
      ndk {
          abiFilters "armeabi-v7a", "x86"
      }
      // because of firestore:
      multiDexEnabled true
  }

  sourceSets {
    debug {
        java.srcDirs('src/debug/java')
      }
  }

  lintOptions {
    disable 'GradleCompatible'
    disable 'InvalidPackage'
  }

  // because of firestore:
  dexOptions {
    javaMaxHeapSize "4g"
  }

  signingConfigs {
    release {
        if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
            storeFile file(MYAPP_RELEASE_STORE_FILE)
            storePassword MYAPP_RELEASE_STORE_PASSWORD
            keyAlias MYAPP_RELEASE_KEY_ALIAS
            keyPassword MYAPP_RELEASE_KEY_PASSWORD
        }
    }
}
  splits {
    abi {
      reset()
      enable enableSeparateBuildPerCPUArchitecture
      universalApk false  // If true, also generate a universal APK
      include "armeabi-v7a", "x86"
    }
  }
  buildTypes {
    debug {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      buildConfigField "String", "CODEPUSH_KEY", '""'
    }
    release {
      buildConfigField "String", "CODEPUSH_KEY", '<REDACTED>"'
      signingConfig signingConfigs.release
      minifyEnabled false
      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:
      // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
      def versionCodes = ["armeabi-v7a": 1, "x86": 2]
      def abi = output.getFilter(OutputFile.ABI)
      if (abi != null) {  // null for the universal-debug, universal-release variants
        output.versionCodeOverride =
          versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
      }
    }
  }
}

dependencies {
  compile project(':react-native-code-push')
.
.
.
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

I'm not sure what I'm missing, the other similar issues do not seem to apply or help me. Do I need to generate my APK some other way?

Most helpful comment

Did you solve this ? I'm facing the same issue.

All 4 comments

Did you solve this ? I'm facing the same issue.

Hi, @cristian-rita did you solve this? Thanks

Facing the same issue with a build variant, works fine with the regular release version but not my release variant for staging

Also seeing this

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Phredward picture Phredward  路  3Comments

kevando picture kevando  路  4Comments

ninjz picture ninjz  路  4Comments

EdmundMai picture EdmundMai  路  4Comments

ACCTFORGH picture ACCTFORGH  路  3Comments