在本地生成apk

时间:2018-10-17 18:22:02

标签: react-native gradle build.gradle

我正在尝试生成我的第一个.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文件中。错误:解析叠加失败。

     

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

     
      
  • 出了什么问题:任务':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文件所在的位置),我是否需要指定一些它们在我的资产中的位置

1 个答案:

答案 0 :(得分:0)

这是一个相当普遍的问题。在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(...