[Android Software/Hacking General [Developers Only]] Jarmezrocks:
THE FOLLOWING POST CONTAINS TIPS AND HELP NOT REQUEST FOR ASSISTANCE

Hi,

I noticed that APKtool gives some very hard to debug errors, almost meaningless most of the time. I have a possibly solution for people who maybe experiencing the same things I have been experiencing?

Basically I run smali in the same location as my wrapper scripts for apktool. I run smali on the decompiled APK/directory and get the errors being returned from it. I keep correcting those until the classes.dex builds then I know that the remaining errors are likely to be related to XML or bad PNGs ....but the latter never happens for me and I don't use others themes/images ever so basically narrows it down to fixing the XML files. Most of the time it is making sure the Hex values match those that are made in the smali.

For convenience sake and for those of you who are new also you may like to use the wrapper scripts that I have for smali to make like a bit more easier for you.

I will provide an example of the errors I was getting apktool, then the corresponding errors from smali and you can see how it works.

APKTool Errors

I: Checking whether sources has changed...
I: Smaling...
Exception in thread "main" brut.androlib.AndrolibException: Could not smali file: java.io.FileInputStream@53c8b26e
at brut.androlib.src.DexFileBuilder.addSmaliFile(DexFileBuilder.java:45)
at brut.androlib.src.DexFileBuilder.addSmaliFile(DexFileBuilder.java:33)
at brut.androlib.src.SmaliBuilder.buildFile(SmaliBuilder.java:64)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:48)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:35)
at brut.androlib.Androlib.buildSourcesSmali(Androlib.java:222)
at brut.androlib.Androlib.buildSources(Androlib.java:179)
at brut.androlib.Androlib.build(Androlib.java:170)
at brut.androlib.Androlib.build(Androlib.java:154)
at brut.apktool.Main.cmdBuild(Main.java:182)
at brut.apktool.Main.main(Main.java:67)

Same APK but Smali delivered errors

MyApp.apk\smali\com\myapp\name\goes\here\R$string.smali[0,0] 0x7f040002a cannot fit into an int
MyApp.apk\smali\com\myapp\name\goes\here\HowToActivity.smali[93,19] Label "cond_1" is not defined.

I eventually fixed both of these and then the classes.dex compiled fine. A small amount of work and the XML fixed and the app compiles.

My smali wrapper scripts are as follows:

I have one bat file called Decompile.bat

Usage:

Decompile <name of jarfile here>

@echo off
java -Xms512m -Xmx1024m -jar "%~dp0baksmali-1.3.4.jar" -a [B]15[/B] %1 %2 %3 %4 %5 %6 %7 %8 %9 --output %~n1

Say you are using Services.jar this will make a directory called Services (no extension) instead of the regular "out" folder that all of us have probably accidently over written every once in a while :) hahah

I alternatively have another batch script similarly named Recompile.bat

Usage:

Recompile <name of folder of the decompiled JAR or whole APK as a folder> i.e. MyApp.apk

@echo off
java -Xmx512m Xmx1024m -jar "%~dp0smali-1.3.4.jar" -a [B]15[/B] %1 %2 %3 %4 %5 %6 %7 %8 %9 --output classes.dex

This will smali all the smali folders in the decompiled directory that you specify and will compile to a classes.dex file ready for dropping into an APK and distribute. Note the APK level of 15. Change according to what is specific to you.

Make adjustments accoding to the smali/baksmali errors i.e. in this case line 93 is fairly obvious! When I fixed that the next error appeared for another line. I slowly error by error managed to compile. If you were trying to figure out what the hell Could not smali file: java.io.FileInputStream@53c8b26e means then good luck!:laugh: