Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Thursday, November 24, 2011

Taking a peek at Android source code (decompiling)

Are you curious about some Android apps behavior?
Do you want to learn how some things are done on Android?

Android apps are written in Java, so it's easy to assume that a .apk file is the same as a .jar file. And if you know a bit of the Java world, you know that a .jar file is nothing more than a renamed .zip file containing compile binaries (.java files).
In the case of .apk files you can find a single classes.dex file (if the app is optimized, you'll find an .odex file) for code and resources and manifest related files. These files are generally not directly accessible. For reading them you'll need some tools.

For some info about the difference between .dex and .odex files you can go here. I won't talk about odexing apps in this article.

Remember that when decompiling an app you won't get the exact original source code, but an approximate that may not even compile back.

Here are the tools for you to open an .apk file:
- dex2jar;
- JD-GUI (Java Decompiler);
- apktool;

You can obtain two different results depending on the tools you use. With dex2jar you can convert a classes.dex file to a regular .jar which can be decompiled by Java Decompiler.
With apktool you can obtain the AndroidManifest.xml, all resource files and the code in a kind of assembler language.

Both of the tools are easy to use:
dex2jar (windows) --> dex2jar.bat classes.dex
apktool (windows) --> apktool.bat d .apk

Now to the hard part. Go play!

Thursday, August 18, 2011

Root for HTC Desire

It's been a while since I rooted my HTC Desire and I should have written about it at the time.

HTC smartphones have a security check so that the ROM can't be written called S-ON.
To have a full root, you need to S-OFF, but for most cases that won't be necessary.

It is possible to have regular root and to use custom ROMs when S-ON, using a custom recovery image. The recovery is a command line shell used to control the ROM.

For HTC Desire and some other HTC smartphones, you can use the simple method of unrevoked:
- unrevoked Home Page
- unrevoked Wiki

Just need to install the drivers for your smartphone, and run the unrevoked tool (don't forget to backup EVERYTHING, because you never know what can go wrong). It will restart your phone and install a ClockworkMod recovery image and root your phone.

After this process you can install any custom ROM and use apps that require root.

I recommend as a first install Titanium Backup for an easy tool to manage your backups of apps and data.

Titanium Backup QR Code:

Wednesday, December 15, 2010

Andruino (Cont.)

I've done some searching about the possibility to being able to compile arduino sources on an Android device and upload it to the Arduino via USB.

Well, I've learned that the stock Android doesn't support the use of the USB port, so it could only be done by rooting your device.

For this to work your device should also be able to use USB OTG, as it would have to be the server in the connection to the Arduino.

Here's the best shot so far to be able to implement this idea.

However it is possible to communicate via bluetooth or WiFi with the stock Android, but for the Arduino that would require an extra shield (XBee) or a specific board (Arduino BT).
There is a project for this, called Amarino. It is designed specifically for communication between Android and Arduino by Bluetooth.

Also I found that the stock Android source for HTC phones is shared here.
This can give people hints on how to circumvent the software limitation.

If rooting your device is an option, Cellbots is the way to go.

Friday, November 19, 2010

Andruino

My two newest hobbies are Android and Arduino.

So I thought of a way to combine them.

Wouldn't it be cool to be able to compile and upload code from an Android phone to an Arduino?

In the next days I'll search about that possibility and related issues.

Monday, September 20, 2010

Android Virtual Keyboard on the Emulator

It happened to me that the emulator's keyboard started as something like Japanese or Chinese.



To change the Android keyboard you'll have to long press the lower left key of the virtual keyboard until you see a menu.



Select 'Input Method' and then 'Android Keyboard'.



And now you're ready to go!

Wednesday, September 8, 2010

Cellphone Network problems

Today I got scared while going to work in seeing that i had no network on the phone.
My girlfriend's phone had no problems (she has the same network) and after reboot (engineer solution) it remained the same.

So when testing for solutions is that I got me worried. I tried Automatic network search, and after 2 minutes of processing, the phone began a restart loop...

So I tried to change SIM card with my girlfriend. In her phone, all fine.
In mine all the same...

But I found that without a SIM card, my phone had no problems...

I went home to back up my contacts and because i left there my USB cable. Upon arrival, I noticed that my phone already had network and everything worked fine. :0

Upon returning to work, I lost network again. So that was the problem, since my girlfriend's phone always worked?

Well, here's the secret:
I only needed to change the Network Mode of 'GSM / WCDMA Automatic' to 'GSM only'.

I assume that my carrier has a problem with the 3G in the area of my job from now on, as at home it works well on 3G and GSM works fine at my job.

I hope to help someone with this ...

Tuesday, August 24, 2010

Android On The Move

I like to keep my personal development environments on a USB drive, because i spend a lot of time on computers other than my own (mostly because of business trips).

So I felt the need to create an Android portable environment.
You can't build this environment on-the-fly, that is, without an initial installation. Most software will be 'stolen' from their original locations.

Sadly, i still only work on Windows (to lazy to spend more time on Linux), so i probably won't be able to help if you need to do the same on Linux (but probably it's not that different from what I did).

So here are the steps I managed so far:

1 - JDK
I'm using jdk1.6.0_20 (the latest at the time). I've downloaded and copied the jdk1.6.0_20 folder to my USB drive. A copy will be enough, after a little configuration.

2 - Eclipse
I'm using 3.5 (Galileo). Also just needed a simply copy of the root folder to the USB drive.

3 - Android SDK
I'm using revisions 6 (for Eclair) and 7 (for Froyo). You should download all the targets necessary before copying the folders. Then, you'll need to copy the root folder (android-sdk-windows) to your USB drive.

4 - AVD (Emulators)
To debug we need an emulator that will run our app. Unfortunately, it needs to be created beforehand on a fixed environment. So, all we have do is to copy the *.avd folder to our .android/avd folder.
AVD uses .ini files to configure target platform and installation path. As this has to be a full path and can't have shell variables, I chose to reconfigure that path in the batch file used to start-up eclipse.

5 - Batch file
To boot the environment we need to indicate to eclipse where to find the virtual machine and the sdk tools. So I start my environment with this script:


REM Updates AVD path config
type "%CD%\.android\avd\[sample].ini" | find /v "path=" > "%CD%\.android\avd\[sample].tmp"
copy /y "%CD%\.android\avd\[sample].tmp" "%CD%\.android\avd\[sample].ini"
echo path=%CD%\.android\avd\[sample].avd>>"%CD%\.android\avd\[sample].ini"
del "%CD%\.android\avd\[sample].tmp"

REM Defines Android home directory (defaults to the users' home directory)
SET ANDROID_SDK_HOME=%CD%

REM Defines path to swt.jar (not sure if necessary)
SET ANDROID_SWT=%CD%\android-sdk-windows\tools\lib\x86

REM -data "." defines the workspace path to load
REM -vm defines the path to the virtual machine
.\eclipseJava\eclipse.exe -data "." -vm".\jdk1.6.0_20\bin\javaw"


This should be enough to allow you to take your Android developments everywere.

Wednesday, August 4, 2010

HTC Desire Android 2.2 OTA

I finally received Android 2.2 for my HTC Desire.

As no upgrade will run perfectly (must be a Murphy's Law), here are the problems i've encountered:

- Google Contacts updated automatically, removing all data saved to phone only (a.k.a. private). Should have saved that data as merged contacts;
- Google Market seems slower (probably just to much users at the time because of the upgrade, or slow wi-fi).
- Google Market no longer shows list of apps installed before the upgrade (but they still work, and can be updated/removed if you search for the app) (after installing new app, the full list was restored);
- My Calendar (offline) was removed. Couldn't find a way to create another;

Generally i haven't noticed any differences, besides a few new apps (Flashlight, Location Picker, Hotspot Wi-Fi) and improved UI (Application Manager).

A Saga

Como estava tão entusiasmado quando escrevi o post anterior sobre o Android...

Entretanto surgiram as férias e outros possíveis projectos e lá se foi para último plano.
Para além disso o portátil queimou, por isso as condições de trabalho agora não são as melhores

Há que arranjar um tempinho para voltar a 'subir ao cavalo'!

Friday, July 9, 2010

Paranoid.Android

Finalmente troquei de telemóvel. Depois de mais de 6 anos de Nokia 5100, acabei por me render a um HTC Desire.

Com isto ganhei um novo interesse. Desenvolver para Android.
Vou registando por aqui as minhas desventuras com a plataforma da Google.
Fiquem atentos!