Not able to build for android

react-native run-android-android
info Starting JS server…
info Building and installing the app on the device (cd android && ./gradlew app:installDebug)…
Starting a Gradle Daemon (subsequent builds will be faster)

> Configure project :app
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)

> Configure project :react-native-device-info
WARNING: The specified Android SDK Build Tools version (25.0.2) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.4.1.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '25.0.2'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

> Configure project :react-native-fabric
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: 
WARNING: The specified Android SDK Build Tools version (26.0.2) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.4.1.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '26.0.2'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

> Configure project :react-native-firebase
react-native-firebase: using React Native prebuilt binary from /home/devendradora/projects/android/DiscourseMobile/node_modules/react-native/android

> Configure project :react-native-key-pair
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: 
WARNING: The specified Android SDK Build Tools version (23.0.1) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.4.1.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '23.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

> Configure project :react-native-orientation
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: The specified Android SDK Build Tools version (23.0.1) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.4.1.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '23.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

> Configure project :react-native-vector-icons
WARNING: The specified Android SDK Build Tools version (26.0.3) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.4.1.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '26.0.3'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

> Configure project :react-native-webview
:react-native-webview:reactNativeAndroidRoot /home/devendradora/projects/android/DiscourseMobile/node_modules/react-native/android

> Task :app:processDebugGoogleServices
Parsing json file: /home/devendradora/projects/android/DiscourseMobile/android/app/google-services.json

> Task :react-native-firebase:compileDebugJavaWithJavac
/home/devendradora/projects/android/DiscourseMobile/node_modules/react-native-firebase/android/src/main/java/io/invertase/firebase/messaging/RNFirebaseMessaging.java:8: error: package android.support.v4.content does not exist
import android.support.v4.content.LocalBroadcastManager;
                                 ^
/home/devendradora/projects/android/DiscourseMobile/node_modules/react-native-firebase/android/src/main/java/io/invertase/firebase/messaging/RNFirebaseMessagingService.java:5: error: package android.support.v4.content does not exist
import android.support.v4.content.LocalBroadcastManager;
                                 ^
/home/devendradora/projects/android/DiscourseMobile/node_modules/react-native-firebase/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotifications.java:11: error: package android.support.v4.content does not exist
import android.support.v4.content.LocalBroadcastManager;
                                 ^
/home/devendradora/projects/android/DiscourseMobile/node_modules/react-native-firebase/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java:21: error: package android.support.v4.content does not exist
import android.support.v4.content.LocalBroadcastManager;
                                 ^
/home/devendradora/projects/android/DiscourseMobile/node_modules/react-native-firebase/android/src/main/java/io/invertase/firebase/messaging/RNFirebaseMessaging.java:36: error: cannot find symbol
    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
    ^
  symbol:   class LocalBroadcastManager
  location: class RNFirebaseMessaging
/home/devendradora/projects/android/DiscourseMobile/node_modules/react-native-firebase/android/src/main/java/io/invertase/firebase/messaging/RNFirebaseMessaging.java:36: error: cannot find symbol
    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
                                                  ^
  symbol:   variable LocalBroadcastManager
  location: class RNFirebaseMessaging
/home/devendradora/projects/android/DiscourseMobile/node_modules/react-native-firebase/android/src/main/java/io/invertase/firebase/messaging/RNFirebaseMessagingService.java:26: error: cannot find symbol
    LocalBroadcastManager
    ^
  symbol:   variable LocalBroadcastManager
  location: class RNFirebaseMessagingService
/home/devendradora/projects/android/DiscourseMobile/node_modules/react-native-firebase/android/src/main/java/io/invertase/firebase/messaging/RNFirebaseMessagingService.java:41: error: cannot find symbol
      LocalBroadcastManager
      ^
  symbol:   variable LocalBroadcastManager
  location: class RNFirebaseMessagingService
/home/devendradora/projects/android/DiscourseMobile/node_modules/react-native-firebase/android/src/main/java/io/invertase/firebase/messaging/RNFirebaseMessagingService.java:51: error: cannot find symbol
        LocalBroadcastManager
        ^
  symbol:   variable LocalBroadcastManager
  location: class RNFirebaseMessagingService
