资源/ code路径改变为PKG在Android应用程序更新 [英] Resource/Code path changing for pkg on Android App update

查看:442
本文介绍了资源/ code路径改变为PKG在Android应用程序更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我更新了新版本我的应用程序,共享preferences都没有了。

  

LogCat中说:从包装de.xxx.yyy codePATH改变   /data/app/de.xxx.yyy-1.apk到/data/app/de.xxx.yyy-2.apk; 护   数据并使用新的

该包是和以前一样。

清单文件的变化是:

 安卓版本code =6 - >安卓版code =7
机器人:VERSIONNAME =1.6.000 - >机器人:VERSIONNAME =1.8
 

和添加权限:

 <使用-权限的Andr​​oid:名称=android.permission.VIBRATE/>
 

为什么新的安装路径和新的数据? 任何人的想法什么happend?

更新 也许ProGuard的问题。 ??? 新的共享preferences有另一端的信件。

  OLD:de.xxx.yyy.a.f.xml
新:de.xxx.yyy.a.h.xml
 

我从类的名称。

 共享preferences米preFS = activity.getShared preferences(
                THECLASS.class.getName(),Activity.MODE_PRIVATE);
 

解决方案

不要使用类名作为键共享preferences。

更好地利用字符串常量共享preferences,而不是类名。

Proguard的将混淆你的类名,这可以,如果您添加或修改的东西在你的项目进行更改。使用ProGuard你的类名是动态的。

 共享preferences米preFS = activity.getShared preferences(
                YOURSTRING,Activity.MODE_PRIVATE);
 

If i update my app with a new version, the sharedPreferences are gone.

LogCat says: Package de.xxx.yyy codePath changed from /data/app/de.xxx.yyy-1.apk to /data/app/de.xxx.yyy-2.apk; Retaining data and using new

The Package is the same as before.

The changes of the manifest-file are:

android:versionCode="6" -> android:versionCode="7"
android:versionName="1.6.000" -> android:versionName="1.8"

and added Permission:

<uses-permission android:name="android.permission.VIBRATE" />

Why the new installation path and the new data? Anybody an idea whats happend?

Update Maybe proguard is the problem. ??? The new sharedPreferences have other end letters.

OLD: de.xxx.yyy.a.f.xml
NEW: de.xxx.yyy.a.h.xml

I get the name from the class.

SharedPreferences mPrefs = activity.getSharedPreferences(
                THECLASS.class.getName(), Activity.MODE_PRIVATE);

解决方案

Never use a classname as key for your sharedPreferences.

Better use a constant String for sharedPreferences instead of the class name.

Proguard will obfuscate your classname and this could be changed if you add or modify something in your project. With proguard your classname is dynamic.

SharedPreferences mPrefs = activity.getSharedPreferences(
                YOURSTRING, Activity.MODE_PRIVATE);

这篇关于资源/ code路径改变为PKG在Android应用程序更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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