问题
I've got an Android app that works highly unstable and I want to fix it. So I decompiled the apk with apktool and figured that the app call a bunch of Log.d where it writes the useful information. Then I installed a log viewer for Android and figured that it doesn't show anything. I read into the reviews of CatLog (for example) and the user told that it doesn't work on the newest Android version. Well, now I wonder what to do - now can I view the log trace on Android provided my phone isn't rooted?
Edit: I wonder if there is some way to modify each call of Log.d or Log.e inside *.smali files decompiled by apktool so I will be able to write say to the text file directly w/o interacting with log mechanisms of OS. Have anyone done similar thing? I also understand that it would be much-much better to use remote debugging, but I simply don't have an access to computer right now - only to smartphone and the Linux server by SSH.
Edit 2: Here is a manifest of an app. I am trying to figure out if it is possible to ad debuggable flag in it.
<?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>
Edit 3: Aha! Apparently I have to put "android:debuggable="true"" I to the application tag of AndroidManifest.xml ... Okay. I modified the AndroidManifest.xml:
<application android:icon="@drawable/icon" android:label="@string/app_name" android:largeHeap="true" android:debuggable="true">
Compiled it to apk, signed it and installed on the smartphone. Also I installed LogCat Extreme. Run both apps and ... no logs in the LogCat Extreme. It seems that Android is not allowing me to view the logs of other apps. Right?
回答1:
Your app needs to have debuggable true
defined in the build variant for you to see Log
messages.
See this documentation.
Once you have debugging enabled in your application, you can use Logcat to view your app's logs via its package name. I've never used CatLog but I'd assume it's just parsing Logcat to display the logs.
回答2:
Try adding:
{
debuggable true
}
in your build.gradle file.
来源:https://stackoverflow.com/questions/54334001/how-to-view-debug-messages-on-android