brodybits / create-react-native-module

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

View does not build on Android with React Native 0.60(+)

brodybits opened this issue · comments

create-react-native-module version: 0.5.0

Command used to generate view module with example:

create-react-native-module --generate-example --view beth-adam

Build output from react-native run-android in generated example:

info JS server already running.
info Installing the app...

> Configure project :react-native-beth-adam
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getJavaCompile(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information.

> Task :react-native-beth-adam:compileDebugJavaWithJavac

> Task :react-native-beth-adam:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings
20 actionable tasks: 20 executed
/Users/brodybits/dev/ctt-b54ec259-dc4d/test1/react-native-beth-adam/example/node_modules/react-native-beth-adam/android/src/main/java/com/reactlibrary/BethAdamManager.java:5: error: package android.support.v7.widget does not exist
import android.support.v7.widget.AppCompatCheckBox;
                                ^
/Users/brodybits/dev/ctt-b54ec259-dc4d/test1/react-native-beth-adam/example/node_modules/react-native-beth-adam/android/src/main/java/com/reactlibrary/BethAdamManager.java:22: error: cannot find symbol
        AppCompatCheckBox cb = new AppCompatCheckBox(c);
        ^
  symbol:   class AppCompatCheckBox
  location: class BethAdamManager
/Users/brodybits/dev/ctt-b54ec259-dc4d/test1/react-native-beth-adam/example/node_modules/react-native-beth-adam/android/src/main/java/com/reactlibrary/BethAdamManager.java:22: error: cannot find symbol
        AppCompatCheckBox cb = new AppCompatCheckBox(c);
                                   ^
  symbol:   class AppCompatCheckBox
  location: class BethAdamManager
3 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-beth-adam:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 32s

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
/Users/brodybits/dev/ctt-b54ec259-dc4d/test1/react-native-beth-adam/example/node_modules/react-native-beth-adam/android/src/main/java/com/reactlibrary/BethAdamManager.java:5: error: package android.support.v7.widget does not exist
import android.support.v7.widget.AppCompatCheckBox;
                                ^
/Users/brodybits/dev/ctt-b54ec259-dc4d/test1/react-native-beth-adam/example/node_modules/react-native-beth-adam/android/src/main/java/com/reactlibrary/BethAdamManager.java:22: error: cannot find symbol
        AppCompatCheckBox cb = new AppCompatCheckBox(c);
        ^
  symbol:   class AppCompatCheckBox
  location: class BethAdamManager
/Users/brodybits/dev/ctt-b54ec259-dc4d/test1/react-native-beth-adam/example/node_modules/react-native-beth-adam/android/src/main/java/com/reactlibrary/BethAdamManager.java:22: error: cannot find symbol
        AppCompatCheckBox cb = new AppCompatCheckBox(c);
                                   ^
  symbol:   class AppCompatCheckBox
  location: class BethAdamManager
3 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-beth-adam:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 32s

    at checkExecSyncError (child_process.js:629:11)
    at execFileSync (child_process.js:647:13)
    at runOnAllDevices (/Users/brodybits/dev/ctt-b54ec259-dc4d/test1/react-native-beth-adam/example/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:75:39)
    at buildAndRun (/Users/brodybits/dev/ctt-b54ec259-dc4d/test1/react-native-beth-adam/example/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:137:41)
    at then.result (/Users/brodybits/dev/ctt-b54ec259-dc4d/test1/react-native-beth-adam/example/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:103:12)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Related to #25 (updates for React Native 0.60)

P.S. I think the underlying cause is using importing AppCompatCheckBox from android.support.v7.widget, which seems to be not included by default when using React Native 0.60. Any help with a simple, clean workaround solution to get a sample widget working on recent versions of React Native would be highly appreciated. Doesn’t matter so much which widget, no need for consistency with iOS, just to get this working.

The following update seems to solve this issue:

diff --git a/templates/android.js b/templates/android.js
index c9e0648..f2b235a 100644
--- a/templates/android.js
+++ b/templates/android.js
@@ -179,7 +179,7 @@ public class ${name}Module extends ReactContextBaseJavaModule {
 
 import android.view.View;
 
-import android.support.v7.widget.AppCompatCheckBox;
+import androidx.appcompat.widget.AppCompatCheckBox;
 
 import com.facebook.react.uimanager.SimpleViewManager;
 import com.facebook.react.uimanager.ThemedReactContext;

This change should be applied to a generated View project if it is needed for React Native 0.60(+) on Android.

Unfortunately this update would cause a similar failure on React Native pre-0.60. I hope we can drop support for RN pre-0.60 someday.