mesibo / samples

Mesibo Samples
55 stars 61 forks source link

error while integrating mesibo with react native #39

Closed DjellalAbdou closed 3 years ago

DjellalAbdou commented 4 years ago

I followed the documentation step by step and trying to lunch RN app after adding dependencies { implementation 'com.mesibo.api:mesibo:1.0.89' } and sync with android studio keeps giving me the same error : `> Task :app:processDebugManifest FAILED [com.mesibo.api:calls:1.0.74] C:\Users\mimom.gradle\caches\transforms-2\files-2.1\04952edf36b243c25655a0e619971942\jetified-calls-1.0.74\AndroidManifest.xml:29:5-66 Warning: Element uses-permission#android.permission.VIBRATE at [com.mesibo.api:calls:1.0.74] AndroidManifest.xml:29:5-66 duplicated with element declared at [com.mesibo.api:calls:1.0.74] AndroidManifest.xml:13:5-66 [com.mesibo.api:mesibo:1.0.89] C:\Users\mimom.gradle\caches\transforms-2\files-2.1\d6570f10c28d5fed74687c4e3ff4a3e9\jetified-mesibo-1.0.89\AndroidManifest.xml:14:5-79 Warning: Element uses-permission#android.permission.ACCESS_NETWORK_STATE at [com.mesibo.api:mesibo:1.0.89] AndroidManifest.xml:14:5-79 duplicated with element declared at [com.mesibo.api:mesibo:1.0.89] AndroidManifest.xml:11:5-79 [com.mesibo.api:mesibo:1.0.89] C:\Users\mimom.gradle\caches\transforms-2\files-2.1\d6570f10c28d5fed74687c4e3ff4a3e9\jetified-mesibo-1.0.89\AndroidManifest.xml:15:5-76 Warning: Element uses-permission#android.permission.ACCESS_WIFI_STATE at [com.mesibo.api:mesibo:1.0.89] AndroidManifest.xml:15:5-76 duplicated with element declared at [com.mesibo.api:mesibo:1.0.89] AndroidManifest.xml:12:5-76

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings 104 actionable tasks: 2 executed, 102 up-to-date D:\lab\freelanceMostaqil\tekram\android\app\src\debug\AndroidManifest.xml:10:7-34 Error: Attribute application@allowBackup value=(false) from AndroidManifest.xml:10:7-34 is also present at [com.mesibo.api:mesibo:1.0.89] AndroidManifest.xml:21:9-35 value=(true). Suggestion: add 'tools:replace="android:allowBackup"' to element at AndroidManifest.xml:7:5-117 to override.

FAILURE: Build failed with an exception.

BUILD FAILED in 32s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details. Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 D:\lab\freelanceMostaqil\tekram\android\app\src\debug\AndroidManifest.xml:10:7-34 Error: Attribute application@allowBackup value=(false) from AndroidManifest.xml:10:7-34 is also present at [com.mesibo.api:mesibo:1.0.89] AndroidManifest.xml:21:9-35 value=(true). Suggestion: add 'tools:replace="android:allowBackup"' to element at AndroidManifest.xml:7:5-117 to override.

FAILURE: Build failed with an exception.

BUILD FAILED in 32s

at makeError (D:\lab\freelanceMostaqil\tekram\node_modules\execa\index.js:174:9)
at D:\lab\freelanceMostaqil\tekram\node_modules\execa\index.js:278:16
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async runOnAllDevices (D:\lab\freelanceMostaqil\tekram\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:5)
at async Command.handleAction (D:\lab\freelanceMostaqil\tekram\node_modules\@react-native-community\cli\build\index.js:186:9)

error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.`

hackrx commented 3 years ago

Hey @abdougenesis are you able to solve this issue?

mesibo commented 3 years ago

Are you using latest API versions?

https://mesibo.com/documentation/install/android/

hackrx commented 3 years ago

@mesibo Yes, I am using the latest API version,

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

app/ build.gradle

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    //noinspection GradleDynamicVersion
        implementation 'com.mesibo.api:mesibo:1.2.30'
    //     implementation 'com.mesibo.api:ui:1.2.30'
    // implementation 'com.mesibo.api:calls:1.2.30'
    //     implementation 'com.mesibo.api:callui:1.2.30'

    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'
    }

    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }

    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }

    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
}

MainApplication.java

package com.mesibotest;

import android.app.Application;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import com.mesibo.api.Mesibo;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost =
      new ReactNativeHost(this) {
        @Override
        public boolean getUseDeveloperSupport() {
          return BuildConfig.DEBUG;
        }

        @Override
        protected List<ReactPackage> getPackages() {
          @SuppressWarnings("UnnecessaryLocalVariable")
          List<ReactPackage> packages = new PackageList(this).getPackages();
          // Packages that cannot be autolinked yet can be added manually here, for example:
          // packages.add(new MyReactNativePackage());
          return packages;
        }

        @Override
        protected String getJSMainModuleName() {
          return "index";
        }
      };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
    initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
  }

  /**
   * Loads Flipper in React Native templates. Call this in the onCreate method with something like
   * initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
   *
   * @param context
   * @param reactInstanceManager
   */
  private static void initializeFlipper(
      Context context, ReactInstanceManager reactInstanceManager) {
    if (BuildConfig.DEBUG) {
      try {
        /*
         We use reflection here to pick up the class that initializes Flipper,
        since Flipper library is not available in release mode
        */
        Class<?> aClass = Class.forName("com.mesibotest.ReactNativeFlipper");
        aClass
            .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
            .invoke(null, context, reactInstanceManager);
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (NoSuchMethodException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }
    }
  }
}

