Issues with resources generated by react in Android Studio 3

5.3k views Asked by At

I recently upgraded to Android Studio 3

gradle plugin: 3.0.0-beta2
gradle: 4.1

In our project we use: "react-native": "0.46.4" with the codepush plugin.

Building:

gradlew assembleStagingDebug

works just fine, but as soon as I try to build production:

gradlew assembleProductionRelease

I get an error caused by resources that are created by react in the processProductinoReleaseResources task:

Issues:
 - ERROR: /Users/user/react/android/app/build/intermediates/res/merged/production/release/drawable-hdpi/node_modules_reactnavigation_src_views_assets_backicon.png uncompiled PNG file passed as argument. Must be compiled first into .flat file.
 - ERROR:  failed parsing overlays
        at com.android.builder.internal.aapt.v2.AaptV2Jni.buildException(AaptV2Jni.java:154)

In my conquest against this issue I tried it with disabling proguard like:

buildTypes {
        release {
            debuggable true
            minifyEnabled false
            shrinkResources false
        }
        debug {
            debuggable true
            minifyEnabled false
            println proguardFiles
        }
    }

But without any luck.

Any ideas? I would also appreciate an explanation of where this .flat conversion of the android resources happens what it actually does and why it does not happen during the StagingDebug task.

The workaround presented here worked for me in the end. But the original issue persists i think.

update 28.3.2018 Since Android studio 3.1 upgrade I get this:

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

Since the issues on the react page are closed, I am looking for alternatives before they deprecate that workaround.

4

There are 4 answers

0
Vipul On

I faced a similar issue in my app. It is resolved by Go to "Android" directory and run

gradlew clean
6
user7532779 On

In your gradle.properties file add following lines:

classpath 'com.android.tools.build:gradle:3.0.0'
distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip
android.enableAapt2=false
0
azwar_akbar On

In my case, I had to replace compile with implementation

Modify app/build.gradle to be:

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:23.0.1"
    implementation "com.facebook.react:react-native:+"  // From node_modules
}
1
user1791914 On

In my case adding android.enableAapt2=false to gradle.properties was enough to fix this.

[UPDATE] This is indeed depreciated. So you might want to try another solution.