I have a project employing React-Native. I'm building the RN module from source, so my project has the ReactAndroid module as a dependency.
I was trying to upgrade the project to Android gradle build tools >=2.3.2, so I could use intant-run:
buildscript {
repositories {
jcenter()
mavenLocal()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
...
}
}
This change forced me to upgrade gradle itself from 3.1 to 3.5 (latest stable).
Building the project suddenly produces the following gradle error
Could not get unknown property 'repositoryUrl' for project ':ReactAndroid' of type org.gradle.api.Project.
Can anyone help?
Well, this turned out interesting.
The error pointed to the this line at the React-Native module's release.gradle
:
def getRepositoryUrl() {
return hasProperty('repositoryUrl') ? property('repositoryUrl') : 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
}
Strangely enough, the problem is that hasProperty('repositoryUrl')
returns true
, while property('repositoryUrl')
causes the error.
On gradle 3.1, hasProperty('repositoryUrl')
returns false
.
Apparently in gradle 3.5, hasProperty()
returns true
in cases where the property is indeed missing but still has a getter. In our case the getter is
def getRepositoryUrl() {...}
This is vaguely explained here.
There is however another method of checking for properties, which ignores getters, named findProperty.
So the fix was to change the following block from release.gradle
:
def getRepositoryUrl() {
return hasProperty('repositoryUrl') ? property('repositoryUrl') : 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
}
def getRepositoryUsername() {
return hasProperty('repositoryUsername') ? property('repositoryUsername') : ''
}
def getRepositoryPassword() {
return hasProperty('repositoryPassword') ? property('repositoryPassword') : ''
}
To this:
def getRepositoryUrl() {
return findProperty('repositoryUrl') != null ? property('repositoryUrl') : 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
}
def getRepositoryUsername() {
return findProperty('repositoryUsername') !=null ? property('repositoryUsername') : ''
}
def getRepositoryPassword() {
return findProperty('repositoryPassword') != null ? property('repositoryPassword') : ''
}
More pains experienced while building the RN module from source here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With