(React-Native)任务:app:generatePackageList FAILED

Posted

技术标签:

【中文标题】(React-Native)任务:app:generatePackageList FAILED【英文标题】:(React-Native) Task :app:generatePackageList FAILED 【发布时间】:2021-09-15 01:10:58 【问题描述】:

我想部署一个生成 APK 文件的 react-native 项目,但是当我在 android 文件夹中使用 ./gradlew assembleRelease 时,控制台显示:

任务:app:generatePackageList 失败

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

在哪里: 脚本 '.\ReactNativeProject\ETS_Finder\node_modules@react-native-community\cli-platform-android\native_modules.gradle' 行:131
出了什么问题: 任务“:app:generatePackageList”执行失败。

java.lang.IllegalArgumentException(无错误消息)`

我已经按照 React-Native 文档的建议为应用创建了一个密钥并修改了 build.gradle 文件。

我也尝试使用 Android Studio 构建相同的应用,但构建输出显示:Build Failed : Cause: argument type mismatch

编辑 1 我的 build.gradle :

project.ext.react = [
    enableHermes: false,  // clean and rebuild if changing
]

apply from: "../../node_modules/react-native/react.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

/**
 * The preferred build flavor of javascriptCore.
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
 *
 * The international variant includes ICU i18n library and necessary data
 * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
 * give correct results when using with locales other than en-US.  Note that
 * this variant is about 6MiB larger per architecture than default.
 */
def jscFlavor = 'org.webkit:android-jsc:+'

/**
 * Whether to enable the Hermes VM.
 *
 * This should be set on project.ext.react and mirrored here.  If it is not set
 * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
 * and the benefits of using Hermes will therefore be sharply reduced.
 */
def enableHermes = project.ext.react.get("enableHermes", false);

android 
    ndkVersion rootProject.ext.ndkVersion

    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions 
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    

    defaultConfig 
        applicationId "com.ets_finder"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    

    signingConfigs 
    release 
      storeFile file('your_key_name.keystore')
      storePassword 'your_key_store_password'
      keyAlias 'your_key_alias'
      keyPassword 'your_key_file_alias_password'
    
  

    splits 
        abi 
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        
    
    signingConfigs 
        debug 
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
            
        
    
    buildTypes 
        debug 
            signingConfig signingConfigs.debug
        
        release 
            // Caution! In production, you need to generate your own keystore file.
            // see https://reactnative.dev/docs/signed-apk-android.
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        
    

    // applicationVariants are e.g. debug, release
    applicationVariants.all  variant ->
        variant.outputs.each  output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null)   // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        defaultConfig.versionCode * 1000 + versionCodes.get(abi)
            

        
    


dependencies 
    implementation fileTree(dir: "libs", include: ["*.jar"])
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules

    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

    debugImplementation("com.facebook.flipper:flipper:$FLIPPER_VERSION") 
      exclude group:'com.facebook.fbjni'
    

    debugImplementation("com.facebook.flipper:flipper-network-plugin:$FLIPPER_VERSION") 
        exclude group:'com.facebook.flipper'
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    

    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:$FLIPPER_VERSION") 
        exclude group:'com.facebook.flipper'
    

    if (enableHermes) 
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
     else 
        implementation jscFlavor
    


// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) 
    from configurations.compile
    into 'libs'


apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

反应原生:"version": "0.64.2"

【问题讨论】:

GabryLinux 分享更多来自 build.gradle 和 react-native 版本的 android 配置信息 【参考方案1】:

我在这篇文章中找到了解决方案:

https://***.com/questions/67093053/react-native-execution-failed-for-task-appgeneratepackagelist

它说 react-native-cli 不支持 Gradle 7.0 版,所以需要将 Gradle 降级到以前的版本(例如,我使用了 Gradle 6.6 版)

【讨论】:

【参考方案2】:

我遇到了同样的错误,降级到 Gradle 6.9 工作正常!

【讨论】:

以上是关于(React-Native)任务:app:generatePackageList FAILED的主要内容,如果未能解决你的问题,请参考以下文章

android应用程序的任务':app:processDebugManifest'的React-native执行失败

任务':app:bundleReleaseJsAndAssets'的React-Native assembleRelease失败

执行 react-native run-android 时任务:app:processDebugResources FAILED

运行 npm react-native run-android 时突然出错。任务:app:processDebugResources 失败

> 任务 :app:checkDebugAarMetadata 在运行 react-native run-android 时失败

任务:app:processDebugMainManifest FAILED