Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gradlew assembleRelease failing at processReleaseResources [0.19] #5787

Closed
haydenth opened this issue Feb 6, 2016 · 51 comments
Closed

gradlew assembleRelease failing at processReleaseResources [0.19] #5787

haydenth opened this issue Feb 6, 2016 · 51 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@haydenth
Copy link
Contributor

haydenth commented Feb 6, 2016

Just running a stock

./gradlew assembleRelease --stacktrace

Getting a failure at processReleaseResources. Not really sure what to do, this looks like it has something to do with aapt and the android packager but I don't know and some basic searches revealing nothing interesting. Any ideas? Is there just some android package I failed to install?

bundle: Done copying assets
:app:processReleaseManifest UP-TO-DATE
:app:processReleaseResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processReleaseResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/local/opt/android-sdk/build-tools/23.0.2/aapt'' finished with non-zero exit value 1

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:processReleaseResources'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:310)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
    at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:90)
    at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28)
    at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:50)
    at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:27)
    at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:40)
    at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:169)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
    at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
    at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
    at org.gradle.launcher.Main.doAction(Main.java:33)
    at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
    at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
    at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:30)
    at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:127)
    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Caused by: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/local/opt/android-sdk/build-tools/23.0.2/aapt'' finished with non-zero exit value 1
    at com.android.build.gradle.tasks.ProcessAndroidResources.doFullTaskAction(ProcessAndroidResources.java:147)
    at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:98)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:243)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:219)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:230)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:208)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
    ... 49 more
Caused by: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/local/opt/android-sdk/build-tools/23.0.2/aapt'' finished with non-zero exit value 1
    at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:42)
    at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:919)
    at com.android.build.gradle.tasks.ProcessAndroidResources.doFullTaskAction(ProcessAndroidResources.java:138)
    ... 57 more
Caused by: org.gradle.process.internal.ExecException: Process 'command '/usr/local/opt/android-sdk/build-tools/23.0.2/aapt'' finished with non-zero exit value 1
    at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:365)
    at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:40)
    ... 59 more


BUILD FAILED
@facebook-github-bot
Copy link
Contributor

Hey haydenth, thanks for reporting this issue!

React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.

  • If you don't know how to do something or something is not working as you expect but not sure it's a bug, please ask on StackOverflow with the tag react-native or for more real time interactions, ask on Discord in the #react-native channel.
  • If this is a feature request or a bug that you would like to be fixed, please report it on Product Pains. It has a ranking feature that lets us focus on the most important issues the community is experiencing.
  • We welcome clear issues and PRs that are ready for in-depth discussion. Please provide screenshots where appropriate and always mention the version of React Native you're using. Thank you for your contributions!

@haydenth
Copy link
Contributor Author

haydenth commented Feb 7, 2016

Specifically the error is

Skipping task ':app:processReleaseManifest' as it is up-to-date (took 0.011 secs).
:app:processReleaseManifest UP-TO-DATE
:app:processReleaseManifest (Thread[main,5,main]) completed. Took 0.015 secs.
:app:processReleaseResources (Thread[main,5,main]) started.
:app:processReleaseResources
Executing task ':app:processReleaseResources' (up-to-date check took 0.046 secs) due to:
  No history is available.
All input files are considered out-of-date for incremental task ':app:processReleaseResources'.
Starting process 'command '/usr/local/opt/android-sdk/build-tools/23.0.2/aapt''. Working directory: /Users/tom/projects/blueprint-native/android/app Command: /usr/local/opt/android-sdk/build-tools/23.0.2/aapt package -f --no-crunch -I /usr/local/opt/android-sdk/platforms/android-23/android.jar -M /Users/tom/projects/blueprint-native/android/app/build/intermediates/manifests/full/release/AndroidManifest.xml -S /Users/tom/projects/blueprint-native/android/app/build/intermediates/res/merged/release -A /Users/tom/projects/blueprint-native/android/app/build/intermediates/assets/release -m -J /Users/tom/projects/blueprint-native/android/app/build/generated/source/r/release -F /Users/tom/projects/blueprint-native/android/app/build/intermediates/res/resources-release.ap_ -G /Users/tom/projects/blueprint-native/android/app/build/intermediates/proguard-rules/release/aapt_rules.txt --custom-package com.blueprintnative -0 apk --output-text-symbols /Users/tom/projects/blueprint-native/android/app/build/intermediates/symbols/release
Successfully started process 'command '/usr/local/opt/android-sdk/build-tools/23.0.2/aapt''
Unknown source file : /Users/tom/projects/blueprint-native/android/app/build/intermediates/res/merged/release/drawable-mdpi-v4/images_back.png: error: Duplicate file.

