React-native: Is there any way to disalbe auto link packages on Android? [RN 0.60.0]

Created on 12 Jul 2019  路  4Comments  路  Source: facebook/react-native

Is there any way not auto link packages on Android? [RN 0.60.0]

RN-codepush is not support 0.60.0 and now I can not pass the server address param.

Now generated PackageList.java looks like this:
new CodePush(${androidDeploymentKey}, getApplicationContext(), BuildConfig.DEBUG),

I need to pass 1st and 4th param

Android Ran Commands Question

Most helpful comment

I temporarily disabled the auto link feature so that I can link them manually.
Just adding it here for whoever wants to do it.

android/settings.gradle

rootProject.name = 'addpointment'
// Comment this line
// apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':rn-android-picker-dialog'
project(':rn-android-picker-dialog').projectDir = new File(rootProject.projectDir, '../node_modules/rn-android-picker-dialog/android')
include ':app'

android/app/build.gradle

apply plugin: "com.android.application"
...
...
// comment this line
// apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

android/app/src/main/java/com/{yourproject}/MainApplication.java


package com.yourproject;

import android.app.Application;
import android.util.Log;

// Comment this line
// import com.facebook.react.PackageList;
// add this package
import com.facebook.react.shell.MainReactPackage;
import com.facebook.hermes.reactexecutor.HermesExecutorFactory;
import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;

import com.rnandroidpicker.PickerPackage;

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() {
      // UnComment to enable autolinking
      // @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 PickerPackage());
      // return packages;
      // add these lines
      return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new PickerPackage()
      );
    }

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

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

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

All 4 comments


We are automatically closing this issue because it does not appear to follow any of the provided issue templates.

馃憠 Click here if you want to report a reproducible bug or regression in React Native.

node_modules/@react-native-community/cli-platform-android/native_modules.gradle

disable "preBuild.dependsOn generatePackageList"

I temporarily disabled the auto link feature so that I can link them manually.
Just adding it here for whoever wants to do it.

android/settings.gradle

rootProject.name = 'addpointment'
// Comment this line
// apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':rn-android-picker-dialog'
project(':rn-android-picker-dialog').projectDir = new File(rootProject.projectDir, '../node_modules/rn-android-picker-dialog/android')
include ':app'

android/app/build.gradle

apply plugin: "com.android.application"
...
...
// comment this line
// apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

android/app/src/main/java/com/{yourproject}/MainApplication.java


package com.yourproject;

import android.app.Application;
import android.util.Log;

// Comment this line
// import com.facebook.react.PackageList;
// add this package
import com.facebook.react.shell.MainReactPackage;
import com.facebook.hermes.reactexecutor.HermesExecutorFactory;
import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;

import com.rnandroidpicker.PickerPackage;

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() {
      // UnComment to enable autolinking
      // @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 PickerPackage());
      // return packages;
      // add these lines
      return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new PickerPackage()
      );
    }

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

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

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

Instead of disabling everything you can also config the package to behave properly https://github.com/react-native-community/cli/blob/master/docs/dependencies.md#platformsandroidpackageinstance

Was this page helpful?
0 / 5 - 0 ratings