yashsingh1/xdaforums huggingface dataset:
[G1 Android Development] Daneshm90:
So Brut.all how far in the future could i expect apktool to sign the apk's it repackages as well :D
[G1 Android Development] stari4ek:
what's the problem with own script which call signing after apktool build?

2Brut.all

Is it possible to have proper return code, if apktool fails to exception during its work.

It's difficult to use it in batch scripts, cause you can't catch it's fail.

Any suggestions? (I don't have any experience with java)
[G1 Android Development] Brut.all:
Basic signing should be easy to add and I would love this feature too ;-) I'm tired of apktool b -> sign -> adb install combo each time I modify one letter in a smali code :-)

Problem is: signing is quite tricky. Some files must be installed through update.zip file, some must be signed with testsign, some have shared UID with other apps, etc. And when you give some easy-to-use-tool to people, they usually become lazy and think, that this tool will do everything for them, they don't even have to know what signing is. Then I will get plenty of complaints that apktool doesn't sign files correctly, etc., etc. :-)

But as I said above - it would be really nice to have this feature. Not for "now I don't have to know, how to do that", but for "now I don't have to do that every time" :-)
[G1 Android Development] Daneshm90:
Agreed. Hate when people ask things to be done without learning how to do it. For now i will just write a small script which has the following options :

1. Decompile using apktool (searches n hopes for only 1 apk in root directory)

2. Recompile using apktool (compiles out directory)

3. Sign (will sign using test.jar)

4. adb install -r out.apk in dist directory.

By script i mean batch.

That should keep me quiet till u implement it :)
[G1 Android Development] Brut.all:
Java automatically returns 1 on uncaught exceptions, so apktool already have this feature. There are cases, when it returns 0 instead of 1, because I catch some exceptions, show helpful error message, but have forgotten to set return code to 1 - I'll fix this. Also there are some errors, that don't stop decoding/building process, but result with broken files ("Could not decode attr value...") - I will return 2 on such cases.
[G1 Android Development] Daneshm90:
Hey here i made a batch for signing/installing/easing the whole process. Let me know wht u think :)

Link
[G1 Android Development] udK:
@Brut.all; I made some test today, everythings is fine just some trouble with some apk, like CheckinProvider.apk, DCSImpl.apk, DCSUtility.apk and some others.

C:\Users\udK\Desktop\test>java -jar apktool.jar d DCSImpl.apk
I: Loading resource table...
I: Decoding resources...
I: Loading resource table from file: C:\Users\udK\apktool\framework\1.apk
Exception in thread "main" brut.androlib.AndrolibException: brut.directory.PathN
otExist: res
at brut.androlib.res.AndrolibResources.decode(Unknown Source)
at brut.androlib.Androlib.decodeResourcesFull(Unknown Source)
at brut.androlib.ApkDecoder.decode(Unknown Source)
at brut.apktool.Main.cmdDecode(Unknown Source)
at brut.apktool.Main.main(Unknown Source)
Caused by: brut.directory.PathNotExist: res
at brut.directory.AbstractDirectory.getDir(Unknown Source)
... 5 more