Unknown source file : /Users/tom/projects/blueprint-native/android/app/build/intermediates/res/merged/release/drawable-mdpi/images_back.png: Original is here. The version qualifier may be implied.

:app:processReleaseResources FAILED
:app:processReleaseResources (Thread[main,5,main]) completed. Took 0.257 secs.

this appears to be related to some kind of android/gradle issue
http://stackoverflow.com/questions/29965398/gradle-finished-with-non-zero-exit-value-1-ic-launcher-png-error-duplicate-fi

@haydenth
Copy link
Contributor Author

haydenth commented Feb 7, 2016

Dug more into this. Looks like the packager is generating images in both drawable-mdpi and drawable-mdpi-v4. I guess newer versions of aapt don't like this so much, even with cruncher disabled..

Unknown source file : /home/tom/projects/blueprint-native/android/app/build/intermediates/res/merged/release/drawable-mdpi-v4/images_google.png: error: Duplicate file.

Unknown source file : /home/tom/projects/blueprint-native/android/app/build/intermediates/res/merged/release/drawable-mdpi/images_google.png: Original is here. The version qualifier may be implied.

@haydenth haydenth changed the title gradlew assembleRelease failing at processReleaseResources gradlew assembleRelease failing at processReleaseResources [0.19] Feb 7, 2016
@haydenth
Copy link
Contributor Author

haydenth commented Feb 7, 2016

I was able to get around this by changing mdpi to mdpi-v4 in:
node_modules/react-native/local-cli/bundle/assetPathUtils.js

function getAndroidAssetSuffix(scale) {
  switch (scale) {
    case 0.75: return 'ldpi';
    case 1: return 'mdpi-v4';
    case 1.5: return 'hdpi';
    case 2: return 'xhdpi';
    case 3: return 'xxhdpi';
    case 4: return 'xxxhdpi';
  }
}

@bestander
Copy link
Contributor

Hi @haydenth, can't reproduce this in a new app.
Can you create a fresh example?

@AvatarQing
Copy link

AvatarQing commented May 20, 2016

I think node_modules/react-native/local-cli/bundle/assetPathUtils.js is need to update to this :

function getAndroidAssetSuffix(scale) {
  switch (scale) {
    case 0.75: return 'ldpi-v4';
    case 1: return 'mdpi-v4';
    case 1.5: return 'hdpi-v4';
    case 2: return 'xhdpi-v4';
    case 3: return 'xxhdpi-v4';
    case 4: return 'xxxhdpi-v4';
  }
}

Or let these folder name can be configured in gradle script.

Because the newest android gradle plugin force to added v4 suffix to the drawable folders by default when execute processResources task, if you do this, it will avoids potential Duplicate file error between drawable-xdpi-v4 and drawable-xdpi.

@AvatarQing
Copy link

I have customized react.gradle to solve the Duplicate file error perfectly. Add following code in to currentBundleTask's creation block

doLast {
    def moveFunc = { resSuffix ->
        File originalDir = file("${resourcesDir}/drawable-${resSuffix}")
        if (originalDir.exists()) {
            File destDir = file("${resourcesDir}/drawable-${resSuffix}-v4")
            ant.move(file: originalDir, tofile: destDir)
        }
    }
    moveFunc.curry("ldpi").call()
    moveFunc.curry("mdpi").call()
    moveFunc.curry("hdpi").call()
    moveFunc.curry("xhdpi").call()
    moveFunc.curry("xxhdpi").call()
    moveFunc.curry("xxxhdpi").call()
}

@RonakKhandelwal
Copy link

Had The same issue still not resolved.

@RonakKhandelwal
Copy link

screen shot 2016-05-27 at 2 41 22 pm

@RonakKhandelwal
Copy link

Solved by deleting the file

@PunitSaharan
Copy link

@RonakKhandelwal hi can you please help me i am getting same error "Execution failed for task ':processReleaseResources'."... thanks

