5

the "app-release.apk" generated ... is not working on my devise, but the "app-debug.apk" is working perfectly,

Update:

after going to the previous version of my App:

in my MainActivity i have this strings:

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();

After deleting Strings 1 to 107 (teamNames, teamOpponent, teamdate) from this Activity the App worked fine on my device

to explain more my MainActivity became:

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();

what's wrong? how can i fix this without deleting Strings?

My error log when i try to install app-release.apk on my device by terminal:

Failure [INSTALL_FAILED_DEXOPT]  

When i try to install on the devise on 'build variant: release' i got this:

enter image description here

Installation failed since the device possibly has stale dexed jars that don't match the current version (dexopt error). In order to proceed, you have to uninstall the existing application. WARNING: Uninstalling will remove the application data! Do you want to uninstall the existing application?

on OK or cancel i got:

Failure [INSTALL_FAILED_DEXOPT]

NB: on Emulator everything is fine

Mounir Elfassi
  • 2,242
  • 3
  • 23
  • 38
  • Why do you use empty productFlavors? – Konrad Krakowiak Mar 12 '15 at 23:03
  • is your buildTypes{ } empty as posted ? – Mohit Mar 12 '15 at 23:04
  • I mean productFlavors{} you have empty closure. Why? – Konrad Krakowiak Mar 12 '15 at 23:05
  • @konrad-krakowiak what should i add in them? – Mounir Elfassi Mar 12 '15 at 23:06
  • @mohit-singh yes empty – Mounir Elfassi Mar 12 '15 at 23:07
  • @MounirElfassi I posted my answer you can see it – Konrad Krakowiak Mar 12 '15 at 23:15
  • Is the apk getting to the device (to determine that, take a look at the "Run" view). If the apk is making it to the device or emulator and failing there then look in the device log using the "Android" view. The views are accessed by selecting the named tags in the lower left of the Android Studio window. Without some info from one of the views it is very hard to tell what might be going on. – AndroidGuy Mar 13 '15 at 13:50
  • @androidguy in the emulator every thing is fine but in my 2 devices i have "Failure [INSTALL_FAILED_DEXOPT] " also a message (see my edited post) – Mounir Elfassi Mar 14 '15 at 15:36
  • Any reason why you include the twitter library twice? The first dependency already compiles every `.jar` in `libs` directory. Maybe the compiler silently fails after trying to include same classes twice... – Eugen Pechanec Mar 16 '15 at 00:45
  • Is your device a Samsung? There was a problem with older `appcompat-v7` library included in the phone colliding with the one you include with your `.apk`. – Eugen Pechanec Mar 16 '15 at 00:53
  • @eugen-pechanec i just removed "compile files('libs/twitter4j-core-4.0.2.jar')" from my build and still the same problem, i have a moto g 2014 and a samsung note 3, on both devices the problem exist – Mounir Elfassi Mar 16 '15 at 00:59
  • Can you open the `.apk` in WinRAR (or other archiving program) and check if it contains `classes.dex`? – Eugen Pechanec Mar 16 '15 at 01:02
  • Try raising `buildToolsVersion` to 22.0.0, `compileSdkVersion` to 22, `targetSdkVersion` to 22 and `appcompat-v7` to 22.0.0. (Download latest tools using SDK manager if needed.) – Eugen Pechanec Mar 16 '15 at 01:05
  • @eugen-pechanec no luck, i did the raising + updating my sdk – Mounir Elfassi Mar 16 '15 at 11:35
  • @eugen-pechanec yes there is 'classes.dex' and the size is 3 MB – Mounir Elfassi Mar 16 '15 at 11:43
  • Try assigning the strings directly to your holder object `pm.teamName = "Lakers..."` Too many declared variables? I've never seen this behavior before. BTW: Why do you bother using database when you hold all the data in memory anyway? Either keep a static array of teams *OR* consider using a [premade database](http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/). – Eugen Pechanec Mar 16 '15 at 13:04
  • Did you fix this issue? – Krish Aug 05 '15 at 22:10
  • no, i just deleted all the strings that i don't need, but i would like to know what was wrong – Mounir Elfassi Aug 07 '15 at 07:44
  • no, i just removed the strings and moved on. – Mounir Elfassi Aug 13 '15 at 08:57

4 Answers4

4

If you are using Emulator then close the emulator. Run AVD Manager and Wipe data of the emulator clicking on edit button. In android studio you can easily wipe you emulator by right clicking on the emulator. enter image description here

If it is in your real device. Then go to Settings>>Applications>> Then search your app and do 2 things.

  1. Clear data
  2. Uninstall

enter image description here

Now run you application. It should work.

Mohammad Arman
  • 7,020
  • 2
  • 36
  • 50
2

You have to add this plugin in the top of build.gradle

apply plugin: 'com.android.application'

As first if you want to sign your application by your key you should add this key in build types as is shown below:

buildTypes {
    release {
        signingConfig android.signingConfigs.config

    }
}

As the second you use empty productFlavors you don't need it please remove it.

When you do this call assembleRelease task form console by method:

./gradlew task assembleRelease

You will have apk file in {your_project}/{your_module[propadbly apk]}/build/outputs/apk/

And as last you make sure that you use proper key. Your logs says:

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

this mean that the key doesn't exist or you make some wrong in your config

Konrad Krakowiak
  • 12,285
  • 11
  • 58
  • 45
1

in build.gradle change compiled and build to latest version. and it worked for me.

================

android {
    compileSdkVersion 22
    buildToolsVersion "22"
riseres
  • 3,004
  • 4
  • 28
  • 40
1

Try to uninstall your app with adb. Like this: adb uninstall <package_name>. Have you tried it with other phones?

Thomas Vos
  • 12,271
  • 5
  • 33
  • 71