0

我正在使用TweetTimelineListAdapterfromFabric来显示推文列表。这在禁用 proguard 时效果很好,但是当我启用它时,我的UserTimeline对象停止在其回调中返回任何成功或失败。

我的日志中没有错误或异常。单步执行代码显示访客登录成功,并且发送了推文请求,但从未收到任何响应。

这是我获取推文的方式:

private void loadTweets() {
    TwitterCore.getInstance().logInGuest(new Callback<AppSession>() {
        @Override
        public void success(Result<AppSession> result) {
            // logging in is successful, this code executes
            UserTimeline userTimeline = new UserTimeline.Builder()
                    .screenName("@ScreenName")
                    .maxItemsPerRequest(100)
                    .includeReplies(false)
                    .includeRetweets(true)
                    .build();

            mAdapter = new TweetTimelineListAdapter(TwitterActivity.this, userTimeline);
            mAdapter.registerDataSetObserver(mDataSetObserver);
            ((ListView) findViewById(R.id.tweet_list)).setAdapter(mAdapter);
        }

        @Override
        public void failure(TwitterException e) {
            Log.e(TwitterActivity.class.getName(), "Error performing guest login to twitter", e);
        }
    });
}

private DataSetObserver mDataSetObserver = new DataSetObserver() {
    @Override
    public void onChanged() {
        super.onChanged();

        // display data or error here based on results
        // this code is never executed
    }
};

这是 Fabric 文档中推荐的我的 proguard 配置文件以及我的一些补充:

-dontwarn  com.digits.sdk.android.*ActionBarActivity

# retrofit specific
-dontwarn com.squareup.okhttp.**
-dontwarn com.google.appengine.api.urlfetch.**
-dontwarn rx.**
-dontwarn retrofit.**
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-keep class retrofit.** { *; }
-keepclasseswithmembers class * {
    @retrofit.http.* <methods>;
}

# GSON
-keep class com.google.gson.** { *; }
-keep interface com.google.gson.** { *; }
-dontwarn com.google.gson.**
4

1 回答 1

0

除了您拥有的 Proguard 设置,您还需要添加

-keepclassmembers class com.company.user.* {
public *;
}

和(非常重要)

-keepnames class * implements android.os.Parcelable {
       public static final ** CREATOR;
}

我不得不学习使用尽可能多的 proguard 分隔符更安全的方法,这样您就不会在缩小自定义库或 sdk 时遇到问题。

有关 proguard 所需的所有分隔符的更多信息,请访问此处http://omgitsmgp.com/2013/09/09/a-conservative-guide-to-proguard-for-android/

也许http://blog.androidquery.com/2011/06/android-optimization-with-proper.html

于 2015-07-29T19:09:40.870 回答