React-native-pager-view: error @react-native-community_viewpager:compileDebugJavaWithJavac

Created on 18 Jun 2019  ·  16Comments  ·  Source: callstack/react-native-pager-view

Question

"@react-native-community/viewpager": "^1.1.7",
"react": "16.8.3",
"react-native": "^0.59.9",

when i run react-native run-android , i get this error ,please help!

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':@react-native-community_viewpager:compileDebugJavaWithJavac'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:151)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:148)
at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:191)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:141)
at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionStateTaskExecuter.execute(ResolveBeforeExecutionStateTaskExecuter.java:75)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution

Needs Repro

Most helpful comment

I was able to fix it by adding:

implementation "com.android.support:support-v4:${rootProject.ext.supportLibVersion}"

to my android/app/build.gradle file.

Note that if you have not set up an ext.supportLibVersion variable in your android/build.gradle file you will have to define your version explicitly. In my case this would be:

implementation "com.android.support:support-v4:28.0.0"

EDIT: I have realized that a library I was using which was androidx enabled was causing the problem. In my case it was react-native-iap: 3.3.8. I had thought what I had mentioned above had fixed it, however this was a red herring. To fix this, I did the following:

  1. yarn add -D jetifier - Jetifier is a tool to migrate dependencies up to and down from AndroidX
  2. npx jetify -r - This will migrate any dependencies down from AndroidX
  3. Globally search your project(including dependencies) for android.useAndroidX=true and android.enableJetifier=true. If you find any dependencies whos gradle.properties file has these set to true, set them to false.
  4. Add a script to your postinstall hook in your package.json that will run both npx jetify -r as well as update any of the offending gradle.properties files.

It seems that when one of your dependencies has jetifier and androidx enabled, that propagates out to other parts of the project, resulting in us not having access to com.android.support:support-v4.

I think the reason this seems to be showing up on this library is because it is often the first library to be compiled which relies on com.android.support:support-v4. While troubleshooting this, I updated node_modules/@react-native-community/viewpager/android/build.gradle to include implementation "com.android.support:support-v4:28.0.0" in it's dependencies. This allowed it to compile, however I hit the same error on subsequent libraries that depended on it.

All 16 comments

got the same issue about 4 hours ago, nothing changed just next build crashed

@forrest23 or @Villar74 do you have any code to reproduce this? Did you link the library? Did you try linking it manually?

@ferrannp @Villar74

I solve this problem by migrate to AndroidX use android studio, I don't know why!

import ViewPagerAndroid from "@react-native-community/viewpager";

@forrest23 I've migrated to AndroidX, but I still have the same problem. "react-native": "0.60.0-rc.2"

Did anyone find any solution?

I was able to fix it by adding:

implementation "com.android.support:support-v4:${rootProject.ext.supportLibVersion}"

to my android/app/build.gradle file.

Note that if you have not set up an ext.supportLibVersion variable in your android/build.gradle file you will have to define your version explicitly. In my case this would be:

implementation "com.android.support:support-v4:28.0.0"

EDIT: I have realized that a library I was using which was androidx enabled was causing the problem. In my case it was react-native-iap: 3.3.8. I had thought what I had mentioned above had fixed it, however this was a red herring. To fix this, I did the following:

  1. yarn add -D jetifier - Jetifier is a tool to migrate dependencies up to and down from AndroidX
  2. npx jetify -r - This will migrate any dependencies down from AndroidX
  3. Globally search your project(including dependencies) for android.useAndroidX=true and android.enableJetifier=true. If you find any dependencies whos gradle.properties file has these set to true, set them to false.
  4. Add a script to your postinstall hook in your package.json that will run both npx jetify -r as well as update any of the offending gradle.properties files.

It seems that when one of your dependencies has jetifier and androidx enabled, that propagates out to other parts of the project, resulting in us not having access to com.android.support:support-v4.

I think the reason this seems to be showing up on this library is because it is often the first library to be compiled which relies on com.android.support:support-v4. While troubleshooting this, I updated node_modules/@react-native-community/viewpager/android/build.gradle to include implementation "com.android.support:support-v4:28.0.0" in it's dependencies. This allowed it to compile, however I hit the same error on subsequent libraries that depended on it.

I get the same error. Did anyone find any solution?

@linqiangsheng Did you try the steps I described above?

@fossage got this error when I did clean build for some other purpose and resolved just by closing and opening the project in Studio. what would be the reason behind this error and Can you suggest permanent solution for this?

@fossage got this error when I did clean build for some other purpose and resolved just by closing and opening the project in Studio. what would be the reason behind this error and Can you suggest permanent solution for this?

What version of library ? Are you using expo ?

@troZee "@react-native-community/viewpager": "5.0.5",.

No, I am not using Expo.

@Yandamuri I am not able to reproduce it https://github.com/troZee/viewPagerExample

Please provide a simple repository with reproducible example

@troZee so you meant to say that no matter how many times you do clean build you didn't get this error, Right!

If this the case, May I know your react-native and react-native-viewpager versions respectively?

BTW, This is the error that I ma getting

Execution failed for task ':@react-native-community_viewpager:packageDebugResources'.
java.nio.file.AccessDeniedException: C:UsersDT1DocumentsMobileProjectsgro3.0smartfsmnode_modules@react-native-communityviewpagerandroidbuildintermediatespackaged_resdebugvalues

@troZee

@Yandamuri I am not able to reproduce it https://github.com/troZee/viewPagerExample

Please provide a simple repository with reproducible example

I am getting following error
Screenshot 2021-04-19 at 4 08 02 PM

I tried all the possibilities described in this SO Question, but nothing worked.

Can you help me in running this project?

@troZee I was using windows machine(Desktop) where it was working well both in debug and release mode. Then tired in my Dell bistro 2520 laptop where I got same error in debug mode(I didn't try in release mode).I have recently moved to Macbook Pro M1 where I am getting this error only when creating release apk(working fine with debug mode). Following is the error

Task :@react-native-community_viewpager:compileReleaseJavaWithJavac FAILED
* What went wrong: Execution failed for task ':@react-native-community_viewpager:compileReleaseJavaWithJavac'. java.lang.IllegalAccessError: class org.gradle.internal.compiler.java.ClassNameCollector (in unnamed module @0x128fee6b) cannot access class com.sun.tools.javac.code.Symbol$TypeSymbol (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.code to unnamed module @0x128fee6b

This is happening in my MacBook Pro M1 and in release mode only.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

orcunorcun picture orcunorcun  ·  9Comments

Andarius picture Andarius  ·  5Comments

troZee picture troZee  ·  8Comments

olhapi picture olhapi  ·  4Comments

troZee picture troZee  ·  3Comments