# 琐碎的一些tips

## MultiDex打包时zip错误

我遇到的是

Execution failed for task ':excelSior:packageAllDebugClassesForMultiDex'.java.util.zip.ZipException: duplicate entry: android\\/support\\/v4\\/util\\/TimeUtils.class

在gradle里，把v4的依赖换成这样子就好了：

```
dependencies {
    compile fileTree(include: '*.jar', dir: 'libs')
    compile 'com.android.support:multidex:1.0.1@aar'
}
```

## 多语言

默认的values文件夹里的strings.xml作为英语的字符串资源文件，新建一个values-zh文件夹，里面放一个strings.xml文件，只不过value都是中文，这样就会自动根据系统语言调用字符串了。

## Preference

android.support.v7.preference可以实现material design效果的设置页面，但我们要如何用getSharedPreference那套方法来操作其中的数据呢？关键在于配置xml文件的名称，查询android.support.v7.preference.PreferenceManager的构造方法，看到：

```java
public PreferenceManager(Context context) {
        this.mContext = context;
        this.setSharedPreferencesName(getDefaultSharedPreferencesName(context));
    }
```

所以可以用getDefaultSharedPreferencesName来获得xml文件的名字，另一种方法：

```java
SharedPreferences sps = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
String userName = sps.getString(getString(R.string.pref_user_name_key), getString(R.string.pref_default_user_name));
```

用getDefaultSharedPreferences来获取。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blog.cweihang.io/android/note.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
