Search code examples
androidreleasesigninggluon-mobile

Gluon android packaging fails on release/signing


I am following the gluonhq documentation for a release config for android: https://docs.gluonhq.com/#platforms_android_distribution_build and https://docs.gluonhq.com/#_signing_for_release.

I generate a keystore as follows: keytool -genkeypair -keyalg rsa -alias pstar -keystore [fullpathtoKS]/PStar.ks -validity 9125 -v

where [fullpathtoKS] is my path to the keystore. I enter the prompted info and get the following returned:

Generating 2,048 bit RSA key pair and self-signed certificate (SHA256withRSA) with a validity of 9,125 days
    for: CN=...
[Storing [fullpathtoKS]/PStar.ks]

Then I enter up the required 4 parameters properties on the POM for release:

<android-keystore-path>[fullpathtoKS]/PStar.ks</android-keystore-path>
<android-keystore-password>myKSpwd</android-keystore-password>
<android-key-alias>pstar</android-key-alias>
<android-key-password>myKSpwd</android-key-password>

On running gluonfx:build and then gluonfx:package, I get the error:

[Thu Sept 29 11:39:59 EEST 2022][SEVERE] The key store path [fullpathtoKS]/PStar.ks is not valid. Using Debug signing configuration
Check the log files...

But no further info can be found in the logs as to why the packaging fails. I created a little Java program:

String keystore = "[fullpathtoKS]/PStar.ks";
String alias = "pstar";
String aliasPw = "myKSpwd";
String ksPw = "myKSpwd";
        
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());

try( FileInputStream fis = new FileInputStream(keystore) ) {
     ks.load(fis, ksPw.toCharArray());
}

ks.getEntry(alias, new KeyStore.PasswordProtection(aliasPw.toCharArray()));

and no exceptions are thrown. The paths and passwords are all OK.

So I assume gluon is not happy with the keystore entry itself. How do I find out what gluonfx:package is complaining about and how to fix it?


Solution

  • The error you see comes from Substrate, when it tries to evaluate the signing configuration you have provided via the GluonFX plugin:

    if (keyStorePath == null || 
        ANDROID_KEYSTORE_EXTENSIONS.stream().noneMatch(keyStorePath::endsWith) || 
        !Files.exists(Path.of(keyStorePath)) || keyAlias == null || keyStorePass == null || keyPass == null) {
                if (keyStorePath != null) {
                    Logger.logSevere("The key store path " + keyStorePath +
                            " is not valid. Using Debug signing configuration");
                }
                return "Debug";
            }
    

    If you check the values in ANDROID_KEYSTORE_EXTENSIONS, you'll see:

    ANDROID_KEYSTORE_EXTENSIONS = List.of(".keystore", ".jks");
    

    Which, according to the Android documentation, for app-signing:

    Java Keystores (.jks or .keystore) are binary files that serve as repositories of certificates and private keys

    are the two valid extensions expected.

    This explains why your extension .ks is not working.

    So all you need to do is rename your key store to PStar.jks, or if that doesn't work, generate one again.