@RonakKhandelwal
Copy link

@PunitSaharan can you please post the terminal output in my case the output simply said unknown source file duplicate file so I'm not sure if you have the same problem

@haydenth
Copy link
Contributor Author

haydenth commented Jul 6, 2016

Hey, sorry for delayed response. I can't replicate from a fresh install, so I'm thinking it probably has something to do with coming from an older version (my project started way back in the react-native 0.12 days). So I am guessing this bug is related to some older files existing that need to be truncated as mentioned above. Given that I went from a fresh install and don't have this problem anymore, not sure this is a bug.

@cosmith
Copy link
Contributor

cosmith commented Jul 6, 2016

I had the same issue, and changing node_modules/react-native/local-cli/bundle/assetPathUtils.js as @haydenth did solved it for me. Is there any drawbacks to this? Should we merge it in?

@Naoto-Ida
Copy link

I'm having the same issue on 0.25.1. Anyway to fix this?

@Naoto-Ida
Copy link

Naoto-Ida commented Jul 7, 2016

~/Documents/CoolApp/android/app/build/intermediates/res/merged/release/drawable-hdpi-v4/node_modules_reactnative_libraries_customcomponents_navigationexperimental_assets_backicon.png this seems to be the issue... I tried all the methods above.

This file names seems weird... is this supposed to be named like this? Seems like it should be / separated than _.

By the way I'm not using NavigationExperimental anywhere.
It comes up in the index.android.bundle when grepping.

@PimDeWitte
Copy link
Contributor

I ran it by running a "find" command in the terminal with the filename, then running rm on the matched file and it fixed it.

@sdg9
Copy link

sdg9 commented Jul 21, 2016

@Naoto-Ida I have the same issue except for mdpi. You figure anything out yet? I'll post if I do.
/android/app/build/intermediates/res/merged/release/drawable-mdpi/node_modules_reactnativerouterflux_node_modules_reactnativeexperimentalnavigation_assets_backicon.png

@Naoto-Ida
Copy link

Naoto-Ida commented Jul 22, 2016

@SDB9 I think I just manually deleted those images in the end

@chamchamgo
Copy link

chamchamgo commented Jul 31, 2016

@haydenth I found the root cause is that old version's packager collect resources (image etc.) and put under $(rn_project)\android\app\src\main\res, while newer version put them under $(rn_project)\android\app\build\intermediates\res\merged$(buildType). It brings duplication which leads to failure of task 'processReleaseResources'. And it also explains why new created project works well. When you have an old RN project upgrading to newer version, just delete directories like 'drawable-xxxx' (ATTN:no 'v?' postfix) under $(rn_project)\android\app\src\main\res and wolrd will be nice.

@haydenth
Copy link
Contributor Author

@chamchamgo That solved my problem for good. Thank you so much. Closing this ticket out, don't think any further work needed here.

@skv-headless
Copy link
Contributor

skv-headless commented Sep 9, 2016

@haydenth could you reopen? I put images which I use in native code to drawable folders. I can't just remove them. This issue is still relevant for me.

@skv-headless
Copy link
Contributor

Also I don't need NavigationExperimental assets in my apk

@haydenth
Copy link
Contributor Author

haydenth commented Sep 9, 2016

I hate to be pedantic, but could you open a different issue for that? I think it's similar but not quite the same issue I was handling.

@cosmith
Copy link
Contributor

cosmith commented Sep 9, 2016

This is still not fixed for me either, the only thing that works reliably is changing node_modules/react-native/local-cli/bundle/assetPathUtils.js

@haydenth haydenth reopened this Sep 9, 2016
@brickpop
Copy link

brickpop commented Mar 21, 2017

In my case, it was just a matter of removing the $(rn_project)\android\app\src\main\res\drawable-* like suggested, then running ./gradlew clean and then trying to compile again

@jpshelley
Copy link
Contributor

I know this issue is closed. But if you are developing React Native in an Android Library, then you will still have this issue as the newer version of Gradle forces library artifacts to resolve their images to a v4 drawable suffix.

I'm currently working on a fix that I will submit a PR for that specific use case.

@iiitmahesh
Copy link

iiitmahesh commented Apr 19, 2017

@ledfusion

