签名APK:失败[INSTALL_FAILED_DEXOPT] ..更新

时间:2015-03-12 22:53:34

标签: android android-studio gradle apk

" app-release.apk"生成...不是我的设计,但" app-debug.apk"工作得很好,

更新

转到我的应用程序的上一个版本后:

在我的MainActivity我有这个字符串:

public class MainActivity extends ActionBarActivity {

 @Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

     final String PREFS_NAME = "MyPrefsFile";

     SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);

     if (settings.getBoolean("my_first_time", true)) {
         //the app is being launched for first time, do something

         TeamModel pm;
         DBHelper db;

         String teamNames1= "Los Angeles Lakers";
         String teamOpponent1= "Golden State Warriors";
         String teamDate1= "2015-03-16 22:30";

         String teamNames2= "Atlanta Hawks";
         String teamOpponent2= "Sacramento Kings";
         String teamDate2= "2015-03-16 20:00";

         .
         .

         String teamNames348= "Charlotte Hornets";
         String teamOpponent348= "Utah Jazz";
         String teamDate348= "2015-03-16 21:00";


         db = new DBHelper(getApplicationContext());
         db.getWritableDatabase();
         pm = new TeamModel();



         pm.teamname=       teamNames1;
         pm.teamopponent=teamOpponent1;
         pm.teamdate=        teamDate1;

         db.addTeam(pm);

         pm.teamname=       teamNames2;
         pm.teamopponent=teamOpponent2;
         pm.teamdate=        teamDate2;

         db.addTeam(pm);
         .
         .
         pm.teamname=       teamNames348;
         pm.teamopponent=teamOpponent328;
         pm.teamdate=        teamDate348;

         db.addTeam(pm);

         Log.d("Comments", "First time");
         settings.edit().putBoolean("my_first_time", false).commit();

从此活动中删除字符串1到107(teamNames,teamOpponent,teamdate)后,应用程序在我的设备上正常运行

解释更多我的MainActivity成了:

public class MainActivity extends ActionBarActivity {

 @Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

     final String PREFS_NAME = "MyPrefsFile";

     SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);

     if (settings.getBoolean("my_first_time", true)) {
         //the app is being launched for first time, do something

         TeamModel pm;
         DBHelper db;

         String teamNames107= "Los Angeles Lakers"; !!!
         String teamOpponent107= "Golden State Warriors"; !!!
         String teamDate107= "2015-03-16 22:30"; !!!

         String teamNames108= "Atlanta Hawks";
         String teamOpponent108= "Sacramento Kings";
         String teamDate108= "2015-03-16 20:00";

         .
         .

         String teamNames348= "Charlotte Hornets";
         String teamOpponent348= "Utah Jazz";
         String teamDate348= "2015-03-16 21:00";


         db = new DBHelper(getApplicationContext());
         db.getWritableDatabase();
         pm = new TeamModel();



         pm.teamname=       teamNames107;
         pm.teamopponent=teamOpponent107;
         pm.teamdate=        teamDate107;

         db.addTeam(pm);

         pm.teamname=       teamNames108;
         pm.teamopponent=teamOpponent108;
         pm.teamdate=        teamDate108;

         db.addTeam(pm);
         .
         .
         pm.teamname=       teamNames348;
         pm.teamopponent=teamOpponent328;
         pm.teamdate=        teamDate348;

         db.addTeam(pm);

         Log.d("Comments", "First time");
         settings.edit().putBoolean("my_first_time", false).commit();

出了什么问题?如何在不删除字符串的情况下修复此问题?

当我尝试通过终端在我的设备上安装app-release.apk时出现错误日志:

Failure [INSTALL_FAILED_DEXOPT]  

当我尝试在构建变体上安装时,发布'我明白了:

enter image description here

  

安装失败,因为设备可能有与当前版本不匹配的过时dexed jar(dexopt错误)。要继续,您必须卸载现有的应用程序。      警告:卸载将删除应用程序数据!      是否要卸载现有应用程序?

关于确定或取消我得到了:

Failure [INSTALL_FAILED_DEXOPT]
NB:在模拟器上一切正常

4 个答案:

答案 0 :(得分:4)

如果您使用的是模拟器,请关闭模拟器。运行 AVD Manager ,然后单击编辑按钮擦除模拟器的数据。 在 android studio 中,您可以通过右键单击模拟器轻松擦除模拟器。 enter image description here

如果它在您的真实设备中。然后转到设置>>应用程序>> 然后搜索您的应用并执行两项操作。

  1. 清除数据
  2. 卸载
  3. enter image description here

    现在运行你的应用程序。它应该工作。

答案 1 :(得分:2)

您必须在build.gradle

的顶部添加此插件
apply plugin: 'com.android.application'

首先,如果您想通过密钥对应用程序进行签名,则应在构建类型中添加此密钥,如下所示:

buildTypes {
    release {
        signingConfig android.signingConfigs.config

    }
}

第二个你使用空productFlavors,你不需要它,请删除它。

执行此操作时,请按方法调用assembleRelease task表格控制台:

./gradlew task assembleRelease

您将在{your_project}/{your_module[propadbly apk]}/build/outputs/apk/

中找到apk文件

最后你要确保使用正确的钥匙。你的日志说:

Failed to read key bbalarmkey from store "/Users/XXXXXXX/key.jks": Keystore was tampered with, or password was incorrect

这意味着密钥不存在或您在配置中出错了

答案 2 :(得分:1)

在build.gradle中

更改编译并构建到最新版本。它对我有用。

=====

android {
    compileSdkVersion 22
    buildToolsVersion "22"

答案 3 :(得分:1)

尝试使用adb卸载您的应用。像这样:adb uninstall <package_name>。你有没有尝试过其他手机?