Skip to content

android_install

shashank1501 edited this page Sep 1, 2021 · 9 revisions

Android Installation

React-Native >= 0.60.0

If you are using autolinking feature introduced in React-Native 0.60.0 have to add only following lines in android/build.gradle file:-

  • We need to add an additional repository in order to get our dependencies.
allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven { url "https://jitpack.io" }
+       maven { url 'https://maven.mapmyindia.com/repository/mapmyindia/'}
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

React-Native < 0.60.0

react-native link should get you almost there,
however we need to add some additional lines to build.gradle.

1. android/build.gradle

We need to add an additional repository in order to get our dependencies.

  • https://jitpack.io
  • https://maven.mapmyindia.com/repository/mapmyindia/
allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
+       maven { url "https://jitpack.io" }
+       maven { url 'https://maven.mapmyindia.com/repository/mapmyindia/'}
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

Make sure that your buildscript > ext settings are correct. We want to be on 28 or higher:

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        compileSdkVersion = 28
        targetSdkVersion = 28
    }
}

Everything below should've been covered by react-native link,
however it never hurts to make sure it actually did what it was supposed to


2. android/app/build.gradle

Add project under dependencies

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
+   implementation project(':mapmyindia-map-react-native-beta')
}

You can set the Support Library version or the okhttp version if you use other modules that depend on them:

  • supportLibVersion "28.0.0"
  • okhttpVersion "3.12.1"

3. android/settings.gradle

Include project, so gradle knows where to find the project

rootProject.name = <YOUR_PROJECT_NAME>

+include ':mapmyindia-map-react-native-beta'
+project(':mapmyindia-map-react-native-beta').projectDir = new File(rootProject.projectDir, '../node_modules/mapmyindia-map-react-native-beta/android/rctmgl')

include ':app'¬

4. android/app/src/main/java/com/PROJECT_NAME/MainApplication.java

We need to register our package

Add import com.mapbox.rctmgl.RCTMGLPackage;
as an import statement and
new RCTMGLPackage() within the getPackages() method

package <YOUR_PROJECT_NAME>;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
+import com.mapbox.rctmgl.RCTMGLPackage;

import java.util.Arrays;
import java.util.List;

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() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
+         new RCTMGLPackage()
      );
    }

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

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

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

For any queries and support, please contact:

Email Email us at apisupport@mapmyindia.com

Stack Overflow Ask a question under the mapmyindia-api

Support Need support? contact us!

Blog Read about the latest updates & customer stories

© Copyright 2021. CE Info Systems Pvt. Ltd. All Rights Reserved. | Terms & Conditions