removing the $(rn_project)\android\app\src\main\res\drawable-* like suggested, then running ./gradlew clean and then trying to compile again

its solves my problem, but every time I was forced do delete drawable and cd android && ./gradlew clean && ./gradlew assembleRelease

even this is (react-native run-android --configuration=release) also gives same error.

_

/home/mahesh/projects/gitlab/test/android/app/build/intermediates/res/merged/release/drawable-mdpi/src_images_loader.gif: error: Duplicate file.
/home/mahesh/projects/gitlab/test/android/app/build/intermediates/res/merged/release/drawable-mdpi-v4/src_images_loader.gif: Original is here. The version qualifier may be implied.

_

iiitmahesh added a commit to transindia/react-native that referenced this issue Apr 23, 2017
facebook#5787
 Original is here. The version qualifier may be implied
iiitmahesh added a commit to transindia/react-native that referenced this issue Apr 23, 2017
facebook#5787
Error : Original is here. The version qualifier may be implied
@leonacky
Copy link

@AvatarQing Thank you so much!

@Amurmurmur
Copy link

+1

@Amnesthesia
Copy link

Happened to me again today. @AvatarQing's fix solved this

@blazevignesh
Copy link

i am also faced same kind of issue.its may help u

Unknown source file : res/drawable-mdpi-v4/images_tobacco.png:0: error: Resource entry images_tobacco is already defined.
Unknown source file : res/drawable-mdpi-v4/images_tobacco.jpg:0: Originally defined here.

**What went wrong:
Execution failed for task ':app:processReleaseResources'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/home/xxxx/Android/Sdk/build-tools/23.0.1/aapt'' finished with non-zero exit value 1**

i just changed image extension(jpg to png) in drawable-mdpi-v4 folder.
i got error in images_tobacco.jpg file.so taht i just changed that image extension(jpg to png).now it works fine

@sujayjaju
Copy link
Contributor

sujayjaju commented Feb 23, 2018

I figured the issue was bundling assets based on @chamchamgo 's comment
To resolve it, this is what I did

rm -rf android/app/src/main/res/drawable-*
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/build/intermediates/res/merged/release/

Note the updated --assets-dest in the above command. Assembling the APK worked ok after that!

react-native run-android --variant=release

@hamidhadi
Copy link

I still have this problem with react-native 0.54.0

@arash-hacker
Copy link

CAUTION please consider your **react native version ** and android sdk version🔥🔥🔥
i face this problem after three ours and see many article i finally found solution
because i using lottie animation i need buil with SDK VERSION 26
and using this structure

BACK UP YOUR RN FOLDER FIRST OF ALL

"react": "^16.3.0-alpha.1",
"native-base": "^2.3.10",
"react-native": "0.54.2",
compileSdkVersion 26
buildToolsVersion "26.0.1"

after reading this

first delete drawble files first
rm -rf android/app/src/main/res/drawable-*

changing file node_modules/react-native/react.gradle adding

doLast {
    def moveFunc = { resSuffix ->
        File originalDir = file("${resourcesDir}/drawable-${resSuffix}")
        if (originalDir.exists()) {
            File destDir = file("${resourcesDir}/drawable-${resSuffix}-v4")
            ant.move(file: originalDir, tofile: destDir)
        }
    }
    moveFunc.curry("ldpi").call()
    moveFunc.curry("mdpi").call()
    moveFunc.curry("hdpi").call()
    moveFunc.curry("xhdpi").call()
    moveFunc.curry("xxhdpi").call()
    moveFunc.curry("xxxhdpi").call()
}

to currentBundleTask and adding android.enableAapt2=false to gradle.propertise
finally commnad ./gradlew assembleRelease worked !!!
NO Need to change assetPathUtil
it's bug of gradle to renaming picture

hope solution help RN Developers.

@naoey
Copy link

naoey commented Apr 25, 2018

Changing things within node_modules isn't really an effective solution. Just deleting drawable-* and disabling aapt2 has fixed it for now.

@danielptm
Copy link

danielptm commented Apr 29, 2018

@naoey's solution worked for me + changing the app level build.gradle file to

...
android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.project"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 2
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
...

facebook-github-bot pushed a commit that referenced this issue May 1, 2018
…ies)

Summary:
_Quick apologies for the lengthiness of this description. Want to make sure I'm clear and it is understood what is being altered._

