在项目':app'中找不到任务'installDebug'(npx react-native run-android issue)

时间:2020-05-01 10:54:54

标签: android reactjs react-native android-studio react-native-android

运行npx react-native run-android之后,我遇到了常见问题“在项目':app中找不到任务'installDebug'”。 enter image description here

按照建议,我尝试执行此https://reactnative.dev/docs/signed-apk-android,但是当我运行时: 来自Android目录的$ ./gradlew bundleRelease来自: “在根项目'MoscowForDummies'中找不到任务'bundleRelease'。”

我的gradle.properties:

MYAPP_UPLOAD_STORE_FILE=my-upload-key.keystore
MYAPP_UPLOAD_KEY_ALIAS=my-key-alias
MYAPP_UPLOAD_STORE_PASSWORD=Profit***
MYAPP_UPLOAD_KEY_PASSWORD=Profit***

我的build.gradle的一部分:

android {
compileSdkVersion rootProject.ext.compileSdkVersion

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
    applicationId "com.moscowfordummies"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
}
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
        }
    }
}

和我的〜/ .bash_profile:

export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

有人对如何解决问题有任何建议吗?

1 个答案:

答案 0 :(得分:0)

除了signingConfig外,您还必须在build.gradle(app)文件中拥有buildTypes

buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://facebook.github.io/react-native/docs/signed-apk-android.
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }