Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues with resources generated by react in Android Studio 3

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.

like image 600
Mike T Avatar asked Aug 30 '17 07:08

Mike T


2 Answers

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
like image 158
user7532779 Avatar answered Nov 18 '22 19:11

user7532779


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.

like image 3
user1791914 Avatar answered Nov 18 '22 18:11

user1791914