首页 > 解决方案 > 我的 build.gradle 与第 22 行中的错误不兼容

问题描述

我使用 keytool 生成了我的密钥并将其粘贴到 android/app 文件夹中,但是运行命令 ./gradlew assembleRelease 会返回错误:

➜ android git: (master) / ./gradlew assembleRelease

FAILURE:构建失败并出现异常。

我的 build.gradle 与文档不同,附上我展示了我的 build.gradle

// 顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项。

buildscript {
    ext {
        buildToolsVersion = "28.0.2"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 27
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
android { // line 22
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}


task wrapper(type: Wrapper) {
    gradleVersion = '4.7'
    distributionUrl = distributionUrl.replace("bin", "all")
}

构建文件“/Volumes/Projetos/Apps/calculator/android/build.gradle”行:22

标签: androidreactjsbuildandroid-gradle-pluginnative

解决方案


将以下行添加到 /android 文件夹中的 gradle.properties 文件中

MYAPP_UPLOAD_STORE_FILE=youkeystorefilenamehere.keystore
MYAPP_UPLOAD_KEY_ALIAS=yourkeyalias
MYAPP_UPLOAD_STORE_PASSWORD=yourstorepassword
MYAPP_UPLOAD_KEY_PASSWORD=yourkeypassword

推荐阅读