2017-01-23 92 views
3

我正在使用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配置相同,尽管我不确定它可能是什么。

+0

您使用的是progaurd吗? –

+0

是的。 Retrofit,OkHttp和OkHttp3都添加到我的proguard规则中。 – Orbit

+0

你可以添加你的progaurd规则吗? –

回答

1

我相信我解决了这个问题。更新有关的依赖,缩小下来到我的ProGuard配置的问题后,我增加了以下规则来我proguard-rules.pro

# Retrofit 2.X 
... 
-keepclasseswithmembers class * { 
    @retrofit2.http.* <methods>; 
} 

# Note: had already been added when updating to OkHttp 3. 
# OkHttp3 
-keepattributes Signature 
-keepattributes *Annotation* 
-keep class okhttp3.** { *; } 
-keep interface okhttp3.** { *; } 
-dontwarn okhttp3.** 

此外,一些本地的文件并没有被保存。包括那些明确的规则或确保您使用通配符来保留所有本地文件应该可以解决问题:

#local 
-keep class example.** { *; } 
+0

你可以接受你自己的答案并获得一个徽章。 –

+0

有两天的等待时间才能接受自己的答案。 – Orbit

+0

哎呀,对不起,那么! –