edit: The new smaller aapt.exe seems to works fine on windows (I'm on W7 64bit)
[G1 Android Development] Brut.all:
Could you upload one of these files? Seems they have resources.arsc file, but not res dir For now you could add empty res directory in apk files and apktool should decode them.
[G1 Android Development] stari4ek:
yes. They don't have res dir, but have resources.arsc (same on sprint htc hero rom)
[G1 Android Development] udK:
Yes you're right, there is not the res dir inside the apk, adding it to the apk apktool dump it fine.

Thank you for the help.
[G1 Android Development] stari4ek:
If I add res to it apktool decode it fine. I think, it doens't have res dir in apk, if res dir has only values (and values-%) in it.

I failed to build it back

$ apktool d CheckinProvider.apk 1
I: Loading resource table...
I: Decoding resources...
I: Loading resource table from file: /home/astar/apktool/framework/1.apk
I: Copying assets and libs...
astar@astar-desktop:~/android/kitchen/build$ apktool b 1
W: Could not find sources
I: Checking whether resources has changed...
I: Building resources...
Exception in thread "main" brut.androlib.AndrolibException: brut.directory.DirectoryException: Error copying file: res
at brut.androlib.Androlib.buildResourcesFull(Unknown Source)
at brut.androlib.Androlib.buildResources(Unknown Source)
at brut.androlib.Androlib.build(Unknown Source)
at brut.androlib.Androlib.build(Unknown Source)
at brut.apktool.Main.cmdBuild(Unknown Source)
at brut.apktool.Main.main(Unknown Source)
Caused by: brut.directory.DirectoryException: Error copying file: res
at brut.directory.DirUtil.copyToDir(Unknown Source)
at brut.directory.DirUtil.copyToDir(Unknown Source)
at brut.directory.AbstractDirectory.copyToDir(Unknown Source)
... 6 more
Caused by: brut.directory.PathNotExist: res
at brut.directory.AbstractDirectory.getFileInput(Unknown Source)
... 9 more
[G1 Android Development] udK:
Same error here.
[G1 Android Development] Brut.all:
Ok, thanks for info.

As you probably guessed, you could create some dummy resource, for example empty res/raw/a file and then apktool will succeed in building apk. This will be easy to fix, I will release 1.2.1 soon.
[G1 Android Development] stari4ek:
Such a great day. New official ROM for HTC Hero, new apktool. Let's continue =)

I have a question.

Sometimes HTC leave old resources in localized values-##/strings.xml. I think that they are old, cause there is no such resources in default values/strings.xml, which is used (sprint rom, english locale)

It makes some inconvenience, if you remove all localized resources (for some kind of optimizations) and try to build application back.

Example:

1. decode

astar@astar-desktop:~/android/kitchen/build$ apktool d rom-base/system/app/Stock.apk 1
I: Loading resource table...
I: Decoding resources...
I: Loading resource table from file: /home/astar/apktool/framework/1.apk
I: Loading resource table from file: /home/astar/apktool/framework/2.apk
I: Copying assets and libs...

2. Build back without any changes

astar@astar-desktop:~/android/kitchen/build$ apktool b 1
W: Could not find sources
I: Checking whether resources has changed...
I: Building resources...
aapt: warning: string 'btn_close' has no default translation in /home/astar/android/kitchen/build/1/res; found: no sk
I: Building apk file...

3. remove unused localization resources and try to build:

astar@astar-desktop:~/android/kitchen/build$ apktool b 1
W: Could not find sources
I: Checking whether resources has changed...
I: Building resources...
Exception in thread "main" brut.androlib.AndrolibException: brut.common.BrutException: could not exec command: [aapt, p, -F, /tmp/APKTOOL3556033874339850092.tmp, -I, /home/astar/apktool/framework/1.apk, -I, /home/astar/apktool/framework/2.apk, -S, /home/astar/android/kitchen/build/1/res, -M, /home/astar/android/kitchen/build/1/AndroidManifest.xml, /home/astar/android/kitchen/build/1/9patch]
at brut.androlib.res.AndrolibResources.aaptPackage(Unknown Source)
at brut.androlib.Androlib.buildResourcesFull(Unknown Source)
at brut.androlib.Androlib.buildResources(Unknown Source)
at brut.androlib.Androlib.build(Unknown Source)
at brut.androlib.Androlib.build(Unknown Source)
at brut.apktool.Main.cmdBuild(Unknown Source)
at brut.apktool.Main.main(Unknown Source)
Caused by: brut.common.BrutException: could not exec command: [aapt, p, -F, /tmp/APKTOOL3556033874339850092.tmp, -I, /home/astar/apktool/framework/1.apk, -I, /home/astar/apktool/framework/2.apk, -S, /home/astar/android/kitchen/build/1/res, -M, /home/astar/android/kitchen/build/1/AndroidManifest.xml, /home/astar/android/kitchen/build/1/9patch]
at brut.util.OS.exec(Unknown Source)
... 7 more
/home/astar/android/kitchen/build/1/res/values/public.xml:175: error: Public symbol string/btn_close declared here is not defined.

Do you have any hidden "force" options to bypass it?

Cause now, I have to manually add missing resources to localization I add (values-ru, for example).

Any suggestions?
[G1 Android Development] Brut.all:
This isn't caused by oldness, but by stupidity of developers. If these resources aren't needed, then why they didn't remove them completely, but default values only? There is no good reason for adding resources without default values - this is just bad thing and this is why aapt warns about that.

Speaking about your problem, I don't understand, why you don't want to just add these resources? There are usually <=20 such resources - 5 minutes of clicking. I could add new switch to decode command, something like: "if there is no default value, then copy it from <lang>", but would it be really that useful?

Ahh and even if you would be sure, that these resources aren't used at all, it wouldn't be easy to remove them. When you do so, then there will be a "hole" in resources numeration, for example there will be: 0x7f020005, 0x7f020006, 0x7f020008, 0x7f020009 and Android forbids such situations.
[G1 Android Development] stari4ek:
Oh yeah! I face this kind of problem at my work everyday, but we have what we have. I'm just looking for good and convenient workaround.

5 minutes of clicking? holy crap. I have fully rebuild/patched/localized build in ~10 minutes, just in one click =)

