androidjsonadtproguardspring-android

Empty json data in Release build (using proguard)


My app doesn't post data to server when I run the release version (signed, Proguard packed). But if I run it directly from ADT, I see the data on the server.

It's weird because it just the same code, one is signed and the other is direct execution. Here is the Code (using org.springframework.web.client.RestTemplate):

private static String URL = "https://myappserver.com/abcservice/";

public ResponseEntity<String> sendMessage(UserMessage us) {
    private RestTemplate template = getTemplate();
    HttpEntity<UserMessage> reqEntity = new HttpEntity<UserMessage>(us, headers);
    ResponseEntity<String> result = 
            template.postForEntity(URL, reqEntity, String.class);
    return result;
}

Below are the 2 scenarios:

Case 1: Works Good

  1. Run the App directly from ADT (Run as: Android Application)
  2. User taps a button, which will invoke sendMessage(..) method.
  3. Controller (on Server) gets the request and the data (UserMessage).
  4. An entry with UserMessage is created.
  5. Server send a 201 response (request has been fulfilled), to the app.

Case 2: PROBLEM

  1. Pack the app (Android Tools -> Export Signed Application Package..)
  2. Install it on device through command line (adb install xxx.apk)
  3. Start the app.
  4. User taps a button, which will invoke sendMessage(..) method.
  5. Controller (on Server) gets the request but no data.
  6. An entry with empty UserMessage is created.
  7. Server send a 201 response (request has been fulfilled), to the app.

I have tried to log both on my device and web server, I can confirm that empty data is received for Case 2, and I'm not able to figure out why it doesn't send data when I pack it?

Does packed/released (Signed +Proguard) apps behave differently, compared to debug packaging?


Solution

  • I guess that it is caused by proguard. Proguard is probably obfuscating some portion of your code, but this code is dynamically invoked by Spring (and jackson ? you didn't mention it). (and so once it is obfuscate : dynamic invocation failed)

    So try to :