facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.37k stars 24.25k forks source link

[Android] Requiring images with Gradle 4 fails release builds #16906

Closed Almouro closed 6 years ago

Almouro commented 6 years ago

Hello guys,

I ran into this issue when updating Gradle and Android Studio.

Thanks for your help!

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment: OS: macOS Sierra 10.12.6 Node: 8.5.0 Yarn: 1.3.2 npm: 5.3.0 Watchman: 4.7.0 Xcode: Xcode 9.1 Build version 9B55 Android Studio: 3.0 AI-171.4408382

Packages: (wanted => installed) react: 16.0.0 => 16.0.0 react-native: 0.50.3 => 0.50.3

Target Platform: Android (22)

Steps to Reproduce

Requiring images with latest gradle fails release builds

I created a small test project but here are the steps to reproduce it:

  1. Init a new project: react-native init Test
  2. Update to latest Gradle:
    • Open Android Studio and install recommended version
    • Build from Android Studio, it should ask you to update build tools, do so
  3. Require an image in index.js
  4. Run cd android && ./gradlew assembleRelease

Expected Behavior

The command ./gradlew assembleRelease should not fail

Actual Behavior

Running ./gradlew assembleRelease when the image is required from the JS fails with:

/Users/almouro/bam/uefa/TestGradle3/android/app/build/intermediates/res/merged/release/drawable-mdpi/image.png: error: uncompiled PNG file passed as argument. Must be compiled first into .flat file..
error: failed parsing overlays.

If the image is not required, the command works fine.

Reproducible Demo

git clone https://github.com/Almouro/react-native-with-gradle-4
yarn
cd android
./gradlew assembleRelease

Workaround

Adding android.enableAapt2=false to android/gradle.properties fixes the issue but it is only a workaround.

macs03 commented 6 years ago

I have the same issue

strawferry commented 6 years ago

+1 😂

vladp commented 6 years ago

+1 have same issue with react-native 0.50 setting android.enableAapt2=false to android/gradle.properties
helps with this issue. However, I am running into a next problem (and not sure if this due to the above setting).

  Task :app:bundleReleaseJsAndAssets
 Scanning folders for symlinks in /home/v/devel/mine/proj/mob/rn.common/node_modules (12ms)
 Scanning folders for symlinks in /home/v/devel/mine/proj/mob/rn.common/node_modules (10ms)
 Loading dependency graph, done.
 warning: the transform cache was reset.
 bundle: start
 bundle: finish
 bundle: Writing bundle output to: /home/v/tmp/u1b/app/intermediates/assets/release/index.android.bundle
 bundle: Done writing bundle output
 bundle: Copying 18 asset files
 bundle: Done copying assets

/home/v/tmp/u1b/app/intermediates/res/merged/release/drawable-mdpi/src_jsapp_img_material_ic_local_library_black_48dp_android_drawablexxhdpi_ic_local_library_black_48dp.png: error: Invalid filename.  Unable to add.

The file

/home/v/tmp/u1b/app/intermediates/res/merged/release/drawable-mdpi/src_jsapp_img_material_ic_local_library_black_48dp_android_drawablexxhdpi_ic_local_library_black_48dp.png

indeed, is not present in the merged/release directory. But I have no idea who generates that file name for what reason/etc.

Almouro commented 6 years ago

My understanding is that the React Native bundleJS gradle task copies all the images in the android merged resources folder, but aapt now expects images there to be compiled in .flat files.

vladp commented 6 years ago

@Almouro I sorted out the issue with src_jsapp_img_material_ic_local_library_black_48dp_android_drawablexxhdpi_ic_local_library_black_48dp.png

it turns out that something in aapt (or somewhere in gradle) chokes on image file names that are located in deep directory structures.
The above name was created by concatenating (with '_') the directory tree where local_library_black_48dp.png was. I basically moved the file into a simpler directory structure, then updated my require ('path_to_image/..) in my index.android.js and that particular problem went away

the need to do the android.enableAapt2=false workaround is still there, unfortunately

wmonecke commented 6 years ago

Same error:

Scanning 766 folders for symlinks in /Users/waltermonecke/Code_Projects/reactNative/lisdo/node_modules (15ms)
Scanning 766 folders for symlinks in /Users/waltermonecke/Code_Projects/reactNative/lisdo/node_modules (100ms)
Loading dependency graph, done.
warning: the transform cache was reset.
bundle: start
bundle: finish
bundle: Writing bundle output to: /Users/waltermonecke/Code_Projects/reactNative/lisdo/android/app/build/intermediates/assets/release/index.android.bundle
bundle: Done writing bundle output
bundle: Copying 106 asset files
bundle: Done copying assets

/Users/waltermonecke/Code_Projects/reactNative/lisdo/android/app/build/intermediates/res/merged/release/drawable-hdpi/node_modules_reactnativerouterflux_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.

node_modules: "react": "16.0.0-alpha.12", "react-native": "0.48.3",

Has anyone had any success fixing this? I can't test the production app because of this.

otoinsa commented 6 years ago

I have the same issue; also happens on production builds. :(

dioxide commented 6 years ago

I have the same issue

praburaja commented 6 years ago

I have the same issue

wuyunqiang commented 6 years ago

I have the same issue. I Adding android.enableAapt2=false to android/gradle.properties but no effect.

SharpMobileCode commented 6 years ago

This bug has been a pain since we've upgraded to Android 3.x and setting android.enableAapt2 = false is not a sustainable long term workaround. It's disappointing that there is no traction on this serious issue.

nklhtv commented 6 years ago

I have the same issue

allison7 commented 6 years ago

Can't use android.enableAapt2=false since then other necessary components fail. A bad situation to find this near the end of a project.

hugoh59 commented 6 years ago

Same getting similar issue.

xzilja commented 6 years ago

android.enableAapt2=false works (when there are no images in drawable)

andreiciceu commented 6 years ago

Getting the same issue :(

heuism commented 6 years ago

Sorry to ask again, but is there a way to deal with this issue? If I do Debug it would be okay, but choose Release Mode and this happens. Thanks

PPTing commented 6 years ago

+1

sibelius commented 6 years ago

any idea of how to fix this?

Alexispap commented 6 years ago
  1. Delete the tmp files of the images that were created during the build process. (in tmp\YOURAPP\app\intermediates\res\merged\release\drawable....). The exact path is given by the compiler error.
  2. Search for files that have a @-suffix different from @2x or @3x in your app folder and delete them. See https://facebook.github.io/react-native/docs/images.html
  3. Sometimes the issue stems from images of a module you use. Search for the images with wrong suffix in the respective node_modules folder and delete them.
  4. DON'T USE the common workaround (which consists in disabling aapt2).
CFKevinRef commented 6 years ago

tl;dr - I think the bundling step in react.gradle should hand off to the Android build system much earlier in the build process

I may have killed a few birds with one stone while working out a solution for something unrelated.

I wanted to bundle the js ahead of time, then build multiple variants using that same bundle. The solution I came up with also allows you to keep AAPT2 enabled, which was a major plus.

First I set a few environment variables, REACT_NATIVE_JS_DIR and REACT_NATIVE_ASSETS_DIR.

Then I bundle with --bundle-output "$REACT_NATIVE_JS_DIR/index.android.bundle" --assets-dest "$REACT_NATIVE_ASSETS_DIR".

The build.gradle adds those to the main source set:

// not needed anymore in this setup:
// apply from: "../../node_modules/react-native/react.gradle"
android {
    ...
    sourceSets {
        // Android includes "main" in all application variants
        main {
            assets.srcDirs += System.env.REACT_NATIVE_JS_DIR
            res.srcDirs += System.env.REACT_NATIVE_ASSETS_DIR
        }
    }
}

Overall this feels a lot friendlier to the Android build system, as the resources and assets actually go through the merge${VariantName}Assets and merge${VariantName}Resources tasks. As a bonus, my universal APK was even 4% smaller.

I have a feeling that react.gradle could be modified to do something similar, like:

I'll try to find some time to put a PR together if that sounds reasonable.

jeaye commented 6 years ago

@CFKevinRef I've verified your approach works, as long as REACT_NATIVE_ASSETS_DIR isn't actually pointing to ./android/app/build/intermediates/res/merged/$build_type. This did it for me:

android_intermediates=$(mktemp -d)
export REACT_NATIVE_JS_DIR=$android_intermediates/assets/$build_type_lower
export REACT_NATIVE_ASSETS_DIR=$android_intermediates/res/merged/$build_type_lower

It's not a great long-term solution, though, since avoiding the default gradle support may cause issues down the road, when new behavior is added, or something is changed. For now, it does allow things to work with AAPT2. Thank you!

It'd be great to see that PR and have this ball rolling.

samehmikhail commented 6 years ago

Until this got fixed, there is another workaround similar to solution proposed by @CFKevinRef. This solution also allows you to keep using AAPT2. Workaround consists of three steps

CFKevinRef commented 6 years ago

Please give https://github.com/facebook/react-native/pull/17967 a try. You should be able to just replace your react.gradle with that one.

Also if you have some old projects lying around based on the Android Gradle Plugin 1.x or 2.x I would appreciate a test as well!

iqbalshirol commented 6 years ago

I had the same issue. But did not fix with - android.enableAapt2=false, as this has issues with other drawable resources in the project.

Fixed it with adding org.gradle.configureondemand=true in build.gradle, which shall disable the 'bundleReleaseJsAndAssets' task to run, which is the best solution and works in any condition. Hope this helps.

andreiciceu commented 6 years ago

@facebook-github-bot reopen By using that commit, i get lots of duplicate assets error, like this:

[drawable-xhdpi-v4/app_assets_icons_lock] /Users/XXX/android/app/src/main/res/drawable-xhdpi/app_assets_icons_lock.png
[drawable-xhdpi-v4/app_assets_icons_lock] /Users/XXX/android/app/build/generated/res/react/release/drawable-xhdpi/app_assets_icons_lock.png
: Error: Duplicate resources

LE, even after deleting duplicate assets from drawable-*, build still fails, with all node-modules depenencies failing like: (after clearing cache, ./gradlew clean, npm install, update react.gradle)

Could not resolve project :react-native-sqlite-storage.
 Required by:
         project :app
      > Unable to find a matching configuration of project :react-native-sqlite-storage:
          - Configuration 'debugApiElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'dev' and found incompatible value 'debug'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'java-runtime' and found incompatible value 'java-api'.
          - Configuration 'debugRuntimeElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'dev' and found incompatible value 'debug'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'java-runtime' and found compatible value 'java-runtime'.
          - Configuration 'releaseApiElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'dev' and found incompatible value 'release'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'java-runtime' and found incompatible value 'java-api'.
          - Configuration 'releaseRuntimeElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'dev' and found incompatible value 'release'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'java-runtime' and found compatible value 'java-runtime'.

As for now, I ended up reverting to Android Studio 2.3.3, as it's the latest version which can build the release

akrumel commented 6 years ago

@CFKevinRef I am getting the following error from the proposed react.gradle file:

Received result Failure[value=org.gradle.initialization.ReportedException: org.gradle.internal.exceptions.LocationAwareException: Circular dependency between the following tasks:
:app:bundleProductionReleaseJsAndAssets
\--- :app:recordFilesBeforeBundleCommandProductionRelease
     \--- :app:mergeProductionReleaseResources
          \--- :app:bundleProductionReleaseJsAndAssets (*)
CFKevinRef commented 6 years ago

Ah ha, this is because CodePush has to do some fairly intricate tracking to generate a hash of "every file created by the react-native bundle task." Their current technique will no longer work as-is.

The good news is that it should be much easier now, as I've exposed the bundle task itself on the application variant, as well the generated lists of files:

android.applicationVariants.all { variant ->
    // This is the generated task itself:
    def reactBundleTask = variant.bundleJsAndAssets
    // These are the outputs by type:
    def resFileCollection = reactBundleTask.generatedResFolders
    def assetsFileCollection = reactBundleTask.generatedAssetsFolders
}

It's possible to test for this new behavior by checking for the bundleJsAndAssets property on application variants.

In any case, as this is merged now, that is probably an issue to fix over at https://github.com/Microsoft/react-native-code-push/

akrumel commented 6 years ago

@CFKevinRef Thanks for the feedback and the great work. For those also seeing this thread, I reverted to Android Studio 2.3.3 to wait for this to settle out, which was pretty painless. I will ensure a bug is exists with codepush and reference the appropriate RN issue(s).

hikuley commented 6 years ago

Hello guys, I have the same issue and so is there a solution for that problem.

ThomWright commented 6 years ago

@hramos could we reopen this? As far as I can tell no fix has been made - a PR was merged then reverted so this is still a problem.

Xing-He commented 6 years ago

I tried the following steps to solve this issue:

yairopro commented 6 years ago

@Xing-He I don't know anything about gradle. But using your solution create another error which is duplicate files error. And using the stackoverflow solution (see link) create another error :

To run dex in process, the Gradle daemon needs a larger heap. It currently has 1024 MB.

Ô.Ô

And about the @CFKevinRef solution, what are the values to set for REACT_NATIVE_JS_DIR and REACT_NATIVE_ASSETS_DIR?

Any news about this error?

MarkOSullivan94 commented 6 years ago

Also getting this error when trying to package up the bundle for a React Native component within an Android project.

Edit: Discovered my config was wrong for packaging up the bundle.

xzilja commented 6 years ago

For anyone experiencing dex related errors try this inside of your android/app/build.gradle

android {
    ...
    dexOptions {
        jumboMode true
    }
}

Related: https://developers.soundcloud.com/blog/congratulations-you-have-a-lot-of-code-remedying-androids-method-limit-part-1

ujwal-setlur commented 6 years ago

@CFKevinRef your PR #17967 worked for me with gradle-4.6 and gradle plugin 3.0.1. This was critical for me since I use react-native-maps which demands an upgraded gradle. I think react-native needs to upgrade its gradle, but I don't know what the impact of third party libraries is.

Thank you very much for this. One question: How should we keep the private version of react.gradle up to date as new versions of react-native are released?

MarkOSullivan94 commented 6 years ago

This was critical for me since I use react-native-maps which demands an upgraded gradle. I think react-native needs to upgrade its gradle, but I don't know what the impact of third party libraries is.

I'm not sure if React Native needs to upgrade its gradle version, React Native Maps did because it was causing build issues within Android Studio 3.0+ whenever I was using it, so I put in a PR to update it.

The reason why RN-Maps was throwing an issue during build is because React Native Maps is added as a Java module which produces a build.gradle file for the module in your project and so AS checks the gradle file for it. Before I added the PR, it kept throwing issues which was always fixed whenever I updated the gradle keywords within the RN-Maps project.

dahudson88 commented 6 years ago

Thanks @IljaDaderko I was having a dex exception but adding that fixed it!!! Only spent 3 hours pulling out my hair :)

CFKevinRef commented 6 years ago

@ujwal-setlur I need to see if I can fix the PR to work with a build-from-source of React Native.

ujwal-setlur commented 6 years ago

Sounds good. Happy to test it when ready.

JCMais commented 6 years ago

Just found that issue. Having the same problem, only disable aapt2 fixed it.

Looking forward to see if you can get it working @CFKevinRef

denisk20 commented 6 years ago

With the workaround applied (android.enableAapt2=false) not only will android gradle build spit countless warnings

Use 'android.enableAapt2=true' to remove this warning.
It will be removed at the end of 2018..

but also my project won't build in Android Studio 3.1+ (it will still build from the terminal).

> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: Failed to execute aapt

* Try:
Run with --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':UI:transformDexWithInstantRunDependenciesApkForDebug'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:103)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:73)
    at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
    at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:256)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:249)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:238)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:663)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:597)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: Failed to execute aapt
    at com.android.builder.profile.Recorder$Block.handleException(Recorder.java:55)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:104)
    at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:212)
    at sun.reflect.GeneratedMethodAccessor302.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:124)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:113)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:95)
    ... 33 more
Caused by: com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: Failed to execute aapt
    at com.android.build.gradle.internal.transforms.InstantRunDependenciesApkBuilder.transform(InstantRunDependenciesApkBuilder.java:152)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:221)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:217)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
    ... 48 more
Caused by: com.android.ide.common.process.ProcessException: Failed to execute aapt
    at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:809)
    at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:797)
    at com.android.build.gradle.internal.transforms.InstantRunSplitApkBuilder.generateSplitApkResourcesAp(InstantRunSplitApkBuilder.java:375)
    at com.android.build.gradle.internal.transforms.InstantRunSplitApkBuilder.generateSplitApkResourcesAp(InstantRunSplitApkBuilder.java:323)
    at com.android.build.gradle.internal.transforms.InstantRunSplitApkBuilder.generateSplitApk(InstantRunSplitApkBuilder.java:211)
    at com.android.build.gradle.internal.transforms.InstantRunDependenciesApkBuilder.transform(InstantRunDependenciesApkBuilder.java:149)
    ... 51 more
Caused by: java.util.NoSuchElementException
    at com.google.common.collect.AbstractIndexedListIterator.next(AbstractIndexedListIterator.java:80)
    at com.google.common.collect.Iterators.getOnlyElement(Iterators.java:315)
    at com.google.common.collect.Iterables.getOnlyElement(Iterables.java:263)
    at com.android.builder.internal.aapt.v1.AaptV1.makePackageProcessBuilder(AaptV1.java:202)
    at com.android.builder.internal.aapt.AbstractProcessExecutionAapt.makeValidatedPackage(AbstractProcessExecutionAapt.java:67)
    at com.android.builder.internal.aapt.AbstractAapt.link(AbstractAapt.java:34)
    at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:807)
    ... 56 more

Removing android.enableAapt2=false fixes this but then it hits the current bug...

jhzzzz commented 6 years ago

i managed to solve this problem by change gradle version from 3.1.1 to 3.0.1

SirPhemmiey commented 6 years ago

Any fix for this please?

ujwal-setlur commented 6 years ago

@sirphemmiey, you can try the PR from @CFKevinRef. It worked for me

nkov commented 6 years ago

The best fix for me was to temporarily revert to gradle 2.3.3 as suggested by @akrumel

classpath 'com.android.tools.build:gradle:2.3.3'
xwartz commented 6 years ago

+1, I have the same issue

AdriaRios commented 6 years ago

+1, the same issue

judemanutd commented 6 years ago

Using the following configuration and everything works fine

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "in.example"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
}

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

project level build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.1'
        classpath 'com.google.gms:google-services:3.2.1'
    }
}

In order to use gradle 4.4 you will need to modify your gradle.properties file to look like this

#Fri Mar 02 12:52:38 IST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
JCMais commented 6 years ago

@judemanutd even the release build works?