aboozaid / react-native-wifi-hotspot

A react-native implementation for handling hotspot requests and make it easier to communicate with peers!
ISC License
40 stars 21 forks source link

"Hotspot creation has failed" #24

Open Patrick-Erichsen opened 4 years ago

Patrick-Erichsen commented 4 years ago

react-native: 0.61.5 react-native-wifi-hotspot": 1.0.0

Problem

I am unable to enable the hotspot, and therefore cannot create a hotspot.

After running through setup, I am able to reach the testing screen with all of the buttons to enable, disable, etc.

When pressing ENABLE, I get a toast notification that reads Hotspot Enabled. However, I'm receiving the following error in Logcat:

2020-06-20 00:25:45.760 6857-7748/edu.mit.privatekit E/class info.whitebyte.hotspotmanager.WifiApManager: java.lang.NoSuchMethodException: setWifiApEnabled [class android.net.wifi.WifiConfiguration, boolean]
        at java.lang.Class.getMethod(Class.java:2068)
        at java.lang.Class.getMethod(Class.java:1690)
        at info.whitebyte.hotspotmanager.WifiApManager.setWifiApEnabled(WifiApManager.java:76)
        at reactnative.hotspot.HotspotManager.isEnabled(HotspotManager.java:32)
        at reactnative.hotspot.HotspotModule.enable(HotspotModule.java:104)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:371)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:150)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:26)
        at android.os.Looper.loop(Looper.java:193)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:225)
        at java.lang.Thread.run(Thread.java:764)

Then, when I try to create a hotspot, I get a toast error that "Hotspot creation has failed". No error logs show up in Logcat.

aboozaid commented 4 years ago

From the android oreo version and above hotspot API has been protected and became systemApi, This library does not yet support these versions I will do update ASAP but I wish to get some free time to do this. PRs welcome as well

Patrick-Erichsen commented 4 years ago

Hey @assemmohamedali , thanks for the quick reply!

From the research I've done, it doesn't seem like there is a public API in Oreo and above to programmatically create hotspots with internet access. The only option is startLocalOnlyHotspot, which does not provide internet access.

aboozaid commented 4 years ago

This is one of the drawbacks of new android versions currently. The only way to enable/disable with internet access capability is to ask a user to do it manually although the second hardest approach is to use a virtual VPN with startLocalOnlyHotspot,

Patrick-Erichsen commented 4 years ago

I'm thinking of making a PR that would allow the library to work using startLocalOnlyHotspot. For the use case my team is investigating, we would not need internet access so this would be suitable.

Would you accept a PR that implements that?

aboozaid commented 4 years ago

Absolutely yeah. it would be suitable for transferring files and do some async actions on two/more devices.

Patrick-Erichsen commented 4 years ago

@assemmohamedali I'm struggling a bit to get this working.

To begin with, I'm trying to just get the library as-is to function on an up-to-date version of RN. On my fork, I've created a fresh project using react-native init TestApp and am simply trying to get the library working with that project.

However, I am getting the same issue as described in #23 when running react-native run-android

Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not resolve project :react-native-wifi-hotspot.
     Required by:
         project :app
      > Unable to find a matching configuration of project :react-native-wifi-hotspot:
          - None of the consumable configurations have attributes.

My settings.gradle looks like this:

rootProject.name = 'TestApp'
include ':react-native-wifi-hotspot'
project(':react-native-wifi-hotspot').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-wifi-hotspot/android')
include ':app'
include ':hotspotmanager'
project(':hotspotmanager').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-wifi-hotspot/android/hotspotmanager')
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)

and my app.build.gradle includes this line:

dependencies {
    implementation project(':react-native-wifi')
    ...
}

My hunch is that it is a gradle issue that I'm not familiar with.

In my gradle-wrapper.properties I have this line:

distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip

and in my top-level build.gradle I have this:

dependencies {
        classpath("com.android.tools.build:gradle:3.4.2")
        ....
}
aboozaid commented 4 years ago

react-native-wifi

and my app.build.gradle includes this line:

dependencies {
    implementation project(':react-native-wifi')
    ...
}

I think the error here where it should be react-native-wifi-hotspot not react-native-wifi

Patrick-Erichsen commented 4 years ago

@assemmohamedali I have a draft PR open here for this work. Hoping to have it cleaned up and ready for your review over the weekend!

rachitgupta98 commented 4 years ago

Hey @Patrick-Erichsen Have you got success to enable the hotspot and other features with the changes you made (in latest react native version) ??

Patrick-Erichsen commented 4 years ago

@rachitgupta98 that is correct - the new TestApp/ project I created in the repo is on RN 0.61.5 and it is able to interact with the library and create a local-only hotspot. Note that this hotspot does not have internet connectivity, however.

As I mentioned - the PR isn't quite ready for review yet, but the draft is open here if you are interested.

rachitgupta98 commented 4 years ago

Hey @Patrick-Erichsen , you can update the repo you forked with the changes ,it will be easy to use

Patrick-Erichsen commented 4 years ago

@assemmohamedali #25 is ready for review! 👍

rachitgupta98 commented 4 years ago

Hey @Patrick-Erichsen I tried to use your pe-local-hotspot-only branch as a dependency , getting this error Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.

Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'. Could not resolve project :react-native-wifi-hotspot. Required by: project :app Unable to find a matching configuration of project :react-native-wifi-hotspot:

  • None of the consumable configurations have attributes.