PGMacDesign
PGMacDesign

Reputation: 6322

Android: Debug and Release Builds Having Different Results

I am about to publish a release version on the store of my app. The debug version (I am using my phone in lieu of the emulator), works perfectly without any problems.

The "Signed APK" version, however, is not connecting to the back-end at all.

How I generated the Signed APK in Android Studio:

My standard requests (IE Signin, getUser, GetSomethingX) are all erroring out. This proves to be a larger problem than I originally thought as I cannot figure out how to test log print statements and see them in the log cat. I, of course, can use Toasts, but it's a bit of a pain to try and read it all that way. There is no difference between the debug and release versions of the actual code I wrote.

The question: Is there something that I am missing as to why my debug version of the APK works perfectly but the build/ release version does not? I have been going back and forth with the network guy on the back-end where we are not sure who is at fault here. Is there something fundamentally different enough between the debug and release versions of an app that could prevent it from working as it should?

Anyone know?

Thanks all!

Upvotes: 3

Views: 3211

Answers (2)

PGMacDesign
PGMacDesign

Reputation: 6322

Ok, found the answer.

The solution is basically the same to this question here: Gson deserialize null pointer in released apk

My original question of whether there is a difference between release and debug builds: The answer is that if you use proguard and set minifyEnabled to true, it will Obfuscate (See link here for Obfuscation details/ Definition) your code (Which I WANTED to happen). Generally, this is not a problem for the code as it compiles points in the R file to the correct Strings and makes zero difference what they are named, BUT, when you are using a dependency like Gson, it does matter because Gson needs to read the incoming JSON Strnig variables names and match them in your code.

The end result here is that to fix the original problem of no JSON objects being parsed correctly, you only need to add serialized names to your POJO class variables. An example would be:

public class Person {
    @SerializedName("name")
    private String name;
    @SerializedName("email")
    private String email;
    @SerializedName("phoneNumber")
    private String phoneNumber;
    .
    //Setters and Getters
    .
}

TL/DR - Always add @SerializedName("JSON_VARIABLE_NAME") to all of your POJO class variable names if you are using Gson.

Upvotes: 9

JNTX 1412
JNTX 1412

Reputation: 75

maybe this wont answering your question
have you use the usb debugging?
it's a method that allow you to debug your apps straight from your real phone
you just need download the driver, enable your phone debugging mode, then plug in your phone to your PC/laptop via usb
this is the link about how to setup the usb debugging

this for the driver

hope this will help you
Best regards

Upvotes: -1

Related Questions