# Problems with App Bundle

Today I tried to produce an Android App Bundle package for Slide Four.
Few modifies to the project files are required, and it works only with Visual Studio 2019.

Firsts, due to the game is available for Android Oreo (8.1) and lower (back from Lollipop: 5.0), we need to force the install location to use only the internal storage. We specify this in AndroidManixest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alimede.android.slidefour" android:versionCode="7"
android:versionName="1.1.7" android:installLocation="internalOnly">


The official documentation state that this constraint is required only for now, maybe next upgrades of Visual Studio will remove it.

Seconds, we need to instruct the build tool to generate an .aab file (Android App Buldle).
So these directives must be added into the Android .csproj file:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<AndroidPackageFormat>aab</AndroidPackageFormat>
</PropertyGroup>


I just added this code before the last line conteining the closing </Project> tag.

Last, to generate the .aab package file, we need to use a command via Developer Console (menu Tools->Command line->Developer console). Create a file into the Android project folder containing the following instructions:

msbuild -restore SlideFour.Android.csproj ^
-t:SignAndroidPackage ^
-p:Configuration=Release ^
-p:AndroidKeyStore=True ^
-p:AndroidSigningKeyStore="C:\path\to\slidefour.keystore" ^
-p:AndroidSigningKeyAlias=slidefour ^
-p:AndroidPackageFormat=aab

Once created, just invoke this command via the Developer Console to produce the App Bundle .aab package. We need to execute these instructions manually because the Visual Studio IDE don't allow it at the moment.

Ok, well done... i think.. but... but.... go to Google Play, create a new release uploading the .aab file, the web interface recognize all the packages contained, press the Verify release and...

#### ...an error appears.. doh!

"This release cannot be implemented because don't allow existing users to upgrade to last added APK."
(translated from italian)

After a bit of online research, the problem seems to be due to an incompatibility of the signature, even if the signature is the same used in previous APKs.
I compared the certificates used in AAB and old APKs:

1. extract the META-INF/CERT.RSA from AAB and old APK using 7zip.
2. display the certificate with openssl using my Linux box:
openssl pkcs7 -inform DER -in CERT.RSA -noout -print_certs -text > cert.txt
3. verified the differences between cert files:
diff cert_aab.txt cert_apk.txt

No differences found!

If I try to launch a debug session in my development device, which contains a previous version of Slide Four compiled with Visual Studio 2017, the compiler tell me that it's not possible to install the new version due to an exception:

Caused by: com.android.ddmlib.InstallException: Failed to finalize session : INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.alimede.android.slidefour signatures do not match the previously installed version; ignoring!

Effectively the error message match the package signature issue :-) !

I'm thinking it's not possible to install a AAB package where an APK is already present... hmm... no, rather I made a mistake that now eludes me.

BTW: eventually i rollback the modifies and produce a new APK version 1.1.8 with Visual Studio 2017, and the upload in Google Play was ok.

Seee ya again...