版本信息
遇到的問題 iOS
1. (已解決)iOS執(zhí)行 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.
//項目根目錄執(zhí)行以下命令
grep -rl "s.dependency 'React/Core'" node_modules/ | xargs sed -i '' 's=React/Core=React-Core=g'
執(zhí)行完成沒有任何提示,之后繼續(xù)
cd iOS
pod install
2. (已解決)執(zhí)行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
多次執(zhí)行報不同錯誤
[!] 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
感覺是網(wǎng)絡(luò)問題室琢,怎么解決不知道,可能是需要換源地址竞穷,可能是需要添加 hosts github的ip。就是一直重復(fù)執(zhí)行
//一直報錯一直執(zhí)行,一路爆紅終于安裝完成
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:網(wǎng)上資料很多都是說端口占用纵顾,試過沒有效果
1洁奈、查看全部端口
sudo lsof -i
2间唉、查看端口監(jiān)聽情況
sudo lsof -i -P | grep -i "listen"
3、查看特定端口
sudo lsof -i:2425
4利术、查詢到之后通過PID進(jìn)行kill
kill PID
嘗試2:
解決辦法: 未按官方文檔要求安裝watchman
brew install watchman
5. (已解決)iOS圖片不能加載
應(yīng)用在IOS 14.0下調(diào)試無法顯示圖片
解決辦法:
修改文件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這個庫可以解決修改本地庫造成的團(tuán)隊協(xié)作問題
解決辦法:
1呈野、修改react-native庫
//文件位置
that exists in node_modules/react-native/Libraries/Image/RCTImageLoader.mm
//替換一下方法所有內(nèi)容
-(id)sendRequest:(NSURLRequest *)request withDelegate:
修改成一下內(nèi)容
- (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. 環(huán)境問題jdk環(huán)境變量配置問題印叁,這個問題是環(huán)境變量配置和環(huán)境不熟悉
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官網(wǎng)下載太慢,這里用的是華為源
需要進(jìn)入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 沖突導(dǎo)致的uncaught exception of type std::bad_cast:
這個問題場景是百度地圖插件,更新到1.0.37作者已經(jīng)沒有維護(hù)了闲延,我碰得到問題是部分Android手機打開地圖會閃退痊剖,具體的原因是jar包網(wǎng)絡(luò)監(jiān)聽方法報錯。
解決方法:
1.嘗試失敗垒玲,首先想到的是更新原生Android百度地圖SDK陆馁,但是會報動態(tài)庫編譯libc++_shared.so沖突,packagingOptions 排除'lib/x86/libc++_shared.so' 會報如題錯誤合愈。查資料一般都是重新編譯三方庫叮贩,知識盲區(qū)只能放棄了。
2.根據(jù)錯誤修改現(xiàn)在代碼佛析,定位報錯信息發(fā)現(xiàn)是BaiduLBS_Android.jar網(wǎng)絡(luò)監(jiān)聽報錯益老,看到這大概有了思路,簡單粗暴直接把相關(guān)的方法干掉寸莫。于是就有了如何修改jar包單個class文件捺萌,親歷可解決部分問題,步驟上面方法已經(jīng)有了膘茎,這里說下注意的地方:
注意的地方:
//修改后的java打包成class文件桃纯,
javac -classpath android/app/src/e.java
這個有個坑,一般java文件都會引入Android.jar或者其他的文件披坏,直接轉(zhuǎn)會報找不到文件态坦,需要將相關(guān)的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文件目錄并執(zhí)行
jar -cvf BaiduLBS_Android.jar ./