android - 未编译的 PNG 文件作为参数传递。必须先编译成 .flat 文件

标签 android react-native react-navigation

当我将 React Navigation 添加到项目并同步它时 但是有一个错误

android\app\build\intermediates\res\merged\release\drawable-hdpi\node_modules_reactnavigation_src_views_assets_backicon.png:

error: uncompiled PNG file passed as argument.

Must be compiled first into .flat file.. error: failed parsing overlays.

然后我搜索并得出结论

You may also run into uncompiled PNG file passed as argument. Must be compiled first into a .flat file.. error: failed parsing overlays. There is a workaround now.

Add android.enableAapt2=false to android/gradle.properties.

但是有一个错误

WARNING: The option 'android.enableAapt2' is deprecated and should not be used anymore.
Use 'android.enableAapt2=true' to remove this warning.
It will be removed at the end of 2018..

我还是错了

文件 app/build.gradle

apply plugin: "com.android.application"

import com.android.build.OutputFile

   

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 = true

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

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "com.ir.babahassan.shop"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
    }
    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"
            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:
            // 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
            }
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:27.1.0"
    implementation "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-location:11.6.0' // disable if you don't want to use enableHighAccuracy: true in geolocation
    implementation 'com.google.android.gms:play-services-base:11.6.0'
    implementation 'com.google.android.gms:play-services-maps:11.6.0'
    implementation project(':react-native-android-open-settings')
}

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

rootProject.name = 'ir.babahassan.shop'
include ':react-native-maps'
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/lib/android')

include ':react-native-android-open-settings'
project(':react-native-android-open-settings').projectDir = new File(settingsDir, '../node_modules/react-native-android-open-settings/android')

include ':app'

文件 gradle.properties

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

#android.useDeprecatedNdk=true
MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=*********
MYAPP_RELEASE_STORE_PASSWORD=*********
MYAPP_RELEASE_KEY_PASSWORD=*********
android.enableAapt2=false

使用来自 this linkReact Navigation

最佳答案

对于任何卡住的人。请勿在 android/gradle.properties 中使用 android.enableAapt2=false 进行临时修复。检查这个 answer

关于android - 未编译的 PNG 文件作为参数传递。必须先编译成 .flat 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51607255/

相关文章:

android - 如何在 Android 中循环遍历 SpannedString 或 SpannableString 中的 Spanned

android - 如何在电话结束后恢复我的 Android 游戏的原生 Activity (GLES 层)?

react-native - 在 IOS 和 Android 上使用 Flutter/React Native 播放 DRM 内容

android - 我可以仅在 Ubuntu 上开始使用 android SDK 和 AVD 进行 native 开发吗?

react-native - 我们如何将 react-navigation 标题的标题居中?

android - Android 中的 ListView 适配器问题

java - 如何从蓝牙设备检索数据?

javascript - react-native 中的后台服务

javascript - 在 UIManager 中找不到 RNCSafeAreaView

react-native - react native navigationOptions调用函数错误