But proposed switch sounds really weird.

Concerning holes in numeration. I don't get it.

As I can see this strings has names as ids. Does it converted to digital id's somewhere?

Is it possible to skip missing string, without incrementing id? And of course it should be optional, cause I think that "those devs" can create situation, when strings from localization dir overlap default (for example in roms, targeted only to specific country/language/operator)

Anyway, thank you for taking a look into the problem. It isn't important, just "last trick"
[G1 Android Development] Brut.all:
Are you using some translator or what? :-) And if I understand you correctly, this isn't a one-time job for you? I could try to create a tool for you, but I want to know, what are you doing ;-)

Yeah, during app building.

Yeah, of course. Actually this would be a "normal" and simpler way of building an app in apktool :-)

Unfortunately there is one problem: resources ids are scattered over whole app code. If you use e.g. R.string.hello_world in your code, then after building this will be converted to: 0x7f020013. If apktool would renumerate resources, code would reference different resources, than it did in original app. I had to add "public.xml hack" to ensure that resources ids will be the same as in original. You could easily remove resources from the end of a list, you could remove resources from the middle if you add same or greater quantity or your own resources, but you can't make "holes".
[G1 Android Development] stari4ek:
Nope. I use localized stuff from other WWE roms =) And bunch of scripts, written by myself (hmm. There are 33 of them already, not counting other great tools, like smali/baksmali/apktool).

The main idea is to be able configure any step of the build process, like adding smali patches, solving CLASSPATH dependencies, resolving signing apps with same shared uid, adding localization and so on. And than I can repack/unpack/unodex whole rom in one single call.

The only stuff I do after it is copying all those apk/odex/jars to manually prepared (it changes very rarely) root folder of update. It's the second click =)

I'm trying do not do anything by hands, cause I'm sure that sometime I'll forget something (You know, it always happens with developers ;))

I hope that I understand your question about one-time job correctly. My bloody English.

You've created it already. It's apktool, and it's great. =)
[G1 Android Development] atrant:
1.2.0 release decompiled astro player thanks!
[G1 Android Development] stari4ek:
Probably I've missed something. But how does it solve problem with building apk back, if empty 'res' was added to help apktool to decode it?

Looking forward to 1.2.1
[G1 Android Development] Exculpo:
Hi there..

Pretty new to this, but I've had some success earlier with this awesome tool on Windows32.

I'm stuck right now though with the hatred DeskClock.apk.

I've seen that this app has been an issue for someone earlier in this thread as well.

Trying to change a small amount of code to make it start the musicapp of my choice.

I got lots of errors with the earlier version of apktool, so I upgraded today, and this time it decoded it as usual.

C:\WINDOWS>java -jar apktool.jar d DeskClock.apk DeskClock.apk-decoded
I: Baksmaling...
I: Loading resource table...
I: Decoding resources...
I: Loading resource table from file: C:\Documents and Settings\Owner\apktool\framework\1.apk
I: Copying assets and libs...
C:\WINDOWS>

I changed the code and the build command.

This time I got no errorcodes, but it seems like I'm getting some problems with the resources?

C:\WINDOWS>java -jar apktool.jar b DeskClock.apk-decoded
I: Checking whether sources has changed...
I: Checking whether resources has changed...
I: Building resources...
I: Building apk file...
C:\WINDOWS>

The original .apk is 395Kb, but when it's built I only get 295Kb.

The app does have a res dir containing an .ogg file in \res\raw

In the \build\apk dir I'm getting resources.arsc

I get the same result when I just try to decode it and rebuild it at once without changing anything.

What am I missing here? Please help me sort it out.
[G1 Android Development] canadiancow:
I just used apktool to decode something other than Google Maps, which was a first for me.

