I have a problem where the upgrade to my apk will not install due to the above message.
I have read posts on SO that say this message happens when the app is signed with a different release key.
example post on different keys
. In my logs as i try to upgrade the 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 orginal app was has been in production 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 migrated the old project and it builds fine and it will install on to a device that doesn't have the previous version installed.
I copied the keystore from my old hard drive to my new SSD and I use it to sign the new version of the app in Android Studio. So i have only ever used the one same keystore, with the same passwords and alias.
Can anyone tell me why Android is saying my upgrade is signed with a different key?
[UPDATE1]
I have extracted the CERT.RSA for both old and new apk. They both use the same keystore and keys but i noticed i was using the wrong release alias. Below is the fingerprints for both apks the top one is the old one the bottom, the new one.
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:
#1: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 3F 95 E8 FA 36 5B 26 07 33 72 8B 09 37 0C 18 C5 ?...6[&.3r..7...
0010: 3B 5A 19 42 ;Z.B
]
]
C:\OpenSSL-Win64\bin>keytool -list -keystore .keystore
keytool error: java.lang.Exception: Keystore file does not exist: .keystore
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
I specified the correct releasealias when clicking on 'Generate Signed Apk' but there is still an error albeit different.
The package conflicts with an existing package by the same name
. I have tried to build the new apk manually, using the following 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 fingerprints match on both apps, can anyone explain why the new app still will not upgrade?
[UPDATE 2]
I have just remembered that when i imported the Eclipse project into Android Studio, it would not build correctly. There was a problem with the Appication Object. My Appication Object is called NfcScannerApplication and i have a class implemented by the same name (which is also described in the manifest).
Once imported into Android Studio, built and pushed on to a device, Android said it could not find the Application class. so i used the following code which 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;
}
// the above method is commented out and this is used
//because the migration process from Eclipse to Android
//needed it. see below
//https://stackoverflow.com/questions/36495954/bootstrapapplication-cannot-be-cast-to-applicationclass
It uses reflection to get the Application class. Could this be the reason why even though i'm using the same keystore etc, Android thinks there is a different app 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 app is first loaded. I call getContext and cast it into my Application class.
What i do now is call getContext.getApplicationContext() and it works fine now. Below is the code i use now and the old code iscommented out above.
//old code
//Context context = getContext();
//nfcAppObj = (NfcScannerApplication) getContext();
//new code
Context applicationContext = getContext().getApplicationContext();
nfcAppObj = getRealApplication(applicationContext);