howto in eclipse debug the Proguard obfuscated apk file - android

I got a crash in my app after using Proguard and signing and exporting with a new key.
The same code works in normal eclipse debug mode.
I read everywhere i should use the mapping.txt to find the code that failed.
But how to do that, I have google this for 2 hour now and no answer is working.
Im now signing the apk file with the debug.keystore and using the default password "android".
Someone say i should android:debuggable="false" in my application tag to make
Proguard obfuscate my debug session in eclipse.
Is this right?
Any help would be grate
on the Proguard Android Developer page I cannot find a way to do this
"When your obfuscated code outputs a stack trace, the method names are obfuscated, which makes debugging ha"
What "stack trace" and from where?
On the page Proguard Manual I cannot find an explanation

You can de-obfuscate the stack trace most easily using the Proguard GUI. You'll find this with your Android SDK.
sdk\tools\proguard\bin\proguardgui.bat
Run the GUI above from the path above.
Click the 'ReTrace' button at the bottom of the panel on the left.
Add the path to your Mapping File (mapping.txt) in the 'Mapping file' text box.
Paste a copy of your stack trace in the 'Obfuscated stack trace' text box.
Click 'ReTrace' in the bottom right.
Happy Debugging!

Not within Eclipse.
Outside of Eclipse, use Retrace function within ProGuard. You'll also need the dumped stacktrace and mapping.txt found under your project's proguard directory to reverse the obfuscated stacktrace. Remember to save a copy of mapping.txt (preferably outside of your project's workspace) each time you deploy a new version of your Android app.

Been looking into this, the documentation for proguard on the android developer site demonstrates how to decode a stack trace, but it does not specify how to get the stack trace.
http://developer.android.com/guide/developing/tools/proguard.html (see section Decoding Obfuscated Stack Traces)
I tried to use a logcat dump as follows:-
E/AndroidRuntime(14584): FATAL EXCEPTION: main
E/AndroidRuntime(14584): java.lang.ExceptionInInitializerError
E/AndroidRuntime(14584): at com.a.a.b.a.dg.<init>(Unknown Source)
E/AndroidRuntime(14584): at com.a.a.b.a.q.a(Unknown Source)
E/AndroidRuntime(14584): at com.a.a.b.a.y.a(Unknown Source)
E/AndroidRuntime(14584): at com.a.a.b.a.y.a(Unknown Source)
E/AndroidRuntime(14584): at com.a.a.b.a.aq.get(Unknown Source)
E/AndroidRuntime(14584): at com.a.a.b.cp.a(Unknown Source)
E/AndroidRuntime(14584): at com.a.a.b.ai.c(Unknown Source)
E/AndroidRuntime(14584): at com.a.a.b.bg.a(Unknown Source)
E/AndroidRuntime(14584): at com.a.a.a.o.a(Unknown Source)
E/AndroidRuntime(14584): at com.a.a.b.ee.a(Unknown Source)
E/AndroidRuntime(14584): at com.a.a.b.ag.a(Unknown Source)
E/AndroidRuntime(14584): at com.a.a.b.cb.a(Unknown Source)
Unfortunately this does not work, but it does work if I remove the E/AndroidRuntime(14584) from the beginning of each line it does work:
FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at com.a.a.b.a.dg.<init>(Unknown Source)
at com.a.a.b.a.q.a(Unknown Source)
at com.a.a.b.a.y.a(Unknown Source)
at com.a.a.b.a.y.a(Unknown Source)
at com.a.a.b.a.aq.get(Unknown Source)
at com.a.a.b.cp.a(Unknown Source)
at com.a.a.b.ai.c(Unknown Source)
at com.a.a.b.bg.a(Unknown Source)
at com.a.a.a.o.a(Unknown Source)
at com.a.a.b.ee.a(Unknown Source)
at com.a.a.b.ag.a(Unknown Source)
at com.a.a.b.cb.a(Unknown Source)
So as the documentation states you need a stack trace file, and there appears to be no indication of getting a valid stack trace file from the device.
The only way I have seen this done is by providing a custom exception handler and writing the stack trace to the sdcard.

For mac user use bellow code to run the
/Users/XYZ/Library/Android/sdk/tools/proguard/bin/proguardgui.sh
Run the GUI above from the path above.
Click the 'ReTrace' button at the bottom of the panel on the left.
Add the path to your Mapping File (mapping.txt) in the 'Mapping
file' text box.
Paste a copy of your stack trace in the 'Obfuscated stack trace'
text box. Click
'ReTrace' in the bottom right.
Happy Debugging!

Steps to get obfuscated apk:
Download latest proguard from proguard site. Current latest version is proguard4.7
Replace "bin" and "lib" folder of C:\Program Files (x86)\Android\android-sdk\tools\proguard with latest downloaded proguard folders.
Check SDK location in eclipse for blank spaces in it and for that go to Window > Preferences > Android. If there is blank space then replace it with:
c:\Progra~2\android\android-sdk (for windows 64-bit)
c:\Progra~1\android\android-sdk (for windows 32-bit)
Check that proguard.cfg file is in your project's root folder and add proguard.config=proguard.cfg in project.properties file of android project.
Now export your project to get obfuscated apk.

Related

Expo - APK bundle must contain the expected embedded asset

I'm new on react, and i tried to run my app but i got this following error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.bits.bee.bwc, PID: 12601
java.lang.AssertionError: APK bundle must contain the expected embedded asset asset_c2f3d742a18a28238b7cd34a5d4b7316.png
at expo.modules.updates.loader.EmbeddedLoader.copyAllAssets(EmbeddedLoader.java:174)
at expo.modules.updates.loader.EmbeddedLoader.processManifest(EmbeddedLoader.java:137)
at expo.modules.updates.loader.EmbeddedLoader.loadEmbeddedUpdate(EmbeddedLoader.java:57)
at expo.modules.updates.UpdatesController.start(UpdatesController.java:286)
at expo.modules.updates.UpdatesController.initialize(UpdatesController.java:96)
at com.bits.bee.bwc.MainApplication.onCreate(MainApplication.java:98)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4552)
at android.app.ActivityThread.access$1500(ActivityThread.java:147)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5255)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
Can someone explain to me how it's work because i looked it up in my asset folder there's nothing named like that. And how do i fix this? Thanks
Info
This exception only happened to me when running a debug build with react-native run-android and the exception did not appear when running a release build with react-native run-android --variant=release.
Solution
Check whether you have the following line in MainApplication.java and if it's there then remove that line:
import com.facebook.react.BuildConfig;
Explanation
The line import com.facebook.react.BuildConfig; causes UpdatesController.initialize(this); to be called in Debug mode which shouldn't happen.
More detail:
When you look at your Stacktrace you posted the line
at com.bits.bee.bwc.MainApplication.onCreate(MainApplication.java:98)
points to UpdatesController.initialize(this);. Including the line above and below that's how it looks like:
if (!BuildConfig.DEBUG) {
UpdatesController.initialize(this);
}
This BuildConfig here points to the BuildConfig class of your package (com.bits.bee.bwc in your case) which is created during the build. If you import com.facebook.react.BuildConfig it will point to another BuildConfig class which does not contain the correct DEBUG value you want.
Since BuildConfig.DEBUG will then be undefined or false, UpdatesController.initialize(this); is called although it shouldn't during a debug build. Hence, because assets will be not embedded for debug builds, the copyAllAssets function which is eventually called will not find any assets and we get the above error.
Some Context of why I ended up importing com.facebook.react.BuildConfig;
I was facing the issue of java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so in my release build and followed the advice to add that line as stated here https://stackoverflow.com/questions/57036317/react-native-java-lang-unsatisfiedlinkerror-couldnt-find-dso-to-load-libherm/63048532#answer-62119615. It didn't make a change for the release build and I forgot about it. Only later when I attempted to make a debug build I got this error.. took me quite a while to realize that this added line is the cause of the issue!
What I learned from debugging this issue:
Don't just add things because you think it won't hurt. If it doesn't fulfill a certain purpose or has no effect, remove the change immediately. It can otherwise cause strange side effects later.
If you have build issues with Android, debug with Android Studio instead of Flipper. Flipper doesn't display you the entire Stacktrace and in Android Studio you can easily browse through all the Java files which eventually helped me to understand this Exception.

