2016-11-07 113 views
0

我正在使用crouton在我的chromebook上創建一個Linux桌面。在這裏,我安裝了Android Studio並開始製作一個簡單的Android應用程序。我可以構建一個apk,將其移至Downloads文件夾,然後從Linux翻轉到ChromeOS並運行該應用程序。 (我使用APK安裝程序 - 工作正常)。是否可以在chromebook上開發和調試android應用程序?

我希望能夠從我的應用程序中看到logcat(實際上,我希望看到在Android Studio中的模擬器中運行時獲得的所有診斷信息 - 但我已經爲logcat解決了問題)。

我讀過的關於使用adb的任何東西都希望您擁有Android Studio的開發機器和運行應用程序的目標機器。使用crouton linux桌面和ChromeOS在同一臺機器上,只有一個可以同時運行,因爲它們共享相同的資源等。 我嘗試了幾個應用程序,但沒有一個能夠顯示我的應用程序運行在chromebook上的logcat - 他們甚至不知道它正在運行。任何人有關於如何查看此特定設置的logcat的任何想法?

回答

0

到目前爲止,我已經找到一個辦法讓logcat的和正在解決該...現在

在主要活動的onCreate調用此方法;

public static void saveLogcatToFile(Context context) { 
      File outputFile = new File(context.getFilesDir(), "logcat.txt"); 

      try { 
       @SuppressWarnings("unused") 
       Process process = Runtime.getRuntime().exec("logcat -df " + outputFile.getAbsolutePath()); 
      } catch (IOException e) {... 

在另一個Activity的onCreate中使用logcat填充TextView;

public static String readLogcatFromFile(Context context) { 
      File logFile = new File(context.getFilesDir(), "logcat.txt"); 
      if (logFile.exists() == false) { ... 

      String logContents = context.getString(R.string.EMPTY_STRING); 
      FileInputStream fileInStream = null; 
      try { 
       fileInStream = new FileInputStream(logFile); 
       logContents = convertStreamToString(fileInStream); 
      } catch (Exception e) { ... 
      } finally { ... 
       fileInStream.close(); 
      } 
      return logContents; 
    } 

    private static String convertStreamToString(InputStream is) throws IOException { 
      BufferedReader reader = new BufferedReader(new InputStreamReader(is)); 
      StringBuilder sb = new StringBuilder(); 
      String line = null; 
      while ((line = reader.readLine()) != null) { 
       sb.append(line).append("\n"); 
      } 
      reader.close(); 
      return sb.toString(); 
    } 

日誌爲每次運行追加,直到您卸載(這會刪除日誌文件)。 我發現它特別有用,當我打破東西,我的應用程序剛剛在啓動時死掉,因爲我可以恢復到之前的提交併在日誌中查看看看發生了什麼

相關問題