記錄運行一個react-native遇到的問題

版本信息

遇到的問題 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;
  }
}
  1. 安裝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 ./

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末猜绣,一起剝皮案震驚了整個濱河市灰殴,隨后出現(xiàn)的幾起案子敬特,更是在濱河造成了極大的恐慌掰邢,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,311評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件伟阔,死亡現(xiàn)場離奇詭異辣之,居然都是意外死亡,警方通過查閱死者的電腦和手機皱炉,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,339評論 2 382
  • 文/潘曉璐 我一進(jìn)店門怀估,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人合搅,你說我怎么就攤上這事多搀。” “怎么了灾部?”我有些...
    開封第一講書人閱讀 152,671評論 0 342
  • 文/不壞的土叔 我叫張陵康铭,是天一觀的道長。 經(jīng)常有香客問我赌髓,道長从藤,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,252評論 1 279
  • 正文 為了忘掉前任锁蠕,我火速辦了婚禮夷野,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘荣倾。我一直安慰自己悯搔,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 64,253評論 5 371
  • 文/花漫 我一把揭開白布舌仍。 她就那樣靜靜地躺著鳖孤,像睡著了一般。 火紅的嫁衣襯著肌膚如雪抡笼。 梳的紋絲不亂的頭發(fā)上苏揣,一...
    開封第一講書人閱讀 49,031評論 1 285
  • 那天,我揣著相機與錄音推姻,去河邊找鬼平匈。 笑死,一個胖子當(dāng)著我的面吹牛藏古,可吹牛的內(nèi)容都是我干的增炭。 我是一名探鬼主播,決...
    沈念sama閱讀 38,340評論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼拧晕,長吁一口氣:“原來是場噩夢啊……” “哼隙姿!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起厂捞,我...
    開封第一講書人閱讀 36,973評論 0 259
  • 序言:老撾萬榮一對情侶失蹤输玷,失蹤者是張志新(化名)和其女友劉穎队丝,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體欲鹏,經(jīng)...
    沈念sama閱讀 43,466評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡机久,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 35,937評論 2 323
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了赔嚎。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片膘盖。...
    茶點故事閱讀 38,039評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖尤误,靈堂內(nèi)的尸體忽然破棺而出侠畔,到底是詐尸還是另有隱情,我是刑警寧澤损晤,帶...
    沈念sama閱讀 33,701評論 4 323
  • 正文 年R本政府宣布践图,位于F島的核電站,受9級特大地震影響沉馆,放射性物質(zhì)發(fā)生泄漏码党。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,254評論 3 307
  • 文/蒙蒙 一斥黑、第九天 我趴在偏房一處隱蔽的房頂上張望揖盘。 院中可真熱鬧,春花似錦锌奴、人聲如沸兽狭。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,259評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽箕慧。三九已至,卻和暖如春茴恰,著一層夾襖步出監(jiān)牢的瞬間颠焦,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,485評論 1 262
  • 我被黑心中介騙來泰國打工往枣, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留伐庭,地道東北人。 一個月前我還...
    沈念sama閱讀 45,497評論 2 354
  • 正文 我出身青樓分冈,卻偏偏與公主長得像圾另,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子雕沉,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 42,786評論 2 345

推薦閱讀更多精彩內(nèi)容