Thanks for submitting a PR! Please read these instructions carefully:

- [x] Explain the **motivation** for making this change.
- [x] Provide a **test plan** demonstrating that the code is solid.
- [x] Match the **code formatting** of the rest of the codebase.
- [x] Target the `master` branch, NOT a "stable" branch.

#5787
```
Unknown source file : /home/tom/projects/blueprint-native/android/app/build/intermediates/res/merged/release/drawable-mdpi-v4/images_google.png: error: Duplicate file.

Unknown source file : /home/tom/projects/blueprint-native/android/app/build/intermediates/res/merged/release/drawable-mdpi/images_google.png: Original is here. The version qualifier may be implied.
```

At Hudl, we've been attempting to package our React Native code into Library Dependencies _(Cocoapods / Android Artifact Resource (aar))_. Recently in React Native 0.42.0, there was an upgrade to the Android Project's gradle plugin from 1.3.1 to 2.2.3. This update drastically effected the outcome of drawable resources in Android without anyone noticing.

**There are 4 outcomes to consider with this change:**
1. You are developing in an Android Application using Gradle 1.3.1 or lower
2. You are developing in an Android Application using Gradle 2.2.3 or higher
3. You are developing in an Android Library Module using Gradle 1.3.1 or lower
4. You are developing in an Android Library Module using Gradle 2.2.3 or higher

With the upgrade to 2.2.3, Android changed the way aapt builds its resources. Any Library created with 2.2.3, has its resources ending with a `v4` suffix. The reasoning behind this I'm not sure of but assume it deals with Vector support that was added around that time.

The change I've added checks if React Native is being ran in an Android Library vs an Application, and appends the v4 suffix to the merged asset folders.

Multiple test were performed.

