如何在Android上查看调试消息?

时间:2019-01-23 19:00:48

标签: android logcat apktool

我有一个运行非常不稳定的Android应用程序,我想修复它。因此,我使用apktool反编译了apk,并发现该应用程序调用了一堆Log.d,在其中写入了有用的信息。然后,我为Android安装了一个日志查看器,发现它没有显示任何内容。我读了CatLog的评论(例如),用户告诉它在最新的Android版本上不起作用。好吧,现在我想知道该怎么办-如果我的手机没有扎根,现在可以在Android上查看日志跟踪了吗?

编辑:我想知道是否有某种方法可以修改apktool反编译的* .smali文件中的Log.d或Log.e的每次调用,这样我就可以对文本进行写文件直接与操作系统的日志机制不交互。有人做过类似的事情吗? 我也知道使用远程调试会好得多,但是我现在根本无法访问计算机-只能通过SSH访问智能手机和Linux服务器。

编辑2 :这是应用程序的清单。我试图弄清楚是否可以在其中添加可调试标记。

<?xml version="1.0" encoding="utf-8" standalone="no"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" android:targetSdkVersion="16" package="com.anda.otgdiskpro" platformBuildVersionCode="23" platformBuildVersionName="6.0-2704002">
    <uses-feature android:name="android.hardware.usb.accessory"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <application android:icon="@drawable/icon" android:label="@string/app_name" android:largeHeap="true">
        <activity android:configChanges="orientation" android:label="@string/app_name" android:launchMode="singleInstance" android:name="com.anda.otgdiskpro.USBActivityPro">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:label="Settings" android:name="com.anda.otgdisk.PrefPage"/>
        <activity android:configChanges="orientation" android:label="@string/title_activity_music" android:launchMode="singleInstance" android:name="com.anda.otgdisk.MusicActivity"/>
    </application>
</manifest>

编辑3 : 啊哈!显然,我必须将“ android:debuggable =“ true”“放入AndroidManifest.xml的应用程序标签中 ... 好的。我修改了AndroidManifest.xml:

    <application android:icon="@drawable/icon" android:label="@string/app_name" android:largeHeap="true" android:debuggable="true">

将其编译为apk,对其进行签名并安装在智能手机上。我也安装了LogCat Extreme。在LogCat Extreme中运行两个应用程序,并且没有日志。似乎Android不允许我查看其他应用程序的日志。对吧?

2 个答案:

答案 0 :(得分:0)

您的应用需要在构建变体中定义debuggable true才能查看Log消息。

请参阅此documentation

在应用程序中启用调试后,可以使用Logcat通过其程序包名称查看应用程序的日志。我从未使用过CatLog,但我假设它只是解析Logcat来显示日志。

答案 1 :(得分:0)

尝试添加:

{
    debuggable true
} 

在build.gradle文件中。