oblador / react-native-vector-icons

Customizable Icons for React Native with support for image source and full styling.
https://oblador.github.io/react-native-vector-icons/
MIT License
17.31k stars 2.12k forks source link

Android: gradle wrapper 7.2 yields 'execution optimizations disabled' warning #1406

Open fiznool opened 2 years ago

fiznool commented 2 years ago

Environment

Description

I have added react-native-vector-icons to my React Native project using RN 0.67. I am using Gradle wrapper 7.3.3 but the behaviour is the same for 7.2.

When running npx react-native run-android --variant debug I see the following in the terminal:

> Task :app:compressDebugAssets
Execution optimizations have been disabled for task ':app:compressDebugAssets' to ensure correctness due to the following reasons:
  - Gradle detected a problem with the following location: '/Users/studiozeffa/Code/rn-project/android/app/build/intermediates/merged_assets/debug/out'. Reason: Task ':app:compressDebugAssets' uses this output of task ':app:copyDebugReactNativeVectorIconFonts' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.3.3/userguide/validation_problems.html#implicit_dependency for more details about this problem.

The same warning is repeated for other gradle tasks too.

This is just a warning - the app still compiles and builds ok

Reproducible Demo

Dirty workaround

I've added the following to fonts.gradle which removes the warning, but I am sure there is a better way to do this.

def compressAssetsTask = tasks.findByName("compress${targetName}Assets")
compressAssetsTask.dependsOn(currentFontCopyTask)

def processMainManifestTask = tasks.findByName("process${targetName}MainManifest")
processMainManifestTask.dependsOn(currentFontCopyTask)

def processManifestTask = tasks.findByName("process${targetName}Manifest")
processManifestTask.dependsOn(currentFontCopyTask)

def processManifestForPackageTask = tasks.findByName("process${targetName}ManifestForPackage")
processManifestForPackageTask.dependsOn(currentFontCopyTask)

def mergeJavaResourceTask = tasks.findByName("merge${targetName}JavaResource")
mergeJavaResourceTask.dependsOn(currentFontCopyTask)

def mergeExtDexTask = tasks.findByName("mergeExtDex${targetName}")
mergeExtDexTask.dependsOn(currentFontCopyTask)

def mergeNativeLibsTask = tasks.findByName("merge${targetName}NativeLibs")
mergeNativeLibsTask.dependsOn(currentFontCopyTask)

def mergeResourcesTask = tasks.findByName("merge${targetName}Resources")
mergeResourcesTask.dependsOn(currentFontCopyTask)

def stripDebugSymbolsTask = tasks.findByName("strip${targetName}DebugSymbols")
stripDebugSymbolsTask.dependsOn(currentFontCopyTask)
jetaggart commented 2 years ago

I'm having this issue as well.

huynhhq commented 2 years ago

I also meet this issue.

mayconline commented 2 years ago

same issue

jandreotti commented 2 years ago

same issue... :(

jetaggart commented 2 years ago

@fiznool can you provide more context with your workaround? I added those lines to the fonts.gradle in the node_modules but nothing changed.

This is causing a full rebuild on every run

fiznool commented 2 years ago

@bit-void the lines above need to go inside the android.applicationVariants.all block. Make sure you add these extra lines of code straight after the following:

    // mergeResources task runs before the bundle file is copied to the intermediate asset directory from Android plugin 4.1+.
    // This ensures to copy the bundle file before mergeResources task starts
    def mergeResourcesTask = tasks.findByName("merge${targetName}Resources")
    mergeResourcesTask.dependsOn(currentFontCopyTask)

    // Put the extra lines here
    // Make sure they come before the two closing braces
  }
}
jandreotti commented 2 years ago

For me the workaround that work was comment the two lines and then add what fiznool put.

