2017-05-04 161 views
9

我真的不知道是怎麼回事。 我已經建立了一個基本的應用程序,並使用代碼共享方法發現here。 這一切都非常基本的,所以這裏的代碼:陣營 - 原生Android:錯誤調用AppRegistry.runApplication

// index.android.js 
// index.ios.js 
import React, { AppRegistry } from 'react-native'; 
import CompetitionAgent from './app/index'; 

AppRegistry.registerComponent('CompetitionAgent',() => CompetitionAgent); 

和組件:

//./app/index.js 
import React, { Component } from 'react'; 
import { 
    StyleSheet, 
    Text, 
    TextInput, 
    View 
} from 'react-native'; 

export default class CompetitionAgent extends Component { 
    constructor() { 
     super(); 
     this.state = {nickname:''}; 
    } 
    render() { 
     return (
      <View style={styles.container}> 
       <View style={styles.information}> 
        <Text style={styles.welcome}> 
         Welcome to the Competition Agent Connect app! 
        </Text> 
        <Text style={styles.instructions}> 
         When you are near a Competition Agent, you can join the session. 
        </Text> 
       </View> 
       <View style={{padding:10}}> 
        <TextInput style={styles.inputStyle} /> 
       </View> 
      </View> 
     ); 
    } 
} 

const styles = StyleSheet.create({ 
    container: { 
     flex: 1, 
     justifyContent: 'center', 
    }, 
    information: { 
     alignItems: 'center', 
     backgroundColor: '#F5FCFF', 
    }, 
    welcome: { 
     fontSize: 20, 
     textAlign: 'center', 
     margin: 10, 
    }, 
    instructions: { 
     textAlign: 'center', 
     color: '#333333', 
     marginBottom: 5, 
    }, 
    inputStyle: { 
     flexDirection: 'row', 
     backgroundColor: '#3E3134', 
     color: '#FFFFFF', 
    } 
}); 

我知道錯誤可能是很多事情。所以這個基本的佈局會產生相同的錯誤。

import React, { Component } from 'react'; 
import { 
    StyleSheet, 
    Text, 
    TextInput, 
    View 
} from 'react-native'; 

export default class CompetitionAgent extends Component { 
    constructor() { 
     super(); 
     this.state = {nickname:''}; 
    } 
    render() { 
     return (
      <View style={styles.container}> 
       <Text style={styles.information}> 
        Welcome to the Competition Agent Connect app! 
       </Text> 
      </View> 
     ); 
    } 
} 

const styles = StyleSheet.create({ 
    container: { 
     flex: 1, 
     justifyContent: 'center', 
    }, 
    information: { 
     alignItems: 'center', 
     backgroundColor: '#F5FCFF', 
    } 
}); 

堆棧跟蹤:

E/unknown:React: Exception in native call 
               java.lang.RuntimeException: Error calling AppRegistry.runApplication 
                at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) 
                at android.os.Handler.handleCallback(Handler.java:739) 
                at android.os.Handler.dispatchMessage(Handler.java:95) 
                at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31) 
                at android.os.Looper.loop(Looper.java:158) 
                at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:208) 
                at java.lang.Thread.run(Thread.java:818) 
               Caused by: com.facebook.jni.CppException: Could not get BatchedBridge, make sure your bundle is packaged correctly 
                at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)  
                at android.os.Handler.handleCallback(Handler.java:739)  
                at android.os.Handler.dispatchMessage(Handler.java:95)  
                at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)  
                at android.os.Looper.loop(Looper.java:158)  
                at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:208)  
                at java.lang.Thread.run(Thread.java:818)  

昨天就好跑,重新啓動Android的工作室都於事無補。

回答

18

如果您運行在Android Studio中的應用程序,那麼你就必須使用react-native start從反應項目的文件夾,從命令行的反應本地打包。

您還可以設置使用adb reverse tcp:8081 tcp:8081 Android的端口轉發。

你有沒有做過那些?

+0

我會試試看。我的Mac從昨天開始就處於待機狀態,並且一切正常,工作正常......我不太熟悉Mac或打包者。猜猜我有幾件事要弄清楚。 – DerpyNerd

+0

看看是否適合你。反應包裝商偶爾會自行死亡,因此必須重新啓動。 – YSK

+0

經驗教訓和指出。開始打包並設置端口轉發並重新運行...謝謝 – DerpyNerd

5

它幫助我時,我已經設置了正確的路徑爲