Wow. apktool with a unobfuscated code is absolutely amazing. I actually know what every file and method does :)
[G1 Android Development] Brut.all:
I didn't know, that there may be no "res" dir, so apktool doesn't check whether this dir exists before it will do something with it.

When decoding it tries to look for "res" contents: empty dir is enough, but lack of it results with an error.

Building process is: compile resources to apk file using aapt, unpack compiled resources, mix them with a code and other stuff, pack back using aapt second time. If there are only values/* files when compiling resources, aapt doesn't store empty "res" dir in resulting apk file - then apktool throws exception at next stage, because it tries to unpack non-existent directory.

Sorry, I don't understand you. Is something missing in resulting apk file? Could you upload original file?

Yeah, smali is quite easy to read - thanks to JesusFreke for it :-)

Writing is much worse, because you have to write several lines of code for some simple thing. This is the reason, why I mix Java and smali in GM mod :-) AFAIK jonasl do the same in his HTC_IME mod.
[G1 Android Development] HackDown:
Froyo problems? Decoding work fine, Encoding process give me exception error.

Trying to modding framework-res.apk froyo rom.

Thanks
[G1 Android Development] Brut.all:
Thanks for info :-)

http://code.google.com/p/android-apktool/issues/detail?id=48
[G1 Android Development] Exculpo:
Yes on this .apk I lost about 100Kb in the resulting apk file.

But it's not only this apk I get weird results, so I guess something's messed up on my system, or maybe I've missed something fundamental somewhere..

I used to be able to decode and rebuild most apk's before I updated from version 1.1.1 to 1.2.0 though. (FYI I updated aapt.exe, apktool.jar and apktool.bat)

For an example, decoding and building framework-res.apk almost doubles the size on the apk.

Original size: 3429Kb.

Rebuilt without changes: 5208Kb.

Attaching original DeskClock.apk
[G1 Android Development] Brut.all:
This does not necessarily mean that anything is wrong. Apktool may use different tools, newer versions of these, etc. Newer usually means: better, faster, smaller. I usually get smaller files and they are perfectly ok.

I've looked into this DeskClock.apk . Firstly, it is compressed in different way. If you use zipinfo against original and resulting file, you will see, that in original xmls are compressed using defN algorithm and in resulting defX is used. Also in original resources.arsc isn't compressed at all. If you unpack both files, you will see, that their contents are 492K vs. 526K of uncompressed size. META-INF is 20K large, so there is only 14K of real difference. Most of these 14K are gained from smaller PNGs. Maybe aapt from Froyo (which I use in apktool) uses some PNG optimizations.

This is also caused by compression, not contents itself. I had some problems with framework-res.apk files if they had resources.arsc file compressed, so I store it without compression. Rom cookers somehow compresses it without issues. I must do some research.
[G1 Android Development] Exculpo:
Ahh ok, thanks for straightening that out.

I failed in my attempt to change the player of my choice to start anyway, but now I know that it uses a different compression, and the finished apk file does in deed work very well, it's just a bonus that the size of the output apk is reduced!

I hope we can find out how the compression of the .arsc files are made then..

You are doing a great job with this tool, thanks for helping me out!
[G1 Android Development] rfgamaral:
Sorry if this has been answered but the topic is quite large with 36 pages already...

Can this tool be used to work on an app with an .apk matching .odex file? Or just on single .apk files? Can I turn an .apk/.odex pair into a single .apk and then use this tool?
[G1 Android Development] Brut.all:
Yeah, you could deodex this file using baksmali, then smali it and decode all with apktool :-)
[G1 Android Development] rfgamaral:
But what should I do after "smaling it"? It creates a out.dex file, should I rename it to classes.dex and put it in the apk?
[G1 Android Development] Daneshm90:
Yes. You are correct.
[G1 Android Development] rfgamaral:
Thank you both :)

Oh, one last thing... Then what? Can I deleted the .apk/.odex pair from /system/app and replace it my own .apk built with Apktool? Should I reboot before testing?
[G1 Android Development] stari4ek:
the answer isn't so simple. Usually - "yes", but if you re-sign it and it uses shared uid (you can check it through it's manifest) all other applications with same shared uid should be re-signed with the same certificate. There are some tricks to prevent re-signing app when you change it's resources.

No. You can replace application on-the-fly.

2Brut.all

Any ETA for next release with issue #44 fix?
[G1 Android Development] rfgamaral:
I guess I'll have that "sharing" problem right?

What should I do exactly? I have no idea what apps should I resign...

But first of all, do I need to resign the apk? My intentions (for now) is to only change the smali code...
[G1 Android Development] stari4ek:
ok =)

First of all. All apk's has sha1 checksum for all files inside it. If you change any of it - you should re-sign application. Usually. But there is a trick. If application lives in /system/app android doesn't check sha1 during install. And you can just add/update files in it without re-signing.

If you change smali code - you'll have classes.dex as output. Probably you can just add this dex to original apk, I didn't try this, usually I resign app if I change smali code.

And be careful, if this application is used by others, They'll fail, cause they're depended on it's odex (they store crc of it). You should un-odex them too.

On other side, if you re-sign application with the shared uid, you can't just push it back - system will reject it, due incompatibility of certificate. You should re-sign all application with the same shared uid. Be careful, sometimes applications have more that one shared uid =)

Yes, it's not that easy like it looks for the first time.

For example, to change smali in Phone.apk I had to re-sign 20 apks.

Probably somebody correct me, and show much simpler way.
[G1 Android Development] rfgamaral:
It's indeed harder than it looks lol...

That and this being my first time looking at smali code, I don't think it will be easy for me to do that I want. As simple as it is...

It would be pretty cool too if I could and it would be even better to release it to the public. But it would be "complicated" to resign "20" apks for such simple change, if that was the case with me of course.

By the way, in case you want to know, what I'm trying to do is to change GoogleContactsProvider to disable photo sync. Why you might ask? Because when photos get synced up with Google Contacts, the photos get resized and compressed a lot as you are probably aware. If this could be disabled, then the photos added in the phone would stay in high quality/resolution.
[G1 Android Development] stari4ek:
Yes, It's a great goal. We all aware of this problem.

I recommend you to try just add produced classes.dex to existing apk using standard zip utility.

Don't forget to remove it's odex from the device.

By the way re-signing is really simple. The main problem to solve all dependencies. And another one, if you re-sign upgradeable app (like google maps) it will fail to update through Market.

PS. in the htc hero's rom there are 7 application with this shared uid
[G1 Android Development] rfgamaral:
That's exactly what I did, do I still to resign it? I mean, I've done a few changes to smali already, built the apk and pushed it to the phone (odex removed) and so far everything's working without any problems, I have not signed anything...

Is it the same procedure as signing an update.zip file? Cause I've done that in the past... I never understood the key thing though, I got one from this forum. Shouldn't I sign stuff with my own key, so people where the stuff came from?

I'll investigate that if I get this working... So far, my smali code changes have no effect, photo always gets synced. Which is weird because I'm removing code and everything is working. It should at least force close on me... Or maybe I'm removing something else and since I'm just looking at the photo, I don't see what happens elsewhere...

EDIT:

I must have done something wrong before, cause now it's force closing like hell... I even restored all my changes, rebuilt the apk, pushed it and it still force closes. Weird... Maybe because I did not sign it?
[G1 Android Development] stari4ek:
Speaking about abstract "right way" - all apps should have proper certificate inside with valid sha1 checksums for all files. But it makes problems for us to change something inside of it. The only reason why it works is that system doesn't check validness for apk's inside /system/app. Good for us =), It won't work for apps from /data/app for example.

yes, it's the same.

I can't say you if you should use your own key or test key is enough, I haven't decide it for me too =).

Did you clean it's entries from the dalvik cache? Did you remove odex from device?

I think, that we should to stop hijecking this thread. Probably it's time to move our discussion to jabber =), otherwise brut.all will kick us =)
[G1 Android Development] rfgamaral:
Well, I'm going to stop anyway...

I can't seem to do it, it keeps force closing now, even if I build the apk with no changes at all. And yes, I deleted the odex file and everything on /data/dalvik-cache. But I can restore the originals and it starts working just fine (no need to restore a nandroid backup).

I have a report to write for a uni project, I dont time for this right now anyway... But if anyone has a clue why this is happening, I'll try to look into it another time.

Thanks for all your help.

Sorry about the thread hijack.
[G1 Android Development] capychimp:
roise

hey i tried debuild and build rosie from hero 2.1 gsm and got some errors building see the file included
[G1 Android Development] Brut.all:
Hmm... :-/ Did you installed 2.apk framework file using if/install-framework command or maybe you did this manually (by copying a file)?
[G1 Android Development] capychimp:
i did manually maybe thats why? ;)

yeah thats it, thx man