React-native-code-push: [android] Running with automatic react-native-versioning

Created on 6 Nov 2016  路  3Comments  路  Source: microsoft/react-native-code-push

  • iOS/Android/Windows version: Android
  • Repro steps and/or stack trace:

Ok, So I'm trying to run code-push release-react MyApp android -m
But I get this:

Detecting android app version:
[Error] No property named "userVer" exists in the "android/gradle.properties" file.

This happens because I use an automatic gradle script which gets my app version from npm automatically.
My gradle script looks like this:

apply plugin: "com.android.application"

import com.android.build.OutputFile
import groovy.json.JsonSlurper

def getNpmVersion() {
    def inputFile = new File("../package.json")
    def packageJson = new JsonSlurper().parseText(inputFile.text)
    return packageJson["version"]
}
/* calculated from git commits to give sequential integers */
def getGitVersion() {
    def process = "git rev-list master --first-parent --count".execute()
    return process.text.toInteger()
}

def userVer = getNpmVersion()
def googleVer = getGitVersion()

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 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode googleVer
        versionName userVer
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        debug {
...bla bla
        }
        release {
bla bla        }
    }
    // 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')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules

    compile ('com.google.android.gms:play-services-gcm:8.1.0') {
        force = true;
    }
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
  from configurations.compile
  into 'libs'
}

So basically userVer is generated automatically with a script here..

How do I make it work regardless? any thought?

All 3 comments

Hi @DeDuckProject, there is a --targetBinaryVersion flag (documentation) that you can use here to explicitly specify the app version(s) that you'd like to target. You can specify this manually, or if you'd like, you could also automate this by writing some kind of script. Does that help?

@silhouettes , thanks for the answer.
I've actually started using targetBinaryVersion because I want to target an older version than the current one. So I wonder why I ever wanted to run this without that flag ;)

Thanks that resolved the issue for me as well..

I was using a function (defined in app.gradle) to automatically set the version of our app the same as what is defined in package.json like so:

def getVersionFromPackageJson() {
    def inputFile = new File("../package.json")
    def packageJson = new JsonSlurper().parseText(inputFile.text)
    return packageJson["version"]
}
def getVersionCodeFromPackageJson() { // major [0], minor [1], patch [2]
    def (major, minor, patch) = getVersionFromPackageJson().tokenize('.')
    def npmVersionArr = [Integer.parseInt(major), Integer.parseInt(minor), Integer.parseInt(patch)] as int[]
    def npmVersion = npmVersionArr[0] * 10000 + npmVersionArr[1] * 100 + npmVersionArr[2]
    return npmVersion
}

defaultConfig {
        ....
        minSdkVersion 16
        targetSdkVersion 22
        versionCode getAcuityVersionCodeFromPackageJson()
        versionName getAcuityVersionFromPackageJson()
        ....
    }

and received the following error:
[Error] No property named "getVersionFromPackageJson()" exists in the "android/gradle.properties" file.

Now it's ok.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

panarasi picture panarasi  路  4Comments

EdmundMai picture EdmundMai  路  4Comments

diegocouto picture diegocouto  路  4Comments

chrisjrex picture chrisjrex  路  4Comments

kevando picture kevando  路  4Comments