AndroidApp crashes when installed from the play store

I have an app that I have recently submitted to the play store. I had tested the .apk file and everything was working fine. On the first install (from the store) - you can login but then it crashes. Here is the stack trace I am getting from the report:
java.lang.NullPointerException
at com.latlon.InitialSearchActivity.e(Unknown Source)
at com.latlon.InitialSearchActivity.a(Unknown Source)
at com.latlon.InitialSearchActivity.g(Unknown Source)
at com.latlon.InitialSearchActivity.a(Unknown Source)
at com.latlon.MyResultReceiver.onReceiveResult(Unknown Source)
at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:43)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4385)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)
I am just not real sure where to start looking. Any ideas?
Well, this part of the stack trace is your code:
java.lang.NullPointerException
at com.latlon.InitialSearchActivity.e(Unknown Source)
at com.latlon.InitialSearchActivity.a(Unknown Source)
at com.latlon.InitialSearchActivity.g(Unknown Source)
at com.latlon.InitialSearchActivity.a(Unknown Source)
at com.latlon.MyResultReceiver.onReceiveResult(Unknown Source)
Your onReceiveResult() method in class MyResultReceiver was called. That method called a method a in the InitialSearchActivity class, which called a method g in that class which called a method a in that class which called a method e in that class. In method e there was a NullPointerException (ie: in that method you tried to use a variable that you thought contained an object reference, but instead that variable contained null.
It looks like the method names have been obfuscated, so you may have to look at the code to figure out what the real method names are.
Looks like you used some toole (like Proguard) to obfuscate your code.
Did you test your APK after obfuscation?
From the logs above a NullPointerException has occured in your code, you'd need to de-obfuscate your code using the key files generated by the obfuscating tool in order to find out the real place (line of code) where null pointer has been accessed.
Please Note,
In the process of obfuscation, sometimes (human error) can cause some of the required methods to be obfuscated. Which in turn causes those methods not to be found, hence an exception (NoSuchMethod) might be raised.
Check the documentation on Proguard (which is the tool that does the code obfusciation).
It is very likely that you "over-obfusciated", which can cause issues with the deployed code. Just like you are seeing.
You can turn off Proguard functionality by editing the "proguard-project.txt" file. To ensure no obfusciation occurs, make sure every line in this file is commented out (by placing a hash - or # mark at the start of each line).
There is a command called retrace that allows you to provide unmap your obfusciation. You will need to provide some files created by proguard to get this working.
Check the docs for full explanation: http://developer.android.com/tools/help/proguard.html
Quick fix (to eliminate Proguard) is to comment the file, so it doesn't run in the first place.

"Failed to read SDK values" error

When Eclipse opens, the Error Log pops up and gives me this error.
java.io.FileNotFoundException: C:\Users\Jess D630\Desktop\School\DCMST\Directed Study\eclipse\platforms\android-7\data\service_actions.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at com.android.ide.eclipse.adt.internal.sdk.AndroidTargetParser.collectValues(AndroidTargetParser.java:403)
at com.android.ide.eclipse.adt.internal.sdk.AndroidTargetParser.collectIntentFilterActionsAndCategories(AndroidTargetParser.java:388)
at com.android.ide.eclipse.adt.internal.sdk.AndroidTargetParser.run(AndroidTargetParser.java:120)
at com.android.ide.eclipse.adt.internal.sdk.Sdk$5.run(Sdk.java:559)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
I know that I need the service_actions.txt file but I cannot find it online anywhere.
I solved a similar problem by finding the source code online for a different file.
Does anyone have the code for it?
That file is referred by the Android SDK. Your SDK and Eclipse configuration is incorrect, that's why you are getting this error. Please refer this guide for setup instructions:
https://developer.android.com/sdk/installing/index.html

Proguard retrace output confusion

I have here a stack trace from one of my games from android market. I have de-proguarded it but I can't really understand it!
I'm not asking for help in the error itself, but just how to interpret this.
I started with this from Market:
java.lang.IllegalArgumentException
at java.nio.Buffer.position(Buffer.java:299)
at com.a.a.k.o.a(Unknown Source)
at com.a.a.k.w.a(Unknown Source)
at com.a.a.k.w.onDrawFrame(Unknown Source)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1363)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
But retrace.bat has output this, which is longer, so I can't tell what com.a.a.k.o.a is (for exmaple).
java.lang.IllegalArgumentException
at java.nio.Buffer.position(Buffer.java:299)
at com.eaw.graphics.WorldViewShader.void glSetMVPMatrix(float[])(Unknown Source)
void glSetNormalMatrix(com.eaw.graphics.AMatrix)
void SetVertices(java.nio.FloatBuffer)
void ApplyArgs(com.eaw.graphics.WorldViewShaderArgs)
at com.eaw.graphics.TriangleRenderer.void onDrawFrame(com.eaw.airrace.ILayer,com.eaw.airrace.StepOutput,boolean)(Unknown Source)
void loadTexture$332cd44f(int[],int,int)
void delayedLoadTexture(int[],int[],int,int)
at com.eaw.graphics.TriangleRenderer.void onDrawFrame(javax.microedition.khronos.opengles.GL10)(Unknown Source)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1363)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
Has it rolled 4 functions into 1 during obscuration? or what?
You should add -keepattributes SourceFile,LineNumberTable to your proguard configuration file!
Your processed code and stack trace doesn't contain line numbers, so ProGuard can't tell to which original method name the obfuscated method name 'a' corresponds. It then prints out all possible alternatives. Cfr. ProGuard's Retrace manual.
The manual also documents how you can preserve line numbers in the obfuscation step.

