cli: MainApplication cannot be converted to ReactNativeHost List packages = new PackageList(this).getPackages();

Environment

System: OS: Linux 4.15 Linux Mint 19.1 (Tessa) CPU: (4) x64 Intel® Core™ i7-6700HQ CPU @ 2.60GHz Memory: 269.00 MB / 4.74 GB Shell: 4.4.19 - /bin/bash Binaries: Node: 10.16.0 - /usr/local/bin/node npm: 6.9.0 - /usr/local/bin/npm npmPackages: react: 16.8.6 => 16.8.6 react-native: 0.60.0 => 0.60.0 npmGlobalPackages: react-native-cli: 2.0.1

Description

I think PackageList expects ReactNativeHost but i’am using react-native-navigation When i run react-native run-android command i get this error https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081 /home/rn/Desktop/denetmenapp/android/app/src/main/java/com/denetmen/MainApplication.java:46: error: incompatible types: MainApplication cannot be converted to ReactNativeHost List<ReactPackage> packages = new PackageList(this).getPackages(); ^ Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output 1 error

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ‘:app:compileDebugJavaWithJavac’.

Compilation failed; see the compiler error output for details.

  • 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 17s

private ReactNativeHost reactNativeHost;
  public PackageList(ReactNativeHost reactNativeHost) {
    this.reactNativeHost = reactNativeHost;
  }

import com.reactnativenavigation.NavigationApplication;
import com.reactnativenavigation.react.NavigationReactNativeHost;
import com.reactnativenavigation.react.ReactGateway;

public class MainApplication extends NavigationApplication {
    
    @Override
    protected ReactGateway createReactGateway() {
        ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), 

    protected List<ReactPackage> getPackages() {
    
        @SuppressWarnings("UnnecessaryLocalVariable")
        List<ReactPackage> packages = new PackageList(this).getPackages();
     
        packages.add( new DocumentScannerPackage());
        packages.add( new CodePush("KEY", getApplicationContext(), isDebug()));

        return packages;
       
    }
}

Reproducible Demo

import com.reactnativenavigation.NavigationApplication;
import com.reactnativenavigation.react.NavigationReactNativeHost;
import com.reactnativenavigation.react.ReactGateway;

public class MainApplication extends NavigationApplication {
    
    @Override
    protected ReactGateway createReactGateway() {
        ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), 

    protected List<ReactPackage> getPackages() {
    
        @SuppressWarnings("UnnecessaryLocalVariable")
        List<ReactPackage> packages = new PackageList(this).getPackages();
     
        packages.add( new DocumentScannerPackage());
        packages.add( new CodePush("some code thing here”, getApplicationContext(), isDebug()));

        return packages;
       
    }
}

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 25 (10 by maintainers)

Most upvoted comments

the same with @react-native-community/cli@2.8.3 and react-native 0.60.4

/android/app/src/main/java/com/emphy/MainApplication.java:7: error: cannot find symbol
import com.facebook.react.PackageList;
                         ^
  symbol:   class PackageList
  location: package com.facebook.react
/Users/irynapolishchuk/mobile/android/app/src/main/java/com/emphy/MainApplication.java:45: error: cannot find symbol
      List<ReactPackage> packages = new PackageList(this).getPackages();
                                        ^
  symbol: class PackageList
2 errors

FAILURE: Build failed with an exception.

@Salakar I managed to run

@guyca i’am getting this error now /home/rn/Desktop/denetmenapp/android/app/src/main/java/com/denetmen/MainApplication.java:19: error: MainApplication is not abstract and does not override abstract method createAdditionalReactPackages() in NavigationApplication public class MainApplication extends NavigationApplication {

here is my full MainApplication.java

package com.denetmen;

import android.app.Application;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import androidx.multidex.MultiDex;
import com.documentscanner.DocumentScannerPackage;
import android.content.Context;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import com.reactnativenavigation.NavigationApplication;
import com.reactnativenavigation.react.NavigationReactNativeHost;
import com.reactnativenavigation.react.ReactGateway;
import java.util.Arrays;
import java.util.List;
import com.microsoft.codepush.react.CodePush;

public class MainApplication extends NavigationApplication {
    @Override
    protected ReactNativeHost createReactNativeHost() {
        return new NavigationReactNativeHost(this) {
            @Override
            public boolean getUseDeveloperSupport() {
                return BuildConfig.DEBUG;
            }

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

            @javax.annotation.Nullable
            @Override
            protected String getJSBundleFile() {
                return CodePush.getJSBundleFile();
            }

            @Override
            protected List<ReactPackage> getPackages() {
                @SuppressWarnings("UnnecessaryLocalVariable")
                List<ReactPackage> packages = new PackageList(this).getPackages();

                packages.add(new DocumentScannerPackage());
                packages.add(new CodePush("KEY", getApplicationContext(), isDebug()));

                return packages;
            }
        };
    }

    @Override
    public boolean isDebug() {
        return BuildConfig.DEBUG;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

}