版本信息
遇到的问题 iOS
1. (已解决)iOS执行 pod install 报错 None of your spec sources contain a spec satisfying the dependency: React/Core
.
Analyzing dependencies
Fetching podspec for `DoubleConversion` from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`
Fetching podspec for `Folly` from `../node_modules/react-native/third-party-podspecs/Folly.podspec`
Fetching podspec for `glog` from `../node_modules/react-native/third-party-podspecs/glog.podspec`
[!] CocoaPods could not find compatible versions for pod "React/Core":
In Podfile:
RNImageCropPicker (from `../node_modules/react-native-image-crop-picker`) was resolved to 0.21.3, which depends on
React/Core
None of your spec sources contain a spec satisfying the dependency: `React/Core`.
You have either:
* out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
* mistyped the name or version.
* not added the source repo that hosts the Podspec to your Podfile.
//项目根目录执行以下命令
grep -rl "s.dependency 'React/Core'" node_modules/ | xargs sed -i '' 's=React/Core=React-Core=g'
执行完成没有任何提示,之后继续
cd iOS
pod install
2. (已解决)执行pod install 报错
[!] Error installing Folly
[!] /usr/bin/git clone https://github.com/facebook/folly.git /var/folders/q6/nwts2ggj4j709spst9qb73s40000gp/T/d20221124-11934-1xhyz8b --template= --single-branch --depth 1 --branch v2020.01.13.00
Cloning into '/var/folders/q6/nwts2ggj4j709spst9qb73s40000gp/T/d20221124-11934-1xhyz8b'...
fatal: unable to access 'https://github.com/facebook/folly.git/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream
多次执行报不同错误
[!] Error installing Folly
[!] /usr/bin/git clone https://github.com/facebook/folly.git /var/folders/q6/nwts2ggj4j709spst9qb73s40000gp/T/d20221124-12508-1r35ys8 --template= --single-branch --depth 1 --branch v2020.01.13.00
Cloning into '/var/folders/q6/nwts2ggj4j709spst9qb73s40000gp/T/d20221124-12508-1r35ys8'...
fatal: unable to access 'https://github.com/facebook/folly.git/': Failed to connect to github.com port 443 after 40648 ms: Operation timed out
感觉是网络问题,怎么解决不知道,可能是需要换源地址,可能是需要添加 hosts github的ip。就是一直重复执行
//一直报错一直执行,一路爆红终于安装完成
pod install
3. (已解决)报错 library not found ljanalytics
ld: library not found for -ljanalytics-ios-2.1.2
clang: error: linker command failed with exit code 1 (use -v to see invocation)
需要把
/node_modules/janalytics-react-native/ios/RCTJAnalyticsModule/janalytics-ios-2.1.2.a
文件名修改为libjanalytics-ios-2.1.2.a
4. (已解决)node报错
node:events:491
throw er; // Unhandled 'error' event
^
Error: EMFILE: too many open files, watch
at FSWatcher._handle.onchange (node:internal/fs/watchers:204:21)
Emitted 'error' event on NodeWatcher instance at:
at NodeWatcher.checkedEmitError (/Users/***/project/***/node_modules/sane/src/node_watcher.js:143:12)
at FSWatcher.emit (node:events:513:28)
at FSWatcher._handle.onchange (node:internal/fs/watchers:210:12) {
errno: -24,
syscall: 'watch',
code: 'EMFILE',
filename: null
}
尝试1:网上资料很多都是说端口占用,试过没有效果
1、查看全部端口
sudo lsof -i
2、查看端口监听情况
sudo lsof -i -P | grep -i "listen"
3、查看特定端口
sudo lsof -i:2425
4、查询到之后通过PID进行kill
kill PID
尝试2:
解决办法: 未按官方文档要求安装watchman
brew install watchman
5. (已解决)iOS图片不能加载
应用在IOS 14.0下调试无法显示图片
解决办法:
修改文件RCTUIImageViewAnimated.m 270行左右
路径如:/node_modules/react-native/Libraries/Image 下文件
- (void)displayLayer:(CALayer *)layer
{
if (_currentFrame) {
layer.contentsScale = self.animatedImageScale;
layer.contents = (__bridge id)_currentFrame.CGImage;
}
}
改成下面:
- (void)displayLayer:(CALayer *)layer
{
if (_currentFrame) {
layer.contentsScale = self.animatedImageScale;
layer.contents = (__bridge id)_currentFrame.CGImage;
}else{
[super displayLayer:layer];
}
}
6. (已解决)iOS选择图片上传报错,Domain=RCTErrorDomain Code=0 "Invalid request token
react-native库报错,使用patch-package这个库可以解决修改本地库造成的团队协作问题
解决办法:
1、修改react-native库
//文件位置
that exists in node_modules/react-native/Libraries/Image/RCTImageLoader.mm
//替换一下方法所有内容
-(id)sendRequest:(NSURLRequest *)request withDelegate:
修改成一下内容
- (id)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequestDelegate>)delegate
{
@synchronized(self) {
__block RCTImageLoaderCancellationBlock requestToken = ^{};
requestToken = [self loadImageWithURLRequest:request callback:^(NSError *error, UIImage *image) {
@synchronized(self) {
if (error) {
[delegate URLRequest:requestToken didCompleteWithError:error];
return;
}
NSString *mimeType = nil;
NSData *imageData = nil;
if (RCTImageHasAlpha(image.CGImage)) {
mimeType = @"image/png";
imageData = UIImagePNGRepresentation(image);
} else {
mimeType = @"image/jpeg";
imageData = UIImageJPEGRepresentation(image, 1.0);
}
NSURLResponse *response = [[NSURLResponse alloc] initWithURL:request.URL
MIMEType:mimeType
expectedContentLength:imageData.length
textEncodingName:nil];
[delegate URLRequest:requestToken didReceiveResponse:response];
[delegate URLRequest:requestToken didReceiveData:imageData];
[delegate URLRequest:requestToken didCompleteWithError:nil];
}
}];
return requestToken;
}
}
- 安装patch-package
安装比较慢,需替换源地址
//查看npm源
npm get registry
//替换淘宝源
npm config set registry http://registry.npm.taobao.org
遇到的问题 Android
1. 环境问题jdk环境变量配置问题,这个问题是环境变量配置和环境不熟悉
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
Exception: Gradle task assembleDebug failed with exit code 1
安装了flutter并且是正常运行Android的,于是忽略了。重新安装就好了
@felixdeMacBook-Pro ~ % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.3.8, on macOS 12.6 21G115 darwin-x64, locale
zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.73.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
• No issues found!
@felixdeMacBook-Pro ~ % which java
/usr/bin/java
@felixdeMacBook-Pro ~ % which javac
/usr/bin/javac
@felixdeMacBook-Pro ~ %
@felixdeMacBook-Pro ~ % java -version
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
下载jdk 完成后直接安装
@felixdeMacBook-Pro ~ % java -version
java version "19.0.1" 2022-10-18
Java(TM) SE Runtime Environment (build 19.0.1+10-21)
Java HotSpot(TM) 64-Bit Server VM (build 19.0.1+10-21, mixed mode, sharing)
2. (已解决)gradle版本过低,改成7.4重新运行解决问题
Configuration on demand is an incubating feature.
FAILURE: Build failed with an exception.
* What went wrong:
Could not open settings generic class cache for settings file '/Users/***/project/***/android/settings.gradle' (/Users/***/.gradle/caches/7.4/scripts/b7pnedn7pgzpudl06hpdmqbc1).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 63
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
3. (已解决)jdk版本过高,安装的是19,报错卸载重新安装11运行成功
jdk官网下载太慢,这里用的是华为源
需要进入JavaVirtualMachines目录
//cd根目录
cd /
cd Library
cd Java
cd JavaVirtualMachines
//查看所有版本
ls
//删除
sudo rm -rf 需要删除的版本
Configuration on demand is an incubating feature.
FAILURE: Build failed with an exception.
* What went wrong:
Could not open settings generic class cache for settings file '/Users/***/project/tour-guide-app/android/settings.gradle' (/Users/***/.gradle/caches/7.4/scripts/b7pnedn7pgzpudl06hpdmqbc1).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 63
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
4. (已解决)of type 'class java.lang.String' as boolean. Expected 'true' or 'false'.
这个问题是gradle.properties文件android.useAndroidX=true后面无输入空格,查看报错地方是否有空格,删除多余空格即可
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/******/project/tour-guide-app/android/app/build.gradle' line: 1
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.version-check'.
> Cannot parse project property android.useAndroidX='true ' of type 'class java.lang.String' as boolean. Expected 'true' or 'false'.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
5. (未解决)ReactNative libc++_shared.so 冲突导致的uncaught exception of type std::bad_cast:
这个问题场景是百度地图插件,更新到1.0.37作者已经没有维护了,我碰得到问题是部分Android手机打开地图会闪退,具体的原因是jar包网络监听方法报错。
解决方法:
1.尝试失败,首先想到的是更新原生Android百度地图SDK,但是会报动态库编译libc++_shared.so冲突,packagingOptions 排除'lib/x86/libc++_shared.so' 会报如题错误。查资料一般都是重新编译三方库,知识盲区只能放弃了。
2.根据错误修改现在代码,定位报错信息发现是BaiduLBS_Android.jar网络监听报错,看到这大概有了思路,简单粗暴直接把相关的方法干掉。于是就有了如何修改jar包单个class文件,亲历可解决部分问题,步骤上面方法已经有了,这里说下注意的地方:
注意的地方:
//修改后的java打包成class文件,
javac -classpath android/app/src/e.java
这个有个坑,一般java文件都会引入Android.jar或者其他的文件,直接转会报找不到文件,需要将相关的jar包放到同级,多个jar包可以用: 号连接,这里是mac的方法,Windows好像是;分号,没有试过
javac -classpath android.jar:BaiduLBS_Android.jar e.java
完整步骤:
1.解析jar文件成class文件
jar xf BaiduLBS_Android.jar
2.使用工具或vscode安装插件,将class文件解析成java可读性强的文件,并打包成class
javac -classpath android.jar:BaiduLBS_Android.jar e.java
3.替换修改的class,并将所有class文件打包成jar文件,cd 到class文件目录并执行
jar -cvf BaiduLBS_Android.jar ./