2016-11-07 111 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(); 
    } 

日志为每次运行追加,直到您卸载(这会删除日志文件)。 我发现它特别有用,当我打破东西,我的应用程序刚刚在启动时死掉,因为我可以恢复到之前的提交并在日志中查看看看发生了什么

相关问题