apache/cordova-android · error · GradleException

${filePath}: Missing key required "${key}"

Error message

${filePath}: Missing key required "${key}"

What it means

doEnsureValueExists is the guard Cordova's gradle scripts use whenever a Java properties file must contain a key. doGetProjectTarget requires target in project.properties (or ../project.properties); the app template's addSigningProps uses privateHelpers.ensureValueExists as the fallback for storeFile and keyAlias in signing properties files; plugin gradle scripts can call it too. When props.get(key) returns null it throws a GradleException naming the offending file and key.

Source

Thrown at framework/cordova.gradle:26

    with the License.  You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
*/

import groovy.xml.XmlParser
import java.util.regex.Pattern
import io.github.g00fy2.versioncompare.Version

String doEnsureValueExists(filePath, props, key) {
    if (props.get(key) == null) {
        throw new GradleException(filePath + ': Missing key required "' + key + '"')
    }
    return props.get(key)
}

String doGetProjectTarget() {
    def props = new Properties()
    def propertiesFile = 'project.properties';
    if(!(file(propertiesFile).exists())) {
      propertiesFile = '../project.properties';
    }
    file(propertiesFile).withReader { reader ->
        props.load(reader)
    }
    return doEnsureValueExists('project.properties', props, 'target')
}

Boolean isVersionValid(version) {
    return !(new Version(version)).isEqual('0.0.0')

View on GitHub (pinned to 7c1e190064)

Solutions

  1. Open the file named in the message and add the missing key — for project.properties that is e.g. target=android-34.
  2. For signing files, add storeFile=/abs/path/app.keystore and keyAlias=alias (or the legacy key.store / key.alias pair) to the named .properties file.
  3. If platform files look hand-mangled, regenerate them: cordova platform rm android && cordova platform add android, then reapply only documented customizations.

Example fix

# before — platforms/android/project.properties
sdk.dir=/opt/android-sdk

# after
sdk.dir=/opt/android-sdk
target=android-34
Defensive patterns

Strategy: validation

Validate before calling

// Fail fast with your own message before Cordova's gradle script runs (build-extras.gradle or a prebuild task)
def props = new Properties()
file('project.properties').withReader { props.load(it) }
def required = ['target']
def missing = required.findAll { props.get(it) == null }
if (missing) {
    throw new GradleException('project.properties missing required keys: ' + missing.join(', '))
}

Prevention

When it happens

Trigger: platforms/android/project.properties lost its target= line (manual edit, bad merge, partially generated platform); release-signing.properties / debug-signing.properties contains neither key.store nor storeFile (or neither key.alias nor keyAlias), so the fallback lookup fires and fails; a plugin gradle script calls privateHelpers.ensureValueExists for a key its props file does not define.

Common situations: Projects generated by very old cordova-android releases then upgraded in place; platform files hand-edited or cloned incompletely (platforms/ partially in git); signing properties files trimmed down during CI setup; plugins that rewrite properties files in before_build hooks.

Related errors


AI-assisted analysis of apache/cordova-android@7c1e190064 (2026-08-22). Data as JSON: /api/errors/84520344c16defc2. Report an issue: GitHub.