Fast-Android-Networking icon indicating copy to clipboard operation
Fast-Android-Networking copied to clipboard

Header parameters are not attached to the request when set minify to true

Open aomari opened this issue 4 years ago • 0 comments

I have an MVP structure project, and it's working very well on development flavour, but when I generate production APK, the app is not working. And after investigation, we found that the requests sent to the server without the header

return Rx2AndroidNetworking.get(url)
                .addHeaders(getApiHeader().getPublicApiHeader())
                .doNotCacheResponse()
                .build()
                .getObjectSingle(MyModel.class);

and here it is the ApiHeader class:

@Singleton
public class ApiHeader {

    private ProtectedApiHeader mProtectedApiHeader;
    private PublicApiHeader mPublicApiHeader;

    @Inject
    public ApiHeader(PublicApiHeader publicApiHeader, ProtectedApiHeader protectedApiHeader) {
        mPublicApiHeader = publicApiHeader;
        mProtectedApiHeader = protectedApiHeader;
    }

    public ProtectedApiHeader getProtectedApiHeader() {
        return mProtectedApiHeader;
    }

    public PublicApiHeader getPublicApiHeader() {
        return mPublicApiHeader;
    }

    public static final class PublicApiHeader {
        @Expose
        @SerializedName("content-type")
        private String contentType;
        @Expose
        @SerializedName("lang")
        private String language;

        @Inject
        public PublicApiHeader(String language) {
            setContentType("application/json");
            setLanguage(language);

        }

        public String getContentType() {
            return contentType;
        }

        public void setContentType(String contentType) {
            this.contentType = contentType;
        }

        public String getLanguage() {
            return language;
        }

        public void setLanguage(String language) {
            this.language = language;
        }
    }

    public static final class ProtectedApiHeader {
        @Expose
        @SerializedName("token")
        private String mAccessToken;
        @Expose
        @SerializedName("content-type")
        private String contentType;
        @Expose
        @SerializedName("lang")
        private String language;

        public ProtectedApiHeader(String accessToken, String language) {
            setAccessToken(accessToken);
            setContentType("application/json");
            setLanguage(language);
        }

        public String getAccessToken() {
            return mAccessToken;
        }

        public void setAccessToken(String accessToken) {
            this.mAccessToken = accessToken;
        }

        public String getContentType() {
            return this.contentType;
        }

        public void setContentType(String contentType) {
            this.contentType = contentType;
        }

        public String getLanguage() {
            return language;
        }

        public void setLanguage(String language) {
            this.language = language;
        }
    }
}

and I have added the following line at the MyApplication.java

if (BuildConfig.DEBUG) {
            AndroidNetworking.enableLogging(HttpLoggingInterceptor.Level.BODY);
        }

why the .addHeaders(getApiHeader().getPublicApiHeader()) is working on development flavour and not working on production flavour? and how can I fix this issue?

aomari avatar Apr 16 '20 09:04 aomari