1. I first started out validating my assumption about the asset merger by creating a new Android Project to verify my assumptions above.
   1. [Application +  >= 2.2.3](https://github.com/jpshelley/TestAndroidLibraryDrawables/tree/master/app/build/intermediates/res/merged/debug) -- `hdpi` contains my drawable. `hdpi-v4` contains dependency's drawables.
   2. [Application + <= 1.3.1](https://github.com/jpshelley/TestAndroidLibraryDrawables/tree/Android-LegacyVersion/app/build/intermediates/res/merged/debug) -- Same as above (I expect because deps are compiled against gradle 2.2.3+ themselves.
   3. [Library + >= 2.2.3](https://github.com/jpshelley/TestAndroidLibraryDrawables/tree/Android-UsingAndroidLibrary/library/build/intermediates/res/merged/debug) -- Only `-v4` folders found! Resources from the library are packages in the app's build output in similar `-v4` folder too.
   4. [Library + <= 1.3.1](https://github.com/jpshelley/TestAndroidLibraryDrawables/tree/Android-UsingAndroidLibraryLegacyVersion/library/build/intermediates/res/merged/debug) -- Same as ii. & iii. `-v4` contains other resources, but my resources are located in non -v4 folder.

2. I then wanted to validate against React Native itself. So I updated my react native code using this PR/Branch, and tested against my project locally. Unfortunately I cannot share that code as it is private, but before this change I was getting the same error as mentioned in #5787 and now my build runs as intended with the assets being placed where they should be.

Additional resources:
* #5787
* http://stackoverflow.com/questions/35700272/android-build-tool-adds-v4-qualifier-to-drawable-folders-by-default-in-generated
* #12710

Please let me know if more information is needed, further test plans, etc. With this change we should be able to upgrade to Gradle 2.3.0 as well to support the latest version of Android Studio.
Closes #13128

Differential Revision: D7828618

Pulled By: hramos

fbshipit-source-id: a7ad7b63b1b51cbfd2ea7656e4d77321306ce33a
@akamahesh
Copy link

Here's another workaround which i have used.
Use this command to update jsbundle.

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

and then use android studio generate apk options .

@jpshelley
Copy link
Contributor

The fix for library based android projects has been merged so we'll hopefully see it in a future release too 2d9e2f3

@Apak00
Copy link

Apak00 commented May 29, 2018

After trying immense amount of workarounds; we ended up downgrading gradle version to 2.2.3 from 3.0.1
and also in gradle/wrapper/gradle-wrapper.properties
distributionUrl=https://services.gradle.org/distributions/gradle-2.14.1-all.zip

now it works fine.

@thinklinux
Copy link

I still had this error with Gradle 3.0.1 :/ Trying so many things that I don't remember them anymore :D

macdoum1 pushed a commit to macdoum1/react-native that referenced this issue Jun 28, 2018
…ies)

Summary:
_Quick apologies for the lengthiness of this description. Want to make sure I'm clear and it is understood what is being altered._

Thanks for submitting a PR! Please read these instructions carefully:

- [x] Explain the **motivation** for making this change.
- [x] Provide a **test plan** demonstrating that the code is solid.
- [x] Match the **code formatting** of the rest of the codebase.
- [x] Target the `master` branch, NOT a "stable" branch.

facebook#5787
```
Unknown source file : /home/tom/projects/blueprint-native/android/app/build/intermediates/res/merged/release/drawable-mdpi-v4/images_google.png: error: Duplicate file.

Unknown source file : /home/tom/projects/blueprint-native/android/app/build/intermediates/res/merged/release/drawable-mdpi/images_google.png: Original is here. The version qualifier may be implied.
```

At Hudl, we've been attempting to package our React Native code into Library Dependencies _(Cocoapods / Android Artifact Resource (aar))_. Recently in React Native 0.42.0, there was an upgrade to the Android Project's gradle plugin from 1.3.1 to 2.2.3. This update drastically effected the outcome of drawable resources in Android without anyone noticing.

**There are 4 outcomes to consider with this change:**
1. You are developing in an Android Application using Gradle 1.3.1 or lower
2. You are developing in an Android Application using Gradle 2.2.3 or higher
3. You are developing in an Android Library Module using Gradle 1.3.1 or lower
4. You are developing in an Android Library Module using Gradle 2.2.3 or higher

With the upgrade to 2.2.3, Android changed the way aapt builds its resources. Any Library created with 2.2.3, has its resources ending with a `v4` suffix. The reasoning behind this I'm not sure of but assume it deals with Vector support that was added around that time.

The change I've added checks if React Native is being ran in an Android Library vs an Application, and appends the v4 suffix to the merged asset folders.

Multiple test were performed.

1. I first started out validating my assumption about the asset merger by creating a new Android Project to verify my assumptions above.
   1. [Application +  >= 2.2.3](https://github.com/jpshelley/TestAndroidLibraryDrawables/tree/master/app/build/intermediates/res/merged/debug) -- `hdpi` contains my drawable. `hdpi-v4` contains dependency's drawables.
   2. [Application + <= 1.3.1](https://github.com/jpshelley/TestAndroidLibraryDrawables/tree/Android-LegacyVersion/app/build/intermediates/res/merged/debug) -- Same as above (I expect because deps are compiled against gradle 2.2.3+ themselves.
   3. [Library + >= 2.2.3](https://github.com/jpshelley/TestAndroidLibraryDrawables/tree/Android-UsingAndroidLibrary/library/build/intermediates/res/merged/debug) -- Only `-v4` folders found! Resources from the library are packages in the app's build output in similar `-v4` folder too.
   4. [Library + <= 1.3.1](https://github.com/jpshelley/TestAndroidLibraryDrawables/tree/Android-UsingAndroidLibraryLegacyVersion/library/build/intermediates/res/merged/debug) -- Same as ii. & iii. `-v4` contains other resources, but my resources are located in non -v4 folder.

2. I then wanted to validate against React Native itself. So I updated my react native code using this PR/Branch, and tested against my project locally. Unfortunately I cannot share that code as it is private, but before this change I was getting the same error as mentioned in facebook#5787 and now my build runs as intended with the assets being placed where they should be.

Additional resources:
* facebook#5787
* http://stackoverflow.com/questions/35700272/android-build-tool-adds-v4-qualifier-to-drawable-folders-by-default-in-generated
* facebook#12710

Please let me know if more information is needed, further test plans, etc. With this change we should be able to upgrade to Gradle 2.3.0 as well to support the latest version of Android Studio.
Closes facebook#13128

Differential Revision: D7828618

Pulled By: hramos

fbshipit-source-id: a7ad7b63b1b51cbfd2ea7656e4d77321306ce33a
@facebook facebook locked as resolved and limited conversation to collaborators Jul 20, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests