【问题标题】:generating apk in react-native在 react-native 中生成 apk
【发布时间】:2018-10-17 18:22:02
【问题描述】:

我正在尝试生成我的第一个 .apk 并在过去几天遇到错误。 我在堆栈溢出和 github 上搜索 ans,但没有任何帮助。
通过指令 here我能够构建调试版本,但是当运行 gradlew assembleRelease 时出现错误

E:\p1\placementScript\android\app\build\intermediates\res\merged\release\drawable-hdpi\node_modules_reactnavigationstack_dist_views_assets_backicon.png: 错误:未编译的 PNG 文件作为参数传递。必须先编译 进入 .flat 文件.. 错误:解析覆盖失败。

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

  • 出了什么问题:任务 ':app:processReleaseResources' 执行失败。 无法处理资源,请参阅上面的 aapt 输出了解详情。

package.json

 {
   ....
  "dependencies": {
    "babel-preset-es2015": "^6.24.1",
    "react": "^16.4.1",
    "react-native": "^0.55.4",
    "react-native-fcm": "^16.2.3",
    "react-native-firebase": "^5.0.0",
    "react-native-push-notification": "^3.1.1",
    "react-native-view-shot": "^2.4.0",
    "react-navigation": "^2.12.1"
  }

   ....
}

和android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "26.0.3"
        minSdkVersion = 16
        compileSdkVersion = 26
        targetSdkVersion = 26
        supportLibVersion = "26.1.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
                classpath 'com.google.gms:google-services:4.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}


task wrapper(type: Wrapper) {
    gradleVersion = '4.4'
    distributionUrl = distributionUrl.replace("bin", "all")
}

和android/app/build.gradle

...
defaultConfig {
 ...
        }
          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
                }
            }
        }
        splits {
        ...

您希望我上传的任何其他文件请询问。

PS:- 我的 src 文件夹中有很多 .png 文件(所有 .js/etc 文件都在其中),我是否需要指定一些它们是我的资产的位置

【问题讨论】:

    标签: react-native gradle build.gradle


    【解决方案1】:

    这是一个相当普遍的问题。查看 RN 问题中的此线程以及可能的解决方案:

    https://github.com/facebook/react-native/issues/19211

    对我有用的解决方案是

    将以下代码添加到文件 node_modules/react-native/react.gradle :

    doLast {
        def moveFunc = { resSuffix ->
            File originalDir = file("${resourcesDir}/drawable-${resSuffix}")
            if (originalDir.exists()) {
                File destDir = file("${resourcesDir}/drawable-${resSuffix}-v4")
                ant.move(file: originalDir, tofile: destDir)
            }
        }
        moveFunc.curry("ldpi").call()
        moveFunc.curry("mdpi").call()
        moveFunc.curry("hdpi").call()
        moveFunc.curry("xhdpi").call()
        moveFunc.curry("xxhdpi").call()
        moveFunc.curry("xxxhdpi").call()
    }
    

    在def currentBundleTask = tasks.create(...内

    【讨论】:

    • @RajanLagah,你有没有试过在重建之前清理你的构建?
    • 你的意思是gradlew clean 吗?
    • @Ariel_Salem 我的 src 文件夹中有很多 .png 文件(所有 .js/etc 文件都在其中),我是否需要指定一些它们是我的资产的位置
    • 是的,您是否运行过gradlew clean?我会在问题线程中尝试一些解决方案,看看有什么效果
    猜你喜欢
    • 2018-02-27
    • 2021-02-08
    • 2018-03-21
    • 1970-01-01
    • 2020-08-18
    • 1970-01-01
    • 2019-02-22
    • 1970-01-01
    • 2019-07-01
    相关资源
    最近更新 更多