gradlew assembleRelease 不适用于 react-native-camera

Posted

技术标签:

【中文标题】gradlew assembleRelease 不适用于 react-native-camera【英文标题】:gradlew assembleRelease doesn't work with react-native-camera 【发布时间】:2020-08-04 09:36:58 【问题描述】:

我无法构建应用程序的发布版本。当我写.\gradlew assembleRelease 时,我收到此错误Execution failed for task ':react-native-camera:compileGeneralReleaseJavaWithJavac'。我的app/build.gradle 文件:

apply plugin: "com.android.application"
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

import com.android.build.OutputFile

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

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

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

def jscFlavor = 'org.webkit:android-jsc:+'

def enableHermes = project.ext.react.get("enableHermes", false);

android 
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions 
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    

    defaultConfig 
        applicationId "com.ms.showcase"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 200
        versionName "2.0.0"
        multiDexEnabled true
        missingDimensionStrategy "react-native-camera", "general"
    
    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://facebook.github.io/react-native/docs/signed-apk-android.
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        
    
    // 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
            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 =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            

        
    


dependencies 
    // This should be here already

    // Firebase dependencies
    implementation "com.google.android.gms:play-services-base:16.1.0"
    implementation "com.google.firebase:firebase-core:16.0.9"
    implementation "com.google.firebase:firebase-messaging:19.0.0"
    implementation 'me.leolin:ShortcutBadger:1.1.21@aar'

    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'

    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)
apply plugin: 'com.google.gms.google-services'

我尝试在 Google 中搜索,但一无所获。我的 RN 版本 0.61。我知道这可能是 AndroidX 的问题,降级到 RN 0.59 会有所帮助,但我认为这不是一个好主意。

我该如何解决这个问题?

【问题讨论】:

【参考方案1】:

你必须更换你的 .\gradlew assembleRelease 经过 ./gradlew assembleRelease

【讨论】:

反斜杠是 Windows 的目录分隔符。我认为这不能解决问题中给出的错误。【参考方案2】:

问题解决了。 npx jetify 帮忙。

【讨论】:

以上是关于gradlew assembleRelease 不适用于 react-native-camera的主要内容,如果未能解决你的问题,请参考以下文章

react-native android中的gradlew assembleRelease命令未生成app-release.apk

React Native for Android - 使用 ./gradlew assembleRelease 会产生“Cannot find module 'babel-preset-react-a

Android Gradle 指定 Module 打包

在詹金斯的任务gradle中找不到汇编版本

密钥库密码不正确/Gradle 任务 assembleRelease 失败,退出代码为 1

assemble 与 assembleDebug 与 assembleRelease 之间的区别