like this:

        // def mergeResourcesTask = tasks.findByName("merge${targetName}Resources")
        // mergeResourcesTask.dependsOn(currentFontCopyTask)

        def compressAssetsTask = tasks.findByName("compress${targetName}Assets")
        compressAssetsTask.dependsOn(currentFontCopyTask)

        def processMainManifestTask = tasks.findByName("process${targetName}MainManifest")
        processMainManifestTask.dependsOn(currentFontCopyTask)

        def processManifestTask = tasks.findByName("process${targetName}Manifest")
        processManifestTask.dependsOn(currentFontCopyTask)

        def processManifestForPackageTask = tasks.findByName("process${targetName}ManifestForPackage")
        processManifestForPackageTask.dependsOn(currentFontCopyTask)

        def mergeJavaResourceTask = tasks.findByName("merge${targetName}JavaResource")
        mergeJavaResourceTask.dependsOn(currentFontCopyTask)

        def mergeExtDexTask = tasks.findByName("mergeExtDex${targetName}")
        mergeExtDexTask.dependsOn(currentFontCopyTask)

        def mergeNativeLibsTask = tasks.findByName("merge${targetName}NativeLibs")
        mergeNativeLibsTask.dependsOn(currentFontCopyTask)

        def mergeResourcesTask = tasks.findByName("merge${targetName}Resources")
        mergeResourcesTask.dependsOn(currentFontCopyTask)

        def stripDebugSymbolsTask = tasks.findByName("strip${targetName}DebugSymbols")
        stripDebugSymbolsTask.dependsOn(currentFontCopyTask)

Some times it does not build or start android app. I try to run another time and it works... Strange... but for now... it was it is..

gunnartorfis commented 2 years ago

Same thing happening here on RN 0.68, using 9.0.0.

williamgurzoni commented 2 years ago

It seems to be a React Native issue: https://github.com/facebook/react-native/issues/33202

fadi-quader-mox commented 2 years ago

same here

Xmaxer commented 1 year ago

When using Gradle 8, this warning becomes an error.

Here's a one line patch file for those who use patch-package:

diff --git a/node_modules/react-native-vector-icons/fonts.gradle b/node_modules/react-native-vector-icons/fonts.gradle
index 5485fac..f1b8932 100644
--- a/node_modules/react-native-vector-icons/fonts.gradle
+++ b/node_modules/react-native-vector-icons/fonts.gradle
@@ -16,7 +16,7 @@ afterEvaluate {
         type: Copy) {
         description = "copy vector icon fonts."
         into "$buildDir/intermediates/ReactNativeVectorIcons/fonts"
-
+        dependsOn "lintVitalReportRelease"
         iconFontNames.each { fontName ->
             from(iconFontsDir) {
                 include(fontName)

I'll disclose that I am not sure this is the way to fix it correctly. It does fix my build issues though.

ya-watanabe commented 1 year ago

I have another variant and faced a bit different error. Reason: Task ':app:lintVitalAnalyzeStagingRelease' uses this output of task ':app:copyReactNativeVectorIconFonts' without declaring an explicit or implicit dependency. Im my case, following patch works.`


diff --git a/node_modules/react-native-vector-icons/fonts.gradle b/node_modules/react-native-vector-icons/fonts.gradle
index 5485fac..674c716 100644
--- a/node_modules/react-native-vector-icons/fonts.gradle
+++ b/node_modules/react-native-vector-icons/fonts.gradle
@@ -16,7 +16,6 @@ afterEvaluate {
         type: Copy) {
         description = "copy vector icon fonts."
         into "$buildDir/intermediates/ReactNativeVectorIcons/fonts"
-
         iconFontNames.each { fontName ->
             from(iconFontsDir) {
                 include(fontName)
@@ -28,5 +27,13 @@ afterEvaluate {
         def targetName = variant.name.capitalize()
         def generateAssetsTask = tasks.findByName("generate${targetName}Assets")
         generateAssetsTask.dependsOn(fontCopyTask)
+
+        if (targetName.contains("Release")) {
+            fontCopyTask.dependsOn("lintVitalReport${targetName}")
+            fontCopyTask.dependsOn("lintVitalAnalyze${targetName}")
+        }
     }
 }