Can't create a release apk with keystore file

Hi guys, I cannot for the life of me figure out how to do a release build because I’m useless at this CI stuff. I’ve read your doc on code signing at least 5 times now :smiley: .

I wanted to go for option 2 because I’d rather not have to touch my gradle file. So I uploaded the keystore to BitRise, set the password etc, changed the default Gradle Runner to assembleRelease, and added a sign-apk workflow step after the gradle runner.
I get an error telling me it can’t find a keystore so the build fails. What do you think I’m doing wrong here?


I then tried option 1 and modified my build.gradle with a new signing config:

release{
        v2SigningEnabled false
        keyAlias System.getenv("BITRISEIO_ANDROID_KEYSTORE_ALIAS")
        keyPassword System.getenv("BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD")
        storeFile file(System.getenv("BITRISEIO_ANDROID_KEYSTORE_URL"))
        storePassword System.getenv("BITRISEIO_ANDROID_KEYSTORE_PASSWORD")
    }

That didn’t work either, it can’t find the keystore:
annot convert URL '<‘https://concrete-userfiles-production.s3-us-west-2.amazonaws.com/project_file_storage_documents/uploads/ - <snip>’ to a file.

1 Like

Na’, first steps are always hard but you’ll get into it in no time, don’t worry! :wink:

I’d suggest as well if you’re getting started.

Sounds good :slight_smile:

I’d suggest you to revert that change, it’s not required if you go with option 2. Let’s stick with Option 2, using the Sign APK step :wink:

Could you please copy paste the related build’s bitrise.io URL? Sounds like a minor misconfiguration - with the URL I can check the logs & the config the build ran with :wink:

Thanks Viktor! Here is the most recent build. Correct me if I’m wrong but does the gradle task assembleRelease not just attempt to create a signed apk in one step (using whatever environment variables are in the gradle)? In which case I need to create an unsigned apk first I guess and somehow pass it to the sign-apk task.

If it makes any difference my assemble task is actually a build variant: assembleRelease_slim, but I don’t think that matters.

From the log of the build:

Caused by: java.lang.IllegalArgumentException: Keystore file not set for signing config release

Are you sure that you reverted the build.gradle changes (the ones mentioned here http://devcenter.bitrise.io/android/code-signing/#1-specify-code-sign-configuration-in-your-project )? It seems your build.gradle is still configured to use a keystore file.

I’d suggest you to remove the signingConfigs section from there (e.g. https://github.com/bitrise-samples/sample-apps-android-sdk22/blob/master/app/build.gradle); that should allow gradle to generate an unsigned release APK, which then can be signed by the Sign APK step.

Let me know how it goes or if you’d have any questions! :wink:

Hey there, I struggled with this for a while and realized that it was due to a missing build.gradle configuration:

// make sure you include signingConfigs above the buildTypes block
signingConfigs {
    release {
        keyAlias System.getenv("BITRISEIO_ANDROID_KEYSTORE_ALIAS")
        keyPassword System.getenv("BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD")
        storeFile file(System.getenv("HOME") + "/keystores/bcs.jks")
        storePassword System.getenv("BITRISEIO_ANDROID_KEYSTORE_PASSWORD")
    }
}

//include signingConfig.release in your release buildType configuration. 
buildTypes {
    debug {
     ...
    }
    release {
    ...
        signingConfig signingConfigs.release
    }
}

Perhaps a rookie mistake, but could be a good idea to cover this in the documentation.

3 Likes

Hi I am still getting following error
Execution failed for task ‘:app:validateSigningStgRelease’.

Keystore file ‘/root/keystores/*****.jks’ not found for signing config ‘release’

Here is build.gradle

release {
keyAlias System.getenv(“BITRISEIO_ANDROID_KEYSTORE_ALIAS”)
keyPassword System.getenv(“BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD”)
storeFile file(System.getenv(“HOME”) + “/keystores/*****.jks”)
storePassword System.getenv(“BITRISEIO_ANDROID_KEYSTORE_PASSWORD”)
}

Also I have added signing config in my release build types
release {
signingConfig signingConfigs.release
}

Can you suggest what I am doing wrong here?

Hi there @yashraj-deserve, :wave:

It seems we would need a little more information to investigate. Could you please send us a build URL where this issue happens and enable Support Access on the Settings tab of the app (https://devcenter.bitrise.io/troubleshooting/enabling-bitrise-support-user/ )? This way we can check things out better on our end. :slight_smile: If you are not comfortable sharing your build here, please feel free to submit a support ticket here.

Thanks,
Kata :star2:

Hi Kata,

I am able to create a release apk with keystore file for our android project but when I tried to install build to device its showing following error

Performing Streamed Install
adb: failed to install <apk path/name>bitrise-signed.apk: Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES: Scanning Failed.: No signature found in package of version 2 or newer for package package name]
Can you help in finding probable solution?

Hi @yashraj-deserve,

Try setting Use apksigner to true in the Sign step’s configuration. The old signing tool (jarsigner) only signs the APK with the V1 signature, while apksigner signs with multiple signature schemes based on minSdkVersion and targetSdkVersion. So your APK will be signed with the V2 scheme as well.

You can read more about signing scheme versions here: https://source.android.com/security/apksigning#schemes

1 Like

Hi Oliver,

It works for me. Thanks for solution