alpine-android icon indicating copy to clipboard operation
alpine-android copied to clipboard

local Keystore is not present or missing?

Open cah-iswaria-sasi opened this issue 1 year ago • 5 comments

We are using alvrme/alpine-android:android-34-jdk17 image for our android project.

Challenge: while extracting apk from aab build, we see warning saying debug.keystore isn't present under ~.android/ folder.

why is not present or where shall we find that local debug.keystore signing thing. Please respond what are we missing here and what are the steps to be taken care of.

image

@alvr

cah-iswaria-sasi avatar Nov 05 '24 17:11 cah-iswaria-sasi

someone please help?

cah-iswaria-sasi avatar Nov 25 '24 05:11 cah-iswaria-sasi

The file is created automatically when you compile the project in debug. If you are not compiling it, you need to create it before. You can create a new one executing this command inside the container.

keytool -genkeypair -v -keystore ~/.android/debug.keystore -keyalg RSA -keysize 2048 -validity 10000 -alias androiddebugkey -storepass android -keypass android

Otherwise, if you prefer a Gradle task:

tasks.register("generateDebugKeystore") {
    group = "build setup"
    description = "Generates a debug.keystore file in the ~/.android/ directory."

    doLast {
        val homeDir = System.getProperty("user.home")
        val keystorePath = "$homeDir/.android/debug.keystore"
        val keystoreFile = File(keystorePath)

        if (keystoreFile.exists()) {
            println("debug.keystore already exists at: $keystorePath")
        } else {
            println("Generating debug.keystore at: $keystorePath")
            val command = listOf(
                "keytool",
                "-genkeypair",
                "-v",
                "-keystore", keystorePath, 
                "-keyalg", "RSA",
                "-keysize", "2048",
                "-validity", "10000",
                "-alias", "androiddebugkey",
                "-storepass", "android",
                "-keypass", "android"
            )

            val process = ProcessBuilder(command)
                .redirectOutput(ProcessBuilder.Redirect.INHERIT)
                .redirectError(ProcessBuilder.Redirect.INHERIT)
                .start()

            val exitCode = process.waitFor()
            if (exitCode == 0) {
                println("debug.keystore generated successfully!")
            } else {
                println("Failed to generate debug.keystore. Exit code: $exitCode")
            }
        }
    }
}

Execute this task before building the APK with Bundletool.

alvr avatar Nov 25 '24 06:11 alvr

@alvr Thank you so much, will try this way and get back to you for an update.

cah-iswaria-sasi avatar Nov 25 '24 06:11 cah-iswaria-sasi

@alvr Hi, Below are my observations. -> for apk generation, i tried to build with gradle task - assembleDebug and list to find whether debug.keystore been creating or not. luckily, it is creating debug.keystore by default under ~.android/debug.keystore. image

->for aab generation, tried with gradle task - bundleProdDebug or bundleDebug but its not creating debug.keystore nor present. why? image

cah-iswaria-sasi avatar Nov 25 '24 13:11 cah-iswaria-sasi

By default, AABs are not signed during creation if the signingConfig is not specified for that buildType. That is because the signing is done when creating the APK from that AAB.

https://developer.android.com/build/building-cmdline?hl=en#bundle_build_gradle https://developer.android.com/tools/bundletool?hl=en#generate-apks-from-sdk-bundle

alvr avatar Nov 26 '24 19:11 alvr