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

Mou*_*ssi 5 android gradle apk android-studio

生成的"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();
Run Code Online (Sandbox Code Playgroud)

从此活动中删除字符串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();
Run Code Online (Sandbox Code Playgroud)

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

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

Failure [INSTALL_FAILED_DEXOPT]  
Run Code Online (Sandbox Code Playgroud)

当我尝试在'build variant:release'上安装时,我得到了这个:

在此输入图像描述

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

在OK或取消我得到:

Failure [INSTALL_FAILED_DEXOPT]
Run Code Online (Sandbox Code Playgroud)

注意:在模拟器上一切都很好

Kon*_*iak 2

你必须在顶部添加这个插件build.gradle

apply plugin: 'com.android.application'
Run Code Online (Sandbox Code Playgroud)

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

buildTypes {
    release {
        signingConfig android.signingConfigs.config

    }
}
Run Code Online (Sandbox Code Playgroud)

当您第二次使用空时,productFlavors您不需要它,请将其删除。

当您assembleRelease task通过方法执行此调用表单控制台时:

./gradlew task assembleRelease
Run Code Online (Sandbox Code Playgroud)

你将有 apk 文件{your_project}/{your_module[propadbly apk]}/build/outputs/apk/

最后,请确保使用正确的密钥。你的日志说:

Failed to read key bbalarmkey from store "/Users/XXXXXXX/key.jks": Keystore was tampered with, or password was incorrect
Run Code Online (Sandbox Code Playgroud)

这意味着该密钥不存在或者您在配置中犯了一些错误