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

Lint/build error - WrongConstant - Gradle - React Native build for android #1150

Closed
leonardo-coutinho-dev opened this issue Jan 4, 2024 · 8 comments · Fixed by #1151
Closed

Comments

@leonardo-coutinho-dev
Copy link

leonardo-coutinho-dev commented Jan 4, 2024

I have the following error when trying to build a react native (bare workflow) app for android (cd android && ./gradlew build):

node_modules\lottie-react-native\android\src\main\java\com\airbnb\android\react\lottie\LottieAnimationViewPropertyManager.kt

lines 72 & 87 - 2 errors

C:\Projetos\hph-services-app\node_modules\lottie-react-native\android\src\main\java\com\airbnb\android\react\lottie\LottieAnimationViewPropertyManager.kt:72: Error: Must be one of: Typeface.NORMAL, Typeface.BOLD, Typeface.ITALIC, Typeface.BOLD_ITALIC [WrongConstant]
                return typeface?: Typeface.defaultFromStyle(400)
                                                            ~~~
C:\Projetos\hph-services-app\node_modules\lottie-react-native\android\src\main\java\com\airbnb\android\react\lottie\LottieAnimationViewPropertyManager.kt:87: Error: Must be one of: Typeface.NORMAL, Typeface.BOLD, Typeface.ITALIC, Typeface.BOLD_ITALIC [WrongConstant]
                return typeface?: Typeface.defaultFromStyle(400)
                                                            ~~~

   Explanation for issues of type "WrongConstant":
   Ensures that when parameter in a method only allows a specific set of
   constants, calls obey those rules.

Problem:

The lint error points to the following line in the LottieAnimationViewPropertyManager.kt file:

return typeface?: Typeface.defaultFromStyle(400)

The error message states:

Error: Must be one of: Typeface.NORMAL, Typeface.BOLD, Typeface.ITALIC, Typeface.BOLD_ITALIC [WrongConstant]

I have:

Gradle version: 7.6.2

"react-native": "0.72.6",
"lottie-react-native": "^6.4.1"
@eTryp
Copy link

eTryp commented Jan 4, 2024

I managed to resolve the compilation issue with a quick fix. It might not be the most elegant solution, but it is effective.
To implement this fix:

  1. Open the file at the following path:

/node_modules/lottie-react-native/android/src/main/java/com/airbnb/android/react/lottie/LottieAnimationViewPropertyManager.kt

  1. In the init method of this file, locate and remove the two instances of Typeface.defaultFromStyle(400).

@TheRogue76
Copy link
Collaborator

Hi guys,

Thanks for pointing this out. This is a linting error. I'll open a PR and update it. One question though mostly out of curiosity, is this actually blocking you guys from building the app? If so we can do a patch release. Our CI is running this fine and we haven't had an issue with this till now. I can see the environment you are building on is Windows though.

@eTryp
Copy link

eTryp commented Jan 4, 2024

Hi,

I'm using MacOS, and the issue arises when I execute ./gradlew build from the terminal.
Interestingly, I encounter no issues when running yarn android.

As you pointed out, it seems the linter might only be activated through the build command.
I'm also interested in understanding @leonardo-coutinho-dev's environment / use case.

@TheRogue76 TheRogue76 linked a pull request Jan 4, 2024 that will close this issue
@TheRogue76
Copy link
Collaborator

I wrote the PR. Please wait for it to be approved, and we can probably release 6.5.1 afterwards if all is good.

@matinzd
Copy link
Collaborator

matinzd commented Jan 4, 2024

Can you drop your app's build.gradle in here? @leonardo-coutinho-dev

@matinzd
Copy link
Collaborator

matinzd commented Jan 4, 2024

Fixed in v6.5.1 🚀

@leonardo-coutinho-dev
Copy link
Author

leonardo-coutinho-dev commented Jan 4, 2024

@eTryp

Hi, I was trying to build the app on Windows, for Android, through the bash terminal (with ./gradlew build on android folder).

We already have a build for iOs (no issues).

I was in charge today to create the build for Android and run into this issue in the morning.

Here's the build.gradle @matinzd:

project-level

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "23.1.7779620"

        // react-native-leaflet-view - build solution

        kotlinVersion = "1.7.20" // 1 <- here is solution
        RNNKotlinVersion = kotlinVersion // 2 <- here is solution
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle")
        classpath("com.facebook.react:react-native-gradle-plugin")

        // react-native-leaflet-view - build solution

        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")// 3 <- here is solution
    }
}

@leonardo-coutinho-dev
Copy link
Author

Fixed in v6.5.1 🚀

This solved the problem, thank you so much guys! ;)

@leonardo-coutinho-dev leonardo-coutinho-dev changed the title Build error - WrongConstant - Gradle - React Native build for android Lint/build error - WrongConstant - Gradle - React Native build for android Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants