Debugging

master
Tomasz Półgrabia 2016-10-09 16:10:30 +02:00
parent 00e5e7dfdf
commit fa093876b2
6 changed files with 152 additions and 26 deletions

View File

@ -19,8 +19,8 @@
-keepattributes Signature -keepattributes Signature
-keepattributes InnerClasses -keepattributes InnerClasses
-dontwarn ch.qos.logback.core.net.** -dontwarn ch.qos.logback.core.net.**
-assumenosideeffects class ch.qos.logback.** { *; } # -assumenosideeffects class ch.qos.logback.** { *; }
-assumenosideeffects class org.slf4j.** { *; } # -assumenosideeffects class org.slf4j.** { *; }
-keep class com.crashlytics.** { *; } -keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.** -dontwarn com.crashlytics.**
-dontwarn retrofit2.** -dontwarn retrofit2.**
@ -41,3 +41,54 @@
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent { -keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
<init>(java.lang.Throwable); <init>(java.lang.Throwable);
} }
# Retrofit 1.X
-keep class com.squareup.okhttp.** { *; }
-keep class retrofit.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**
-dontwarn okio.**
-dontwarn retrofit.**
-dontwarn rx.**
-keepclasseswithmembers class * {
@retrofit.http.* <methods>;
}
# If in your rest service interface you use methods with Callback argument.
-keepattributes Exceptions
# If your rest service methods throw custom exceptions, because you've defined an ErrorHandler.
-keepattributes Signature
# Also you must note that if you are using GSON for conversion from JSON to POJO representation, you must ignore those POJO classes from being obfuscated.
# Here include the POJO's that have you have created for mapping JSON response to POJO for example.
-keep class com.google.gson.** { *; }
-keep class com.google.inject.** { *; }
-keep class org.apache.http.** { *; }
-keep class org.apache.james.mime4j.** { *; }
-keep class javax.inject.** { *; }
-keep class retrofit.** { *; }
-keep class ch.qos.logback.** { *; }
-keep class org.slf4j.** { *; }
# Proguard rules for retrofit
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on RoboVM on iOS. Will not be used at runtime.
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions
-keep class java.nio.file.** { *; }
-keep class retrofit2.** { *; }
-keep class okio.** { *; }

View File

