最近一个n年前的RN项目需要重新打包,遇到很多问题,在这里记录一下。
旧项目的相关依赖包版本:
"react": "16.0.0-beta.5",
"react-native": "0.49.3",
"react-native-device-info": "^0.17.4",
环境配置相关:
// 低于 0.67 版本的 React Native 需要 JDK 1.8 版本(官方也称 8 版本)。
JDK openjdk version "1.8.0_42"
NDK android-ndk-r10e
node 10.24.1
npm 6.14.12
React Native v0.49 构建打包相关文档链接:
https://github.com/reactnativecn/react-native-website/blob/production/archived_docs/version-0.49/android-building-from-source.md
错误问题 & 解决方法记录
1. ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:font
解决方法:
https://github.com/react-native-device-info/react-native-device-info/issues/694
将此代码添加到您的项目android/build.gradle,解决了
ext {
buildToolsVersion ="23.0.1"
minSdkVersion = 16
compileSdkVersion = 23
targetSdkVersion = 23
supportLibVersion ="23.0.0"
googlePlayServicesVersion ="15.0.1" //重点是这句
}
2. 程序包com.facebook.react不存在
问题1中 修改了 googlePlayServicesVersion,会出现问题2,
解决方法:
在项目下的 android/build.gradle 文件中添加如下代码,即可成功编译
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
allprojects {
configurations.all {
resolutionStrategy {
// Remove this override in 0.65+, as a proper fix is included in react-native itself.
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
}
3. Unable to process incoming event 'ProgressComplete ' (ProgressCompleteEvent)
解决方法:
打包时使用以下命令
./gradlew assembleRelease --console plain //我是这条命令解决的
或者
./gradlew assembleRelease –-stacktrace
标签:react,React,android,Native,com,打包,native
From: https://www.cnblogs.com/djzz/p/16929630.html