遇到的错误:
Gradle sync failed: Could not get unknown property 'repositoryUrl' for project ':ReactAndroid' of type org.gradle.api.Project. Consult IDE log for more details (Help | Show Log) (1s 199ms)
错误日志:
Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'repositoryUrl' for project ':ReactAndroid' of type org.gradle.api.Project.
at org.gradle.internal.metaobject.AbstractDynamicObject.getMissingProperty(AbstractDynamicObject.java:83)
at org.gradle.internal.metaobject.AbstractDynamicObject.getProperty(AbstractDynamicObject.java:61)
at org.gradle.api.internal.project.DefaultProject.property(DefaultProject.java:991)
at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:479)
at org.gradle.internal.metaobject.BeanDynamicObject.tryInvokeMethod(BeanDynamicObject.java:191)
at org.gradle.internal.metaobject.CompositeDynamicObject.tryInvokeMethod(CompositeDynamicObject.java:98)
at org.gradle.internal.metaobject.MixInClosurePropertiesAsMethodsDynamicObject.tryInvokeMethod(MixInClosurePropertiesAsMethodsDynamicObject.java:30)
at org.gradle.groovy.scripts.BasicScript$ScriptDynamicObject.tryInvokeMethod(BasicScript.java:134)
at org.gradle.internal.metaobject.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:160)
at org.gradle.groovy.scripts.BasicScript.invokeMethod(BasicScript.java:83)
at release_9x18o9zsjs6a4z2wl9jziipro.getRepositoryUrl(C:\jessiework\devel\RN\MyProject\node_modules\react-native\ReactAndroid\release.gradle:15)
at org.gradle.internal.metaobject.BeanDynamicObject$GroovyObjectAdapter.invokeOpaqueMethod(BeanDynamicObject.java:579)
at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:506)
at org.gradle.internal.metaobject.BeanDynamicObject.tryInvokeMethod(BeanDynamicObject.java:191)
解决方案:
将ReactAndroid 的release.gradle 中定义的三个任务修改如下:
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') : ''
}
编译慢的解决办法:
编译慢主要的原因出在 ReactAndroid 的build.gradle 的一个下载任务上, boost文件的大约为100M+ 原生的下载路径需要vpn,找到一个替代的下载源,修改如下:
task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
//src 'https://github.com/react-native-community/boost-for-react-native/releases/download/v1.63.0-0/boost_1_63_0
// .tar.gz'
src 'http://jaist.dl.sourceforge.net/project/boost/boost/1.63.0/boost_1_63_0.tar.gz'
onlyIfNewer true
overwrite false
dest new File(downloadsDir, 'boost_1_63_0.tar.gz')
}
NDK 报错:
Android NDK: android-9 is unsupported. Using minimum supported version android-14.
make: Entering directoryC:/jessiework/devel/RN/talos-dev/react-native/ReactAndroid/src/main/jni/react/jni' C:/Users/****/AppData/Local/Android/sdk/ndk-bundle/build//../build/core/build-binary.mk:688: Android NDK: Module reactnativejni depends on undefined modules: fbjni make: Leaving directory
C:/jessiework/devel/RN/talos-dev/react-native/ReactAndroid/src/main/jni/react/jni'
C:/Users/*****/AppData/Local/Android/sdk/ndk-bundle/build//../build/core/build-binary.mk:701: *** Android NDK: Aborting (set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies) . Stop.
:react-native:ReactAndroid:buildReactNdkLib FAILED
FAILURE: Build failed with an exception.* What went wrong:
Execution failed for task ':react-native:ReactAndroid:buildReactNdkLib'.
Process 'command 'C:\Users***\AppData\Local\Android\Sdk\ndk-bundle\ndk-build.cmd'' finished with non-zero exit value 2
解决方案
必须使用ndk-jr10e 版本
参考资料:
https://stackoverflow.com/questions/43967489/could-not-get-unknown-property-repositoryurl-for-project
http://reactnative.cn/docs/0.24/android-buildingfromsource.html
//www.greatytc.com/p/bd4bcdceba9b