Eclipse crash after opening .xml file

i am starting with android development
i have created some sample application but
when i am opening .xml file resides in res/layout/main.xml
after that my eclipse crash and close.
i even try "open with android layout editor" which also crashes eclipse.
i am not getting why this problem occur.
my os is ubantu 9.04
and using eclipse Galileo
EDIT:
i am getting following error in my eclipse log file. what dose this means???
!ENTRY com.android.ide.eclipse.adt 4 0 2011-04-29 16:56:16.476
!MESSAGE loadAndParseRClass failed to find class com.saltriver.gui.R
!STACK 0
java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
at com.android.ide.eclipse.adt.internal.resources.manager.ProjectClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at com.android.ide.eclipse.adt.internal.resources.manager.CompiledResourcesMonitor.loadAndParseRClass(Unknown Source)
at com.android.ide.eclipse.adt.internal.resources.manager.CompiledResourcesMonitor.fileChanged(Unknown Source)
at com.android.ide.eclipse.adt.internal.resources.manager.GlobalProjectMonitor$DeltaVisitor.visit(Unknown Source)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:68)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:79)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:79)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:79)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:79)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:79)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:79)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:48)
at com.android.ide.eclipse.adt.internal.resources.manager.GlobalProjectMonitor$1.resourceChanged(Unknown Source)
at org.eclipse.core.internal.events.NotificationManager$2.run(NotificationManager.java:291)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.NotificationManager.notify(NotificationManager.java:285)
at org.eclipse.core.internal.events.NotificationManager.broadcastChanges(NotificationManager.java:149)
at org.eclipse.core.internal.resources.Workspace.broadcastPostChange(Workspace.java:313)
at org.eclipse.core.internal.resources.Workspace.endOperation(Workspace.java:1022)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1809)
at org.eclipse.core.internal.events.NotificationManager$NotifyJob.run(NotificationManager.java:40)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
"crash" is not very specific. Look into the file .metadata/.log in your workspace to see if Eclipse wrote an error message before it died.
If that doesn't help, start Eclipse from a console with -debug -console -consoleLog.
[EDIT] The error means that you're using Java X to run Eclipse but a plugin needs Java Y (where Y > X).
the usual case is that you run Eclipse with Java 5 and you have a plugin which needs Java 6. Unfortunately, the error message is useless: It doesn't tell you which class is the problem, from which JAR it came, which version it has and which versions are supported - The code has all the information but some smart guy decided that you don't need that. Pity.
So try to get the latest version of Java to run the IDE.
This is independent of the Java version which you use to build and run your projects!! It's just the VM which Eclipse uses to load its plugins. For VMs used in projects, see the Eclipse preferences.
Close 'Eclipse'
Go to your Eclipse folder open eclipse.ini file in any text editor.
after the line which says openFile add following two lines.
-vm
C:\Program Files\Java\jdk1.6.0_24\bin\javaw.exe
(This folder path may vary according to your java installation directory).
save and close.
Open eclipse and tadaaaa!!! you can open xml files again. :)

Categories

Resources