Tagandroid

playing with Arduino

Google I/O was awesome! 🙂

//DL

Obfuscate your Android application

Proguard is the nice way to obfuscate your Android application to prevent reverse engineering. Here is Google tutorial for this http://developer.android.com/guide/developing/tools/proguard.html.

But you can face some difficulties with it:

  1. To minimize risk of “class not found” exceptions – don’t obfuscate external libraries that you have in your project. Add -keep option to proguard.cfg
    -keep public class com.google.ads.** {
        public protected *;
    }
  2. If you are using reflection in your code – add these classes to the exclude list:
    -keepclassmembers class * {
        public static void buildUriMatcher(android.content.UriMatcher, java.lang.String);
    }
  3. Stop using onClick listeners in xml resources!:) Or also add an exception:
    public void on*(android.view.View);
  4. In Eclipse you can easily get “conversion to dalvik format failed with error 1”:

    Don’t worry – don’t obfuscate external libraries + don’t use Eclipse for export signed application. Just create build.xml for Ant and all will be just perfect!

    Read more about this problem here: http://bimbim.in/post/2010/09/24/Reason-of-Conversion-to-dalvik-format-failed-with-error-1.aspx

  5. Try to reverse engineering your code with JD (as described here). You may need to remove some debug log String constants to make your code completely unreadable:)

enjoy

//DL

Fragment.onActivityResult is not called

If you are using android fragments compatibility package… and onActivityResult is not called – don’t be afraid! Your code is perfect, it’s Google bug:)
http://code.google.com/p/android/issues/detail?id=15394

I’ve recompiled the library with the fix. Please find it attached.
enjoy!

//DL

Efficient JSON parsing on Android

The most common question: which parser to use for JSON parsing on Android device.
Here are several options:

  1. That comes with platform (org.json) – optimized since 2.2
  2. Jackson
  3. GSON
  4. Something else

Let’s take a look.

  1. org.json – Not very convenient to use. Doesn’t support stream parsing out of the box.
  2. jackson – very convenient to use, excellent mapping features, custom stream deserializers… but don’t use it on Android. Like Facebook and Twitter did… This will put you into the grave:) Everything is excellent before you will take a look into the ddms log.
  3. This is the the log when you are trying to open Facebook news feed (Google Nexus One, 2.2. Facebook v.1.5):

    02-25 02:49:52.862: DEBUG/dalvikvm(22579): GC_FOR_MALLOC freed 3339 objects / 504352 bytes in 68ms
    02-25 02:49:53.762: DEBUG/dalvikvm(170): GC_EXPLICIT freed 1246 objects / 63000 bytes in 94ms
    02-25 02:49:54.002: DEBUG/WifiService(85): releaseWifiLockLocked: WifiLock{NetworkLocationProvider type=2 <a href="mailto:binder=android.os.Binder@44b3cb58">binder=android.os.Binder@44b3cb58</a>}
    02-25 02:49:58.942: INFO/ActivityManager(85): Starting activity: Intent { cmp=com.facebook.katana/.activity.stream.StreamActivity }
    02-25 02:49:59.152: DEBUG/dalvikvm(14758): GC_FOR_MALLOC freed 2159 objects / 607368 bytes in 37ms
    02-25 02:49:59.532: DEBUG/dalvikvm(14758): GC_FOR_MALLOC freed 2156 objects / 152352 bytes in 40ms
    02-25 02:49:59.752: INFO/ActivityManager(85): Displayed activity com.facebook.katana/.activity.stream.StreamActivity: 778 ms (total 778 ms)
    02-25 02:50:00.262: DEBUG/dalvikvm(14758): GC_FOR_MALLOC freed 1128 objects / 271976 bytes in 46ms
    02-25 02:50:00.632: DEBUG/dalvikvm(14758): GC_FOR_MALLOC freed 4492 objects / 928160 bytes in 55ms
    02-25 02:50:03.922: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 1845 objects / 556056 bytes in 66ms
    02-25 02:50:04.012: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 697 objects / 49840 bytes in 39ms
    02-25 02:50:05.702: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 1686 objects / 560232 bytes in 45ms
    02-25 02:50:05.812: DEBUG/dalvikvm(14535): GC_EXPLICIT freed 1270 objects / 45920 bytes in 142ms
    02-25 02:50:05.862: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 535 objects / 26608 bytes in 70ms
    02-25 02:50:06.422: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 1279 objects / 390888 bytes in 42ms
    02-25 02:50:06.782: INFO/dalvikvm(14758): Jit: resizing JitTable from 8192 to 16384
    02-25 02:50:06.952: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 1490 objects / 558784 bytes in 42ms
    02-25 02:50:08.702: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 1222 objects / 498232 bytes in 38ms
    02-25 02:50:09.272: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 1711 objects / 349648 bytes in 72ms
    02-25 02:50:11.322: DEBUG/dalvikvm(14758): GC_FOR_MALLOC freed 3758 objects / 1647488 bytes in 45ms
    02-25 02:50:12.012: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 2347 objects / 624600 bytes in 53ms
    02-25 02:50:12.142: DEBUG/dalvikvm(22579): GC_EXPLICIT freed 2020 objects / 316328 bytes in 86ms
    02-25 02:50:15.712: DEBUG/dalvikvm(14758): GC_FOR_MALLOC freed 2275 objects / 823520 bytes in 65ms
    02-25 02:50:17.552: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 1776 objects / 591760 bytes in 54ms
    02-25 02:50:17.822: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 623 objects / 101408 bytes in 73ms
    02-25 02:50:19.452: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 1172 objects / 473632 bytes in 57ms
    02-25 02:50:20.212: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 700 objects / 74080 bytes in 46ms
    02-25 02:50:20.772: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 804 objects / 119440 bytes in 37ms
    02-25 02:50:21.672: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 1529 objects / 344096 bytes in 42ms
    02-25 02:50:23.602: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 914 objects / 326848 bytes in 44ms
    02-25 02:50:23.662: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 174 objects / 7232 bytes in 40ms
    02-25 02:50:23.752: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 116 objects / 10616 bytes in 50ms
    02-25 02:50:25.202: DEBUG/dalvikvm(14758): GC_EXTERNAL_ALLOC freed 1286 objects / 368296 bytes in 70ms
    

    scaring, right?:)

  4. gson – GSON stream is very nice and small. It doesn’t produce so much garbage as Jackson. But it is not so convenient to use. Good news that GSON stream parser is included in API 11.

I would prefer GSON and org.json for my code.

Happy parsing!

//DL

Android mini figures: boy and girl

No comments. Just brilliant! 🙂

//DL

Honeycomb preview

First impressions:

  1. 01-27 00:13:07.872: ERROR/AndroidRuntime(283): FATAL EXCEPTION: main
    01-27 00:13:07.872: ERROR/AndroidRuntime(283): java.lang.NoSuchMethodError: Activity.getInstanceCount
  2. my notebook display (1680×1050) is really small for this stuff:)

honeycomb preview

//DL

Android wallpaper

How to decompile Android application

It’s quite easy to decompile Android application and take a look into it:)

  1. Download dex2jar tool (thanks to the creator!) http://code.google.com/p/dex2jar/
  2. Find apk that you want to decompile (like Twitter_v1.0.5.apk)
  3. Use dex2jar.bat Twitter_v1.0.5.apk – get Twitter_v1.0.5.apk.dex2jar.jar
  4. Download Java Decompiler
  5. Open jar file – enjoy pure java code:)

java decompiler (dex android)

If you want to take a look into AndroidManifest.xml:

  1. Download AXMLPrinter2.jar
  2. Extract AndroidManifest.xml from apk file
  3. Use java -jar AXMLPrinter2.jar AndroidManifest.xml >> twitter_manifest.txt
  4. Enjoy readable AndroidManifest.xml

Hope you will learn a lot from somebody’s code and create a new powerful Android app! 🙂

//DL

Android Gingerbread 2.3 on Nexus One

We created Gingerbread build for our Nexus One.

    1. Internet SIP Calls works but… sound goes only one way:)
    2. Device startup time is awesome

      Waiting for official build

      //DL

      SIP support in Android 2.3 gingerbread

      As you know there is native SIP support in 2.3. There’s SipManager class for it.

      But it doesn’t work on Emulator! Both functions isApiSupported and isVoipSupported return false, SipManager.newInstance(this) returns null.

      Application is installed without errors althought we have this line in manifest file:

      <uses-feature
          android:name="android.hardware.sip.voip"
          android:required="true" />

      Holy crap, Google! 🙂

      //DL

      © 2020 Android Tales

      Theme by Anders NorenUp ↑