@ -54,7 +54,14 @@ public class GooglePlacesWorker extends AsyncTask<GooglePlacesRequest, Integer,
param.getSearchItemType(), param.getSearchItemType(),
param.getPageToken()); param.getPageToken());
lg.debug("Whole retrofit response: {}", placesResponse);
if (placesResponse != null && placesResponse.code() == HttpStatus.SC_OK) { if (placesResponse != null && placesResponse.code() == HttpStatus.SC_OK) {
lg.debug("Retrofit respone code: {}, body: {}, error body: {}, message: {}",
placesResponse.code(),
placesResponse.body(),
placesResponse.errorBody(),
placesResponse.message());
GooglePlacesResponse response = new GooglePlacesResponse(); GooglePlacesResponse response = new GooglePlacesResponse();
final GooglePlaceResponse responseBody = placesResponse.body(); final GooglePlaceResponse responseBody = placesResponse.body();
lg.debug("Google response body: {}", responseBody); lg.debug("Google response body: {}", responseBody);
@ -83,7 +90,9 @@ public class GooglePlacesWorker extends AsyncTask<GooglePlacesRequest, Integer,
final String googleStatus = response.getStatus(); final String googleStatus = response.getStatus();
if (!"OK".equals(googleStatus) && !"SUCCESS".equals(googleStatus)) { if (!"OK".equals(googleStatus) && !"SUCCESS".equals(googleStatus)) {
if (!"OVER_QUERY_LIMIT".equals(googleStatus)) { if (!"OVER_QUERY_LIMIT".equals(googleStatus)) {
Toast.makeText(ctx, "Google returned status {}", Toast.LENGTH_LONG).show(); Toast.makeText(ctx,
String.format("Google returned status %s", googleStatus),
Toast.LENGTH_LONG).show();
} else { } else {
Toast.makeText(ctx, Toast.makeText(ctx,
"This application has exceeded free google places api daily limit - 150k." + "This application has exceeded free google places api daily limit - 150k." +

View File

@ -16,6 +16,41 @@
# public *; # public *;
#} #}
# Retrofit 1.X
-keep class com.squareup.okhttp.** { *; }
-keep class retrofit.** { *; }
-keep class retrofit2.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**
-dontwarn okio.**
-dontwarn retrofit.**
-dontwarn rx.**
-keepclasseswithmembers class * {
@retrofit.http.* <methods>;
}
# If in your rest service interface you use methods with Callback argument.
-keepattributes Exceptions
# If your rest service methods throw custom exceptions, because you've defined an ErrorHandler.
-keepattributes Signature
# Also you must note that if you are using GSON for conversion from JSON to POJO representation, you must ignore those POJO classes from being obfuscated.
# Here include the POJO's that have you have created for mapping JSON response to POJO for example.
-keep class com.google.gson.** { *; }
-keep class com.google.inject.** { *; }
-keep class org.apache.http.** { *; }
-keep class org.apache.james.mime4j.** { *; }
-keep class javax.inject.** { *; }
-keep class retrofit.** { *; }
-keep class ch.qos.logback.** { *; }
-keep class org.slf4j.** { *; }
# Proguard rules for retrofit # Proguard rules for retrofit
# Platform calls Class.forName on types which do not exist on Android to determine platform. # Platform calls Class.forName on types which do not exist on Android to determine platform.
@ -28,6 +63,7 @@
-keepattributes Signature -keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance. # Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions -keepattributes Exceptions
-keep class java.nio.file.** { *; } -keep class java.nio.file.** { *; }
-keep class retrofit2.** { *; } -keep class retrofit2.** { *; }
-keep class okio.** { *; } -keep class okio.** { *; }

View File

@ -0,0 +1,14 @@
package pl.tpolgrabia.googleutils.utils;
import retrofit2.Converter;
import retrofit2.Retrofit;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
/**
* Created by tpolgrabia on 09.10.16.
*/
public class CustomConverter extends Converter.Factory {
}

View File

@ -2,10 +2,7 @@ package pl.tpolgrabia.googleutils.utils;
import android.content.Context; import android.content.Context;
import com.androidquery.AQuery; import com.androidquery.AQuery;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.logging.HttpLoggingInterceptor;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import pl.tpolgrabia.googleutils.GooglePlacesService; import pl.tpolgrabia.googleutils.GooglePlacesService;
@ -53,7 +50,7 @@ public class PlacesUtils {
} }
OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
// httpClient.addInterceptor(new RetrofitDebugInterceptor()); httpClient.addInterceptor(new RetrofitDebugInterceptor());
Retrofit retrofit = new Retrofit.Builder() Retrofit retrofit = new Retrofit.Builder()
.baseUrl(GooglePlacesConstants.GOOGLE_MAPS_PLACES_API_BASEURL) .baseUrl(GooglePlacesConstants.GOOGLE_MAPS_PLACES_API_BASEURL)
@ -74,22 +71,4 @@ public class PlacesUtils {
} }
private static class RetrofitDebugInterceptor implements Interceptor {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
final Request req = chain.request();
okhttp3.Response response = chain.proceed(req);
boolean successFull = response.isSuccessful();
int code = response.code();
String message = response.message();
String msg = response.body().string();
lg.debug("Got response. Is successfull: {}, code: {}, message: {}, msg: {}",
successFull,
code,
message,
msg);
// now we repeat once again (because we have used the stream)
return chain.proceed(chain.request());
}
}
} }

View File

@ -0,0 +1,37 @@
package pl.tpolgrabia.googleutils.utils;
import android.util.Log;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.ResponseBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
/**
* Created by tpolgrabia on 09.10.16.
*/
class RetrofitDebugInterceptor implements Interceptor {
private static final Logger lg = LoggerFactory.getLogger(RetrofitDebugInterceptor.class);
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
final Request req = chain.request();
okhttp3.Response response = chain.proceed(req);
boolean successFull = response.isSuccessful();
int code = response.code();
String message = response.message();
String msg = response.body().string();
Log.d("XXX", String.format("Got response. Is successfull: %d, code: %d, message: %s, msg: %s",
successFull ? 1 : 0,
code,
message,
msg));
// now we repeat once again (because we have used the stream)
return response.newBuilder()
.body(ResponseBody.create(response.body().contentType(), msg))
.build();
}
}