How to install Evernote android-job on React Native? - react-native

I've created a repo in which the error can be easily reproducible:
https://github.com/yaronlevi/android_job_with_react_native
I am trying to install Evernote's library android-job for scheduling jobs in a React Native project (with Play Services also installed).
When I run the project I get an error in the Dex phase:
Multiple dex files define Landroid/support/v4/app/BundleUtil
Dex: Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/app/BundleUtil;
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/app/BundleUtil;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
It seems like several libraries are trying to fetch different versions of a support library.
What I did is just added android-job to the gradle file:
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile 'com.evernote:android-job:1.2.2'
}
The exact steps I took can be seen in the repo link above. (You can clone it and run easily).
How can I solve the conflict that occurs regarding the support library.
Thanks in advance (-:

Related

Dependencies between Android native modules (prefab) fail to build

Our Android application consists of 40-some Android Library Modules (ALMs), each of which also builds a C++ shared library with externalNativeBuild and CMake. So far we had the dependencies between these libs set up like this:
The dependent ALM references the dependency ALM with api project(':lib')
The dependent CMake script references the dependency .so with add_library(SHARED IMPORTED lib) and set_target_properties(lib PROPERTIES IMPORTED_LOCATION ...) and a relative path.
Recently we had to upgrade to the latest Android API version. This started off a cascade because now we were getting deprecated warnings in code generated by the navigation-ktx library, but upgrading that requires upgrading Gradle and the Android Gradle plugin. After that I started getting errors like liblib.so, needed by 'project', missing and no known rule to make it.
It looks like the latest Gradle parallelizes build tasks more heavily, and this means the dependent CMake/Ninja builds are being started concurrently with their dependencies, resulting in this error because the dependency is not yet built. I figured out that what we were doing was not entirely supported, but there is a "supported" way to do that now, so I refactored our entire build to use Prefab.
Now I started getting other errors, alternating between:
1.
C++ build system [prefab] failed while executing ...
Usage: prefab [OPTIONS] PACKAGE_PATH...
Error: Invalid value for "PACKAGE_PATH": Directory ... is not readable.
ld: error: undefined symbol ...
I looked into build/intermediates and found that in the 2nd case, the cmake config script was generated incorrectly: instead of add_library(lib::lib SHARED IMPORTED ) it had add_library(lib::lib INTERFACE IMPORTED) like it it was a header only library, and there was no IMPORTED_LOCATION set in the file.
What am I doing wrong and what should I do to unbreak our build?
It looks like the toolchain support for prefab interdependencies within a project is not quite finished. Others are reporting the same kind of errors at https://issuetracker.google.com/issues/265544858:
This appears to be a race condition with generating prefab cmake files.
It says in https://issuetracker.google.com/issues/221231432 that the header-only cmake config is generated to satisfy Android Studio's IDE features (completion, etc.) before the library is actually built.
Treat as-yet-unconfigured modules as if they are Header-only libraries for Android Studio purposes. This works because Android Studio doesn't care about linker flags for the purposes of providing language services.

FrescoModule tried to override com.facebook.react.modules.fresco.FrescoModule

After upgrading from React-Native 0.59.10 to 0.62.2 I receive this error when running the Android app, the IOS app runs without any issues. I found out Fresco is connected to Flipper but I do not understand how to fix this.
In my MainApplication.java file I have no reference to Flipper or Freso (I tried checking this file for duplicate imports. The only reference to Flipper I have in mainapplication.java is the initializeFlipper part on the bottom of the file (as instructed in the upgrade manual).
Unfortunately because I have no understanding where this is coming from I really have no clue of to which code snippets to include to help solve this error message. If anyone could help me with this, and telling what files/code is relevant here please do!
EDIT: Below is the android/app/build.grade file
dependencies {
implementation project(':react-native-fbsdk')
implementation project(':react-native-firebase')
implementation project(':react-native-google-signin')
implementation project(':react-native-image-crop-picker')
implementation project(':react-native-maps')
implementation project(':react-native-screens')
implementation project(':react-native-reanimated')
implementation project(':react-native-gesture-handler')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'com.facebook.android:facebook-core:5.0.0'
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
}
It's an auto-linking issue make sure to unlink any package that uses fresco
for reference default android/app/build.gradle

react-native link adds compile to gradle script, but compile support soon gone

Whenever I use react-native link, it adds the following to my app gradle file.
Image from Android Studio Gradle File
Then when I compile this, Android Studio tells me that "compile" is being deprecated and won't be supported after 2018. My question is, what would the correct replacement be for, for instance, react-native-ionicons?
The section of the gradle file in question is as follows.
dependencies {
compile project(':react-native-vector-icons')
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.facebook.react:react-native:+'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.squareup.okhttp3:okhttp:3.4.0-RC1'
implementation 'com.android.support.constraint:constraint-layout:1.0.0-alpha3'
testImplementation 'junit:junit:4.12'}
It was due to react-native link not having been updated but as of React-Native 0.58.3 the linking procedure has been updated so that compile and api have been replaced with implementation. Which you can see at this pull request
You could also just change compile to implementation in your grade file.
However you may find that some of the build.gradle files for the dependencies still use compile and api, unfortunately they only way to fix warnings from those is to make a pull request on the dependency changing compile and api to implementation

React Native command line 'processDebugGoogleServices' error

I am trying to build an app with below build.gradle file but there is always one error failed to create folder. I have checked many answers but no one helped me in this.
* What went wrong:
Execution failed for task ':app:processDebugGoogleServices'.
> Failed to create folder: D:\App\android\app\build\generated\res\google-services\debug
my app/build.gradle file
dependencies {
compile project(':react-native-android-permissions')
compile project(':react-native-push-notification')
compile project(':react-native-fbsdk')
compile project(':react-native-google-signin')
compile project(':react-native-image-resizer')
compile project(':react-native-image-picker')
compile project(':react-native-fs')
compile project(':react-native-vector-icons')
compile project(':react-native-maps')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:25.0.0"
compile "com.facebook.react:react-native:+" // From node_modules
compile project(':RNPermissionsModule')
compile(project(":react-native-google-signin")) {
exclude group: "com.google.android.gms"
}
compile(project(':react-native-fbsdk')){
exclude(group: 'com.facebook.android', module: 'facebook-android-sdk')
}
compile "com.facebook.android:facebook-android-sdk:4.22.1"
compile "com.google.android.gms:play-services-maps:11.8.0"
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "com.android.support:appcompat-v7:25.0.1"
compile project(':react-native-push-notification')
compile ('com.google.android.gms:play-services-gcm:11.8.0') {
force = true;
}
}
apply plugin: 'com.google.gms.google-services'
Have you used google services plugin in classpath also?
If not please write in build.gradle located outside of the app folder
classpath 'com.google.gms:google-services:3.0.0'
I think this will help you ..!!
I faced the same problem and I solved this by uninstalling the app [yourapp.apk] from your device (e.g: your mobile device) and then run react-native run-android again and it worked like a charm.
But Why?
because you've already had the app with the same name installed on your device (mainly because of the reason that you've downloaded it from somewhere -- and now you want to run the test.app which has the same name, so that's why you've faced this error
do not hesitate to ask me any questions if it didn't work for you!

Multiple dex files define Lcom/google/android/gms/internal/zzqf

I am getting following error while running the build command. However I am using only one version of google service.
:app:dexDebug
Unknown source file : UNEXPECTED TOP-LEVEL EXCEPTION:
Unknown source file : com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzqf;
Unknown source file : at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
Unknown source file : at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
Unknown source file : at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
Unknown source file : at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Unknown source file : at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
Unknown source file : at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
Unknown source file : at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
Unknown source file : at com.android.dx.command.dexer.Main.run(Main.java:277)
Unknown source file : at com.android.dx.command.dexer.Main.main(Main.java:245)
Unknown source file : at com.android.dx.command.Main.main(Main.java:106)
build.gradle
dependencies {
compile(project(':react-native-google-signin')){
exclude group: "com.google.android.gms" // very important
}
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile 'com.google.android.gms:play-services-auth:9.2.1'
compile "com.facebook.react:react-native:+" // From node_modules
compile project(':react-native-vector-icons')
compile "com.airbnb.android:react-native-maps:0.7.1"
compile 'com.google.android.gms:play-services-maps:9.2.1'
compile project(':react-native-image-picker')
compile project(':RNMaterialKit')
compile project(':react-native-fcm')
}
Changing node_modules is not the right approach, you can apply the dex in /android/app/build.gradle forcefully.
compile ('com.google.android.gms:play-services-auth:9.2.1'){
force=true
}
compile ('com.google.android.gms:play-services-maps:9.2.1'){
force=true
}
Do make sure that all your dependencies support 9.2.1
You are using play-services:9.2.1 make sure you have same play-service version in your entire project including node modules.
Look at the following screenshot. I have same play-service version in the entire project.
Solution: Apply the dex in /android/app/build.gradle forcefully.
compile ('com.google.android.gms:play-services-auth:9.2.1'){
force=true
}
compile ('com.google.android.gms:play-services-maps:9.2.1'){
force=true
}