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);
}
......
}

1 Answer 1

3

You can add like this:

protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
    new MainReactPackage()
   ,new RNTextInputLayoutPackage()
  );
}
Sign up to request clarification or add additional context in comments.

3 Comments

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'.
Did you make necessary changes at android/settings.gradle and android/app/build.gradle files?
Your solution and a minor change fixed it. The names were different in settings.gradle and build.gradle. Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.