Android Studio 1.1.0设置minifyEnabled为true导致应用程序出现问题 [英] Android studio 1.1.0 setting minifyEnabled true causing issues with app
问题描述
这是我的gradle.build文件
Here's my gradle.build file
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
versionCode 2
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Proguard-rules.pro文件
Proguard-rules.pro file
-keepclassmembers class * extends de.greenrobot.dao.AbstractDao {
public static java.lang.String TABLENAME;
}
-keep class **$Properties
-dontwarn com.squareup.**
-dontwarn okio.**
-dontwarn retrofit.**
-dontwarn org.joda.time.**
我有一个Java类之一
I have one of the java class as
public class Endpoints {
public final static String GET_ENDPOINT = "MY_ENDPOINT";
}
我在改造后的适配器中使用的
which I use in my retrofit restadapter as
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(Endpoints.GET_ENDPOINT)
.setLogLevel(RestAdapter.LogLevel.NONE)
.setConverter(new GsonConverter(gson))
.setClient(new OkClient(BusProvider.getClientInstance()))
.build();
现在,当minifiyEnabled为false时,整个代码工作正常,但是我将minifyEnabled设置为true,则不会发生网络调用.我的应用程序启动后立即调用此端点,但是网络日志未显示正在发出的网络请求.有人可以告诉我这是怎么回事吗?
Now when minifiyEnabled is false, the entire code works just fine but I set minifyEnabled true, the network call doesn't happen. My app calls this endpoint as soon as it is launched but the network logs dont show the network request being made. Can someone tell me whats wrong here?
推荐答案
Proguard在我在项目中使用的许多库中都无法很好地发挥作用.
Proguard doesn't play well with many of the libraries I used in my project.
对于gson,我在 http://google-gson.googlecode.com/svn/trunk/examples/android-proguard-example/proguard.cfg
您需要更改
-keep class com.google.gson.examples.android.model.** { *; }
到
-keep class com.your.package.name.your.models.** { *; }
要进行翻新,您需要添加
For retrofit you need to add
-dontwarn retrofit.**
-keep class retrofit.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepclasseswithmembers class * {
@retrofit.http.* <methods>;
}
从这里 https://github.com/square/retrofit/issues/117
对于我添加的joda库
For joda library I added
-keep class org.joda.time.** { *; }
-dontwarn org.joda.time.**
对于otto,您需要添加
For otto you need to add
-dontwarn com.squareup.**
-keepclassmembers class ** {
@com.squareup.otto.Subscribe public *;
@com.squareup.otto.Produce public *;
}
从此处获取 https://github.com/StephenAsherson/Android-OttoSample/blob/master/proguard-project.txt
我还添加了
-keep class com.squareup.okhttp.** { *; }
在使用这些配置更改之前,proguard将我的应用程序从3.4 mb修剪到2 mb.使用这些更改后,它将其缩小到3.2 mb,因此我将使用minifyEnabled false.
Before using these configuration changes proguard trimmed my app from 3.4 mb to 2 mb. After using these changes it shrinks it to 3.2 mb so I am just going to go with minifyEnabled false.
这篇关于Android Studio 1.1.0设置minifyEnabled为true导致应用程序出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!