package.json

"dependencies": {
    "react": "16.13.1",
    "react-native": "0.63.4"
  },

console-error

MesiboTest % yarn android
yarn run v1.22.10
$ react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 967 file(s) to forward-jetify. Using 16 workers...
info JS server already running.
info Installing the app...

> Task :app:processDebugManifest FAILED

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.3/userguide/command_line_interface.html#sec:command_line_warnings
12 actionable tasks: 2 executed, 10 up-to-date
/Users/hackrx/Documents/MyShareFolder/MesiboTest/android/app/src/debug/AndroidManifest.xml:11:7-34 Error:
        Attribute application@allowBackup value=(false) from AndroidManifest.xml:11:7-34
        is also present at [com.mesibo.api:mesibo:1.2.30] AndroidManifest.xml:19:9-35 value=(true).
        Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at AndroidManifest.xml:7:5-117 to override.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@allowBackup value=(false) from AndroidManifest.xml:11:7-34
        is also present at [com.mesibo.api:mesibo:1.2.30] AndroidManifest.xml:19:9-35 value=(true).
        Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at AndroidManifest.xml:7:5-117 to override.

* 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 2s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
/Users/hackrx/Documents/MyShareFolder/MesiboTest/android/app/src/debug/AndroidManifest.xml:11:7-34 Error:
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
mesibo commented 3 years ago

I can see following in your logs, try it and post results

Suggestion: add 'tools:replace="android:allowBackup"' to element at AndroidManifest.xml:7:5-117 to override.

hackrx commented 3 years ago

@mesibo I already tried this and this is what I got

$ react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 967 file(s) to forward-jetify. Using 16 workers...
info JS server already running.
info Installing the app...
> Task :app:generateDebugBuildConfig FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.3/userguide/command_line_interface.html#sec:command_line_warnings
3 actionable tasks: 2 executed, 1 up-to-date

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:generateDebugBuildConfig'.
> org.xml.sax.SAXParseException; systemId: file:/Users/hackrx/Documents/MyShareFolder/MesiboTest/android/app/src/main/AndroidManifest.xml; lineNumber: 13; columnNumber: 39; The prefix "tools" for attribute "tools:replace" associated with an element type "application" is not bound.

* 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 Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

AndroidManifest.xml

  <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"              
      tools:replace ="android:allowBackup"      //<-----------------
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>
mesibo commented 3 years ago

have you added xmlns:tools="http://schemas.android.com/tools" in your manifest?

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
...

I have also raised an internal request to remove allowBackup if not required.

hackrx commented 3 years ago

Error in Js server:

image

App.js


import React, {Component} from 'react';
import {
  Alert,
  Button,
  AppRegistry,
  Platform,
  StyleSheet,
  Text,
  View,
} from 'react-native';
import MesiboModule from './MesiboModule';

// Refer to https://mesibo.com/documentation/ to generate token
const mesiboToken =
  'xxxxxxxxxxxxxxxxxxxxxxxxxxxx';
const mesiboDestination = 'Destination User';

MesiboModule.init(mesiboToken);

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
  android:
    'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

type Props = {};
export default class App extends Component<Props> {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>Welcome to Mesibo!</Text>
        <Text style={styles.instructions}>
          Ensure that the Storage permission is granted
        </Text>

        <View style={styles.buttonContainer}>
          <Button
            onPress={() => {
              MesiboModule.sendMessage(
                mesiboDestination,
                'Hello From React Native',
              );
            }}
            title="Send a Message"
          />
        </View>

        <Button
          onPress={() => {
            MesiboModule.launchUi(mesiboDestination);
          }}
          title="Launch UI"
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
  buttonContainer: {
    margin: 20,
  },

  alternativeLayoutButtonContainer: {
    margin: 20,
    flexDirection: 'row',
    justifyContent: 'space-between',
  },
});

MesiboModule.js

import {NativeModules} from 'react-native';
module.exports = NativeModules.MesiboModule;

This example is from sample/React-native/helloWorld @mesibo can you guys please make a sample project available in this repo? It is too cumbersome for any beginner.

mesibo commented 3 years ago

we will try to help but this is our official stand. Refer to https://mesibo.com/documentation/faq/#does-mesibo-supports-cross-platform-tools-like-flutter-react-native-ionic-etc

You should know how to use native API with your platform. Moreover, the latest reported issues have nothing to do with mesibo.

Closing the issue.

mesibo commented 3 years ago

We have updated the repository with a react-native sample to send messages and make video and voice calls.

A sample project is available for Android which you can build and run. You can follow similar steps to use Mesibo with React Native in iOS by creating a Native Module in iOS.