16

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.

Mike T
  • 1,154
  • 13
  • 24

4 Answers4

17

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
user7532779
  • 213
  • 2
  • 7
  • Yes that what worked for me too, but I still think there is a bug in react and it should work without this property flag. – Mike T Oct 30 '17 at 13:30
  • The only thing this does for me is change the error into `Original is here. The version qualifier may be implied.` – Kevin Østerkilde Oct 30 '17 at 16:55
  • @Kevin Østerkilde Did you also have following in your project's build.gradle dependencies { classpath 'com.android.tools.build:gradle:3.0.0' } – user7532779 Oct 30 '17 at 19:04
  • @user7532779 I did, yes. Actually I managed to solve my issue earlier today and I'm not sure if it's even related. I deleted any folders in `android/app/src/main/res` that started with `drawable`, as well as deleted `android/app/src/main/assets/index.bundle`. After that, running `./gradlew assembleRelease` just worked. (Still with the fixes mentioned here applied.) – Kevin Østerkilde Oct 31 '17 at 19:13
  • 2
    Hmmm it works but I don't know why :P I just added `android.enableAapt2=false` and in started working ... my `gradle.properties` file already has `android.useDeprecatedNdk=true` and `RELEASE_STORE_FILE` info. – Michael Stokes Nov 13 '17 at 17:49
  • `enableAapt2` is deprecated – Julian K Dec 14 '19 at 04:04
3

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.

user1791914
  • 576
  • 5
  • 20
  • 1
    That is true, but it seems this workaround will come to an end because since Android Studio 3.1 it is deprecated. – Mike T Mar 29 '18 at 16:05
0

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
}
Gianfranco P.
  • 6,858
  • 3
  • 40
  • 56
azwar_akbar
  • 956
  • 10
  • 25
0

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

gradlew clean
Vipul
  • 686
  • 5
  • 13