3

I'm trying to follow these instructions: https://www.npmjs.com/package/react-native-text-input-layout. I'm confused at the register module in mainactivity.java part. My mainactivity.java doesn't look at all like the one from the instructions.

This is my mainactivity.java:

package com.starterkit;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;

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

public class MainActivity extends ReactActivity {

/**
 * Returns the name of the main component registered from JavaScript.
 * This is used to schedule rendering of the component.
 */
@Override
protected String getMainComponentName() {
    return "StarterKit";
}

/**
 * Returns whether dev mode should be enabled.
 * This enables e.g. the dev menu.
 */
@Override
protected boolean getUseDeveloperSupport() {
    return BuildConfig.DEBUG;
}

   /**
   * A list of packages used by the app. If the app uses additional views
   * or modules besides the default ones, add more packages here.
   */
@Override
protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
    new MainReactPackage()
  );
}
}

And this is the mainactivity.java from the instructions:

 import com.memox.rntextinputlayout.RNTextInputLayoutPackage;  // <---       import 

 public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
 ......

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);

mReactInstanceManager = ReactInstanceManager.builder()
  .setApplication(getApplication())
  .setBundleAssetName("index.android.bundle")
  .setJSMainModuleName("index.android")
  .addPackage(new MainReactPackage())
  .addPackage(new RNTextInputLayoutPackage()) // <------ add this line to your MainActivity class 
  .setUseDeveloperSupport(BuildConfig.DEBUG)
  .setInitialLifecycleState(LifecycleState.RESUMED)
  .build();

mReactRootView.startReactApplication(mReactInstanceManager, "AndroidRNSample", null);

setContentView(mReactRootView);
}
......
}
dms
  • 35
  • 1
  • 6

1 Answers1

3

You can add like this:

protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
    new MainReactPackage()
   ,new RNTextInputLayoutPackage()
  );
}
sekogs
  • 292
  • 4
  • 18
  • I tried this and got the following error. FAILURE: Build failed with an exception. * Where: Build file '/Users/mickey/react-native-starter-app-master1/android/app/build.gradle' line: 125 * What went wrong: A problem occurred evaluating project ':app'. > Project with path ':RNTextInputLayout' could not be found in project ':app'. – dms Mar 15 '16 at 11:42
  • Did you make necessary changes at android/settings.gradle and android/app/build.gradle files? – sekogs Mar 15 '16 at 11:58
  • Your solution and a minor change fixed it. The names were different in settings.gradle and build.gradle. Thanks for the help! – dms Mar 15 '16 at 12:10