/home/devendradora/projects/android/DiscourseMobile/node_modules/react-native-firebase/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotifications.java:54: error: cannot find symbol
    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
    ^
  symbol:   class LocalBroadcastManager
  location: class RNFirebaseNotifications
/home/devendradora/projects/android/DiscourseMobile/node_modules/react-native-firebase/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotifications.java:54: error: cannot find symbol
    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
                                                  ^
  symbol:   variable LocalBroadcastManager
  location: class RNFirebaseNotifications
/home/devendradora/projects/android/DiscourseMobile/node_modules/react-native-firebase/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java:204: error: cannot find symbol
      LocalBroadcastManager
      ^
  symbol:   variable LocalBroadcastManager
  location: class RNFirebaseNotificationManager
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
12 errors

> Task :react-native-firebase:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-firebase: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.
1 Like

@devendradora can you try adding a gradle.properties file in /android with the following contents:

android.useDeprecatedNdk=true
android.useAndroidX=true
android.enableJetifier=true

and then running the run-android command again? Let me know if that doesn’t work.

4 Likes

Thank you Dear @pmusaraj

I have updated gradle.properties but still getting error.

  • I have updated below in a branch checkout from master after cloning to temporarily fix various errors .
  1. In android/app/build.gradle
  • commented versionName MYAPP_VERSION

  • commented signingConfigs

  1. updated android/gradle.properties

android.useDeprecatedNdk=true
android.useAndroidX=true
android.enableJetifier=true

It would be really helpful, if package.json and build.gradle is updated so that there is no build failure

Please find logs. pasted in pastebin
https://pastebin.com/md6dHHd1

Thank you for all your help.

Make sure you’ve pulled the repository and cleaned your build (either in Android Studio or via Gradle). This sounds like an issue with caches, once they’re cleared, the build should run.

2 Likes

Thank you dear @pmusaraj
I once again tried a fresh git clone and build project in windows , linux and mac os , but same error.

Is it possible for you to kindly share the latest package.json and build.gradle

thank you.

What is your version of gradle and java?

2 Likes

I tried all the steps specified , but still it fails throwing following error

**Execution failed for task ':react-native-firebase:compileDebugJavaWithJavac'.**
**> Compilation failed; see the compiler error output for details.**

**java -version**
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-2-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)


**Gradle version**
Tried gradle-4.10.2 , gradle-5.1.1
1 Like

You can try upgrading your openjdk to version to 12 or look into the compiler logs for more details on that specific errors.

4 Likes

Hey,
So I was also getting similar kind of errors and found out that some of the libraries require Java8 support…so as we have to manually install these versions in android studio version 3 and later…so do you also followed the same path coz I want to be sure before making a change to the build tools?

2 Likes

I ran into some similar issues building the Android app yesterday, and followed the steps from GitHub - mikehardy/jetifier: The jetifier AndroidX transition tool in react-native-friendly npm format. If you pull the latest commits in the DiscourseMobile repository and run yarn install, you should be able to then build the app for Android.

2 Likes

I wanted to build the project and debug as I was not able to add our discourse site to official android app on playstore.
I tried adding http and https version of the site https://forum.amarantos.org
It is acessible by browser, but discourse app gives error saying site not found.
Please help.

Ah, I see. I did debug this for you, and I see that the app’s request to https://forum.amarantos.org/site/basic-info.json gets a 403 response with the reason “Crawler is not allowed!”. That means that the site refuses the request from the app because it thinks the app is a crawler. Can you search for crawler in your site settings and let me know if you see “Discourse Android App / 1.0” or something similar in the list of blocked crawlers? This is something that should be fixed on your Discourse instance, you need to allow the app to access the site.

5 Likes

Thanks a lot @pmusaraj

In whitelisted crawler user agents , I had Google Bot and Discourse Android App / 1.0 , but these entries were not present in blacklist. So I tried removing above 2 entries in whitelisted crawler user agent , then it worked.

Please can you let me know exact user agent for discourse android or ios app so that i whitelist only them.

Good to hear. You should whitelist the following:

  • DiscourseHub (this is appended to the user agent in iOS)
  • Discourse Android App (app’s API calls on Android)
  • Discourse iOS App (app’s API calls on iOS)

Notice I removed the version number, those might change, you’re better off whitelisting without that.

1 Like