I have a problem when updating to my apk will not be installed due to the above message.
I read SO posts that say this message occurs when an application is signed with a different release key.
example of a message on different keys
. In my logs, when I try to update apk, I get the following:
04-07 13:28:03.796 2072-2072/? W/InstallAppProgress: Replacing package:com.xxx.rr3 04-07 13:28:04.326 3675-3845/? W/PackageManager: verifying app can be installed or not 04-07 13:28:04.378 3675-3845/? W/PackageManager: Package com.xxx.rr3 signatures do not match the previously installed version; ignoring!
. The original application has been released for over 4 years and was written using Eclipse, which is installed on my old hard drive.
6 months ago, my boss bought me an SSD drive and I installed Android Studio. I transferred the old project, and it works fine, and it will be installed on a device that does not have a previous version installed.
I copied the keystore from my old hard drive to my new SSD, and I use it to sign a new version of the application in Android Studio. Therefore, I used only one keystore with the same passwords and aliases.
Can someone tell me why Android says my update is signed with a different key?
[Update1]
I extracted CERT.RSA for the old and new apk. They both use the same key store and keys, but I noticed that I used the wrong release alias. Below are the fingerprints for both apks, the upper one is old, lower, new.
C:\OpenSSL-Win64\bin>keytool -printcert -file CERT.RSA Owner: CN=matthew womersley, OU=dev, O=carefreegroup, L=wakefield, ST=west yorkshire Issuer: CN=matthew womersley, OU=dev, O=carefreegroup, L=wakefield, ST=west yorkshire Serial number: 6144ad2c Valid from: Fri Jan 11 08:55:29 GMT 2013 until: Thu May 14 09:55:29 BST 3012 Certificate fingerprints: MD5: 50:63:5E:54:9D:D3:C4:71:A9:4E:3C:F4:27:9E:50:CA SHA1: 7C:2C:DB:7E:92:D2:01:46:43:8D:D2:B9:A4:D2:B0:F4:85:E7:16:D9 SHA256: 38:64:89:4D:A2:37:72:AA:CE:90:5E:34:46:B9:D0:A4:CA:18:B7:07:7A:E2:DB:1D:7C:60:CD:70:F6:77:C5:FF Signature algorithm name: SHA256withRSA Version: 3 Extensions:
I pointed out the correct releases when I clicked "Generate Signed Apk", but still there is an error, although another.
Package conflicts with existing package with the same name
. I tried to create a new apk manually using the following link:
link
C:\Users\mattheww\StudioProjects\nfcscanner3>gradlew assembleRelease Downloading https://services.gradle.org/distributions/gradle-2.14.1-all.zip Unzipping C:\Users\mattheww\.gradle\wrapper\dists\gradle-2.14.1-all\8bnwg5hd3w55iofp58khbp6yv\gradle-2.14.1-all.zip to C:\Users\mattheww\.gradle\wrapper\dists\gradle-2.14.1-all\8bnwg5hd3w55iofp58khbp6yv FAILURE: Build failed with an exception. * Where: Build file 'C:\Users\mattheww\StudioProjects\nfcscanner3\app\build.gradle' line: 1 * What went wrong: A problem occurred evaluating project ':app'. > java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0 * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 29.982 secs
.
If the keystore and fingerprint storage are the same in both applications, can someone explain why the new application will still not be updated?
[UPDATE 2]
I just remembered that when I imported the Eclipse project into Android Studio, it would not be built correctly. There was a problem with the application object. My application object is called NfcScannerApplication, and I have a class implemented with the same name (which is also described in the manifest).
After importing into Android Studio, built-in and connected to the device, Android stated that it could not find the application class. so I used the following code that seemed to solve the problem.
public static NfcScannerApplication getRealApplication (Context applicationContext) { Log.e(TAG, "inside NfcScannerApplication getRealApplication"); NfcScannerApplication application = null; if (applicationContext instanceof NfcScannerApplication) { application = (NfcScannerApplication) applicationContext; } else { Application realApplication = null; Field magicField = null; try { magicField = applicationContext.getClass().getDeclaredField("realApplication"); magicField.setAccessible(true); realApplication = (Application) magicField.get(applicationContext); } catch (NoSuchFieldException e) { Log.e(TAG, e.getMessage()); } catch (IllegalAccessException e) { Log.e(TAG, e.getMessage()); } application = (NfcScannerApplication) realApplication; } return application; }
It uses reflection to get the Application class. Could this be the reason that although I use the same keystore, etc., Android believes that there is another application on the device with the same name?
[UPDATE 3] I seem to have found the problem. :) I have a ContentProvider that gets the application context when the application loads first. I call getContext and pass it to the application class.
Now I get a call to getContext.getApplicationContext (), and now it works fine. Below is the code I'm using now, and the old code is listed above.
//old code //Context context = getContext(); //nfcAppObj = (NfcScannerApplication) getContext(); //new code Context applicationContext = getContext().getApplicationContext(); nfcAppObj = getRealApplication(applicationContext);