【问题标题】:How to view debug messages on Android?如何在 Android 上查看调试消息?
【发布时间】:2019-01-23 19:00:48
【问题描述】:

我有一个运行非常不稳定的 Android 应用,我想修复它。所以我用 apktool 反编译了 apk,发现应用程序调用了一堆 Log.d,它在其中写入了有用的信息。然后我为 Android 安装了一个日志查看器,并认为它没有显示任何内容。我阅读了 CatLog 的评论(例如),用户告诉它在最新的 Android 版本上不起作用。好吧,现在我想知道该怎么做 - 如果我的手机没有 root,我现在可以在 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不允许我查看其他应用程序的日志。对吧?

【问题讨论】:

    标签: android logcat apktool


    【解决方案1】:

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

    看到这个documentation

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

    【讨论】:

    • 不错。你能指出我应该把可调试标志放在哪里吗?在通过apktool编译之前的AndroidManifest.xml?
    • 不,它会进入模块级别 build.gradle 文件。检查我链接的第一个文档。
    • 是的,我检查过了。我阅读了有关 gradle 的信息。问题是我用apktool反编译的项目中没有gradle文件。只有 AndroidManifest.xml,一些资源和一堆 smali 文件。
    • 我很犹豫,假设您使用的是 Gradle(还有其他构建工具)。在您的场景中,您需要制作自己的 build.gradle 文件。听起来您无法访问源代码,因为您必须反编译 apk。这很难做到,因为您需要知道应用程序使用了哪些依赖项和配置。
    • 我不确定 apktool 究竟是用什么来编译的,但我不认为它是 gradle。它只需要将 *.smali 文件转换回字节码。但关键是 debuggable 标志似乎对我没有帮助(参见编辑 3)。
    【解决方案2】:

    尝试添加:

    {
        debuggable true
    } 
    

    在您的 build.gradle 文件中。

    【讨论】:

    • 问题是没有任何 gradle 文件。我用 apktool 反编译得到了这个东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多