ANDROID_HOME = C:\Users\username\AppData\Local\Android\sdk 

和工具:

%ANDROID_HOME%\build-tools 
%ANDROID_HOME%\platform-tools 
%ANDROID_HOME%\tools 
+0

這是有用的信息,但您是否收到相同的錯誤消息?這似乎很奇怪,因爲這個錯誤只在我運行我的應用程序時出現。這意味着應用程序在過去已經成功構建和捆綁。沒有SDK和工具鏈接正確,你不可能有一個成功的構建,或者我錯了嗎? – DerpyNerd

+0

我有一個「構建成功」的消息,雖然也有「java.lang.RuntimeException:Error調用AppRegistry.runApplication」 當我正確設置路徑它已經消失。順便說一句,我只有一個ANDROID_HOME的PATH,但沒有它的工具。 – ivts

+0

爲了構建你必須設置所有描述lvts的路徑,你是否已經運行了打包程序?該設備必須能夠連接到打包程序才能運行您剛剛構建的代碼 – DerpyNerd

1

我也有類似的問題。試圖讓它在設備上運行時,我會遇到此錯誤。它在我電腦上的模擬器上正常工作。

問題是我什麼時候做adb devicesreact-native run-android我會得到「ADB不被識別爲內部或外部命令」。

所以我的修復是路徑adb.exe的父目錄添加到我的環境變量,然後重新啓動我的命令提示。我這樣做後,adb devices不會拋出「無法識別的內部外部等等」,它列出了我的設備。然後我運行react-native run-android,並在啓動時不再顯示紅色屏幕,顯示完全無用的錯誤消息Error calling AppRegistry.runApplication! :)

所以我發現亞行位於我的文件夾中:

C:\Users\Noitidart\AppData\Local\Android\sdk\platform-tools\adb.exe 

我是在Windows 10系統上。 Noitidart是我的電腦用戶名。然後點擊「編輯」,然後點擊「新建」並添加到「C:\ Users \ Mercurius \ AppData \ Local \ Android \ sdk \ platform-tools」中, 。下面是截圖:

+1

非常有幫助,謝謝。然而,我的路徑設置正確,否則我不能從一開始就部署到我的設備:) – DerpyNerd

+0

非常感謝@DerpyNerd您的評論和種類+1 :) – Noitidart

1

運行在Genymotion模擬器第二陣營本地項目時,我最近遇到了同樣的問題,我得到了紅色的屏幕,一個錯誤說:

錯誤調用AppRegistry。 runApplication

然而,在我的情況下,不被那些缺乏環境變量引起的,正如我在一開始就加入他們。而且adb reverse tcp:8081 tcp:8081命令也不適用於我。我嘗試了幾乎所有可以在互聯網上找到的解決方案,但都沒有成功。

在我的情況下,解決方案是設置調試服務器主機&端口,如下圖所示:

CTRL + M,開闢覆蓋設置

enter image description here

點擊「開發設置的',進入設置菜單

enter image description here

單擊「調試服務器主機&端口設備」,然後鍵入localhost:8081,在彈出的

enter image description here

而現在你可以重新加載它,應該開始工作。

希望這個解決方案可以幫助一些人。

背景:

其實,在Windows 7 Pro的設置我的開發環境,當我跑我的第一陣營原生應用程式後,我得到了一個錯誤,指出:

無法加載來自資產'index.android.bundle'的腳本。確保 您的軟件包已正確打包,或者您正在運行一個包 服務器。

爲了解決這個問題,我設置調試服務器選項爲localhost:8081,和我預期的設置將採取全球效應的虛擬設備上。但它似乎正在爲每個應用程序工作,這意味着我必須一遍又一遍地設置新的React Native項目。

我還在Windows 10 Home上設置了環境(遵循與我在Windows 7 Pro上完全相同的過程),不需要設置調試服務器選項,它不會給我這樣的錯誤,而且我可以運行任何React Native項目都不需要設置任何東西。

+0

應該注意的是,設置'localhost:8081 '用於模擬器,':8081'用於通過Wi-Fi設備;) – DerpyNerd

+0

這可能是爲什麼'adb reverse tcp:8081 tcp:8081'沒有改變任何東西,因爲如果你在模擬器上運行是沒有什麼可以反向的,因爲模擬器已經指向本地主機 – DerpyNerd

+0

是的,我正在使用Genymotion而不是真正的Android設備。謝謝你指出。 – VincentZHANG