当前位置: 首页 > 知识库问答 >
问题:

如何解决用React-Native构建APK时执行aapt失败的错误?

孔和畅
2023-03-14

我已经构建了一个React原生应用程序。它在android模拟器上运行良好,现在我想生成一个APK。我已经按照文档进行了这方面的操作,在这里可以看到我使用了命令

./gradlew汇编

apply plugin: "com.android.application"

import com.android.build.OutputFile

/**  * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets  * and bundleReleaseJsAndAssets).  * These basically call `react-native bundle` with the correct arguments during the Android build  * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the  * bundle directly from the development server. Below you can see all the possible configurations  * and their defaults. If you decide to add a configuration block, make sure to add it before the  * `apply from: "../../node_modules/react-native/react.gradle"` line.  *  * project.ext.react = [  *   // the name of the generated asset file containing your JS bundle  *   bundleAssetName: "index.android.bundle",  *  *   // the entry file for bundle generation  *   entryFile: "index.android.js",  *  *   // whether to bundle JS and assets in debug mode  *   bundleInDebug: false,  *  *   // whether to bundle JS and assets in release mode  *   bundleInRelease: true,  *  *   // whether to bundle JS and assets in another build variant (if configured).  *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
*   // The configuration property can be in the following formats  *   //         'bundleIn${productFlavor}${buildType}'  *   //         'bundleIn${buildType}'  *   // bundleInFreeDebug: true,  *   // bundleInPaidRelease: true,  *   // bundleInBeta: true,  *  *   // whether to disable dev mode in custom build variants (by default only disabled in release)  *   // for example: to disable dev mode in the staging build type (if configured)  *   devDisabledInStaging: true,  * // The configuration property can be in the following formats  *   //  'devDisabledIn${productFlavor}${buildType}'  *   //         'devDisabledIn${buildType}'  *  *   // the root of your project, i.e. where "package.json" lives  *   root: "../../",  *  *   // where to put the JS bundle asset in debug mode  *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",  *  *   // where to put the JS bundle asset in release mode  *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",  *  *   // where to put drawable resources / React Native assets, e.g. the ones you use via  * // require('./image.png')), in debug mode  *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",  *  *   // where to put drawable resources / React Native assets, e.g. the ones you use via  * // require('./image.png')), in release mode  *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",  *  *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means  *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to  *   // date; if you have any other folders that you want to ignore for performance reasons (gradle 
*   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/  *   // for example, you might want to remove it from here.  *   inputExcludes: ["android/**", "ios/**"],  * 
*   // override which node gets called and with what additional arguments  *   nodeExecutableAndArgs: ["node"],  *  *   // supply additional arguments to the packager  *   extraPackagerArgs: []  * ] 
*/

project.ext.react = [
    entryFile: "index.js" ]

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

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    defaultConfig {
        applicationId "com.project"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 2
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        release {
            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:
        // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
        def versionCodes = ["armeabi-v7a": 1, "x86": 2]
        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
        }
    }
    }
    productFlavors {
    } }

dependencies {
    compile project(':react-native-vector-icons')
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.facebook.react:react-native:+'
    // From node_modules
    implementation project(':react-native-maps')
    implementation(project(':react-native-maps')) {
        exclude group: 'com.google.android.gms', module: 'play-services-base'
        exclude group: 'com.google.android.gms', module: 'play-services-maps'
    }
    implementation 'com.google.android.gms:play-services-base:10.2.4'
    implementation 'com.google.android.gms:play-services-maps:10.2.4' }

// 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' }

在我的全局gradle.properties文件中,我还更新了react-native到编写本文时的最新版本55.3,但我仍然得到如下所示的错误。

失败:生成失败,出现异常。

>

  • 错误:任务“:app:ProcessReleaseResources”执行失败。

    无法执行aapt

  • 共有1个答案

    佘缪文
    2023-03-14

    我和你有同样的问题。我将gradle.properties文件中的android.enableaapt2=false更改为android.enableaapt2=true。我希望这对你也管用。

     类似资料:
    • 当我尝试使用./gradlew bundleRelise构建apk文件时,我遇到了这个错误 失败:构建失败,但有一个异常。 问题所在:任务“:app:bundleReleaseResources”的执行失败。 执行 com.android.build.gradle.internal.tasks.Workers$ActionFacade Android 资源链接失败 C:\Users\Yoan\Re

    • 当我试图在ios模拟器上运行应用程序时,我得到了这个。有谁能告诉我这个问题的原因/解决办法是什么。 以下构建命令失败:CompileC/users/xxx/library/developer/xcode/deriveddata/eattog-dfbqbeyhmbgzhfcodvhcaqjxepf/build/intermediates.noindex/p s.llvm.clang.1_0.comp

    • 错误,无法安装应用程序。确保您已经设置了Android开发环境:https://reactnative.dev/docs/environment-setup。运行带有--verbose标志的CLI以获得更多详细信息。错误:命令失败:./gradlew app:installdebug-preactnativedevserverport=8081 失败:生成失败,出现异常。 在6s中生成失败 MY

    • 错误:评估脚本时出现问题。无法确定当前字符,它不是字符串、数字、数组或对象 当前读取的字符是'D',其int值为68无法确定当前字符,它不是字符串、数字、数组或对象行号1索引号0,正如我提到的,它是一个新的项目。你知道怎么解决这个问题吗?

    • 我是一名Web开发人员,我第一次构建React Native应用程序。在我添加对推送通知的FCM支持之前,该应用程序一直在工作和编译。 我遵循React Native FCM的所有说明,使用CocoaPods。 现在,by内置xCode失败,出现以下错误: 我的AppDelegate文件如下所示: 我的PodFile是这样的: 有人遇到过这样的问题吗?我甚至无法理解是什么导致了它(因为错误消息不是

    • 我有一个第三方依赖项(react-native-admob),在它的build.gradle文件中指定了以下内容:com.google.android.gms:play-services-ads:+。看看谷歌Android API发布说明页面,2019年6月17日,整个com.Google.Android.gms API组都有突破性的更新。 我运行“./Gradlew AssembleDebug”