我正在使用Retrofit来调用API。我添加了一个拦截器来查看被请求的url。在调试版本中,网址被正确翻译,但签名版本导致网址不能被翻译和解析,因为它应该。一些相关的代码如下:翻新网址未被正确翻译
改造服务:
@GET("/1.1/launch/next/{number}")
Observable<LaunchResponse> getNextXLaunches(@Path("number") int numberOfNextLaunches);
调用此方法时,我简单地传递一个整数,以确定发射到请求的数目。在签名的apk,上述产生以下网址:
..../1.1/launch/next/%7BlaunchNum%7D
,而不是
..../1.1/launch/next/10
正如你所看到的,传递到路径的价值没有被正确翻译,而是{number}
正在逐字解决。
我也遇到类似的问题今后尝试后不同的版本:
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4'
compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:okhttp:3.5.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.5.0'
我感到奇怪的是运行已签名的版本APK此问题时,才存在。什么可能导致这个问题?什么是修复?
编辑:按照要求,这里有一些相关的ProGuard规则:
# Retrofit 2.X
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
# OkHttp
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**
# OkHttp3
-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
编辑:我已经建有minifyEnabled
集中的释放false
禁用ProGuard的,它工作正常。因此,这个问题必须与我的ProGuard配置相同,尽管我不确定它可能是什么。
您使用的是progaurd吗? –
是的。 Retrofit,OkHttp和OkHttp3都添加到我的proguard规则中。 – Orbit
你可以添加你的progaurd规则吗? –