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

问题描述 投票:0回答:1

[运行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

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

android reactjs react-native android-studio react-native-android
1个回答
0
投票

除了在签名配置之外,您还必须在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"
        }
    } 
© www.soinside.com 2019 - 2024. All rights reserved.