3

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?

ben75
  • 29,217
  • 10
  • 88
  • 134
vijay
  • 831
  • 9
  • 14

3 Answers3

4

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** { *; }

ben75
  • 29,217
  • 10
  • 88
  • 134
  • Yes, it is Spring + Jackson. Also using `org.springframework.http.converter.json.MappingJackson2HttpMessageConverter` – vijay Jun 19 '14 at 20:23
  • 1
    Correct, the proguard was screwing up things. And `-keep class ....` helped. Thanks a lot. – vijay Jun 19 '14 at 20:25
1

I have same issue, and I committed below 2 line

// shrinkResources true

// minifyEnabled true

enter image description here

Abdullah
  • 2,393
  • 1
  • 16
  • 29
0

The above answer didnt work for me may be it was correct on 2014 For 2019 when I set the compileSdkVersion 28 it works.

Bahaa Hany
  • 744
  • 13
  • 22