React-native-orientation: <anonymous ReactNativeHost> cannot be converted to Activity

Created on 5 Jan 2017  Â·  20Comments  Â·  Source: yamill/react-native-orientation

i get an error when i compile in android

error: incompatible types: cannot be converted to Activity
new OrientationPackage(this),

Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
:app:compileDebugJavaWithJavac FAILED

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.

Most helpful comment

Hi all I'm new to RN but I think I know why this is failing. This commit changed the constructor but is not yet published to npm ([email protected]).

If you look into your node_modules folder you see the OrientationPackage with the old Activity constructor.

I think people experiencing this issue can get a temporary fix it by pointing the dependency to the master version of the repo until the @yamill pushes the next version to npm.

Simply point your package.json entry to:

"dependencies": {
    "react": "~15.4.0-rc.4",
    "react-native": "0.40.0",
    ...
    "react-native-orientation": "git+https://[email protected]/yamill/react-native-orientation.git"
},

Then run yarn or npm innstall and try to re compile with react-native run-android. It worked for me.

All 20 comments

Change "new OrientationPackage(this)" to "new OrientationPackage()".
It works for me.

Then he says that the argumentslist is empty...

Check this step :

// The docs say this
Implement onConfigurationChanged method (in MainActivity.java)

// And I do this
Implement onConfigurationChanged method (in MainApplication.java)

ah okay ... i will try

2017-01-09 11:09 GMT+01:00 Hai Nguyen notifications@github.com:

Check this step :

// The docs say this
Implement onConfigurationChanged method (in MainActivity.java)

// And I do this
Implement onConfigurationChanged method (in MainApplication.java)

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/yamill/react-native-orientation/issues/141#issuecomment-271248251,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGMY23-w7WaAaKlvkzRPREy2QIOH_q5sks5rQgdxgaJpZM4LbvB_
.

I have same problem, i tried @ng-hai solution but it's not worked
my exception:
error: constructor OrientationPackage in class OrientationPackage cannot be applied to given types;
new OrientationPackage(this)
^
required: Activity
found:
reason: actual argument cannot be converted to Activity by method invocation conversion
1 error
:app:compileDebugJavaWithJavac FAILED

anybody can help me please?

Hi all I'm new to RN but I think I know why this is failing. This commit changed the constructor but is not yet published to npm ([email protected]).

If you look into your node_modules folder you see the OrientationPackage with the old Activity constructor.

I think people experiencing this issue can get a temporary fix it by pointing the dependency to the master version of the repo until the @yamill pushes the next version to npm.

Simply point your package.json entry to:

"dependencies": {
    "react": "~15.4.0-rc.4",
    "react-native": "0.40.0",
    ...
    "react-native-orientation": "git+https://[email protected]/yamill/react-native-orientation.git"
},

Then run yarn or npm innstall and try to re compile with react-native run-android. It worked for me.

Thank you! It's work!

@cherta Thanks, it works

I tried to change "react-native-orientation": git+https://[email protected]/yamill/react-native-orientation.git"
but still not working.../Users/luca/workspace/pillsy/android/app/src/main/java/com/pillsy/MainApplication.java:27: error: constructor OrientationPackage in class OrientationPackage cannot be applied to given types;
new OrientationPackage(this)
^
required: no arguments
found:
reason: actual and formal argument lists differ in length
1 error
:app:compileDebugJavaWithJavac FAILED

Hi, @zhiyong888! Try removing node_modules and executing yarn again, maybe that helps.

Hi @cherta , I already tried to remove node_modules and executed npm install. but still not working...

If you check the code on the master branch, the constructor that complains about the argument is in the correct shape. Try looking at your node_modules version of the same file to see if it's the same, or it's still downloading the npm published version.

`package com.github.yamill.orientation;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

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

public class OrientationPackage implements ReactPackage {

public OrientationPackage() {
}

@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
    return Arrays.<NativeModule>asList(
        new OrientationModule(reactContext)
    );
}

@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
    return Collections.emptyList();
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
    return Arrays.asList();
}

} This is OrientationPackage.java in mynode_modules`. very weird.

weird indeed. Try react-native link I don't think it helps but who knows

I already tried react-native link and linked successful. but still not working...

Well, my friend, I'm out of ideas at this point :(

I solved the problem using all answers together:

1: react-native start
2: replace content of react-native-orientation with "git+https://[email protected]/yamill/react-native-orientation.git" in package.json
3: react-native upgrade
4: react-native link
5: react-native run-android with genymotion opened

Hope it helps, this is my first answer.

Closing this as there have been updates to master which fix this. Like @cherta said in his comment, just point your package.json to this repo instead of the NPM version.

@andrerfneves this issue is not fixed with the npm module. yarn add / npm install still gives this issue.

@idlework like it says in the README, the npm module is not updated to the GitHub repository. Which means the NPM version of the package is outdated. Please use the "git+https://[email protected]/yamill/react-native-orientation.git" instead of the npm version inside your package.json. You can also read through the README for more info. If error persists, please open another issue.

Was this page helpful?
0 / 5 - 0 ratings