Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 970
vijay Avatar asked Dec 11 '25 19:12

vijay


1 Answers

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 :

  • disable proguard to confirm that it is the cause of the problem
  • if it is confirmed : try to configure it so hat it won't obfuscate class that are serialized in json (i.e. UserMessage) :

    -keep class com.company.UserMessage** { *; }

like image 127
ben75 Avatar answered Dec 14 '25 07:12

ben75