Android studio 1.1.0 设置 minifyEnabled true 导致应用程序出现问题 [英] Android studio 1.1.0 setting minifyEnabled true causing issues with app

查看:59
本文介绍了Android studio 1.1.0 设置 minifyEnabled true 导致应用程序出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的 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,我添加了 gson 团队在 http://google-gson.googlecode.com/svn/trunk/examples/android-proguard-example/proguard.cfg

For gson I added the proguard rules given by the gson team at 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.** { *; }

对于改造,您需要添加

-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