Error while building Android?

I’m trying to build Android locally so we can support custom fonts in Android as well as iOS, but I’m getting this error:

ReactNativeClient git:custom-android-editor-styles ❯ react-native run-android
info JS server already running.
info Building and installing the app on the device (cd android && ./gradlew app:installDebug)...

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':@react-native-community_slider'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/devonzuegel/dev/joplin/ReactNativeClient/android/local.properties'.

* 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 0s
error Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
error Command failed: ./gradlew app:installDebug. Run CLI with --verbose flag for more details.

@tessus since you’re on Android, do you perhaps have any ideas here?

I see you are on macOS. Add the following to your .bash_profile:

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
export ANDROID_SDK_ROOT=$ANDROID_HOME
export ANDROID_AVD_HOME=$HOME/.android/avd
alias emulator='$ANDROID_SDK_ROOT/tools/emulator'

This should fix the error above. Laurent also added npx jetify to the build process to get around some issues that started with the transition to Android 10, so you shouldn't run into any other weird errors.
Please note that you have to start the emulator manually. For some reason it is not started automatically as it is done with run-ios.

But to be honest, I also have a few issues with the Android build environment. I have found a workaround, which is really irritating, but it's the only way to get it to run properly.

So, should you run into the same problem I had later on, have a look at:

The fix is truly annoying, since it has to be run every time before running react-native run-android, but it was the only way for me to get it to work (never had any issues with run-ios):

react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

I hope the info helps. If not, I'll be back after I had a decent sleep.

1 Like

It looks like Android Studio is not installed correctly. The best for this project is to follow the steps “CLI Quickstart” on this page: https://facebook.github.io/react-native/docs/getting-started

1 Like

Unfortunately I’m still super stuck after following dozens of rabbit holes… When I try to run the emulator, I get this:

ReactNativeClient git:master ❯ react-native run-android                                      ✹
info JS server already running.
info Building and installing the app on the device (cd android && ./gradlew app:installDebug)...

> Configure project :@react-native-community_slider
Checking the license for package Android SDK Build-Tools 28.0.3 in /Users/devonzuegel/Library/Android/sdk/licenses
Warning: License for package Android SDK Build-Tools 28.0.3 not accepted.
Checking the license for package Android SDK Platform 28 in /Users/devonzuegel/Library/Android/sdk/licenses
Warning: License for package Android SDK Platform 28 not accepted.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':@react-native-community_slider'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
     build-tools;28.0.3 Android SDK Build-Tools 28.0.3
     platforms;android-28 Android SDK Platform 28
  To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
  Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html

  Using Android SDK: /Users/devonzuegel/Library/Android/sdk

* 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 1s
error Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
error Command failed: ./gradlew app:installDebug. Run CLI with --verbose flag for more details.

Following that error, I tried updating the licenses, but then I got his error:

ReactNativeClient git:master ❯ sdkmanager --update && yes | sdkmanager --licenses          ⏎ ✹

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
	at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
	at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
	at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
	at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
	at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 5 more

It appears to to be some issue with my Java version, but following several guides like this one hasn’t resolved the issue.

My goal in building the Android app is to support custom fonts with this PR, which is already working for iOS. I don’t want to waste a bunch of your time just trying to help me build this on my machine, so if it’s less of a pain for one of you to resolve it—or if you’re fine with just merging as-is without Android support—that’s fine by me too! I just didn’t want to leave Android users hanging.

I’m not familiar with these licensing errors unfortunately, I guess it depends how Android SDK was installed.

I’ll give another try to the Android build once you’ve updated the branch, as I assume there’s not much missing to get it working in Android too.