react-native-social-share icon indicating copy to clipboard operation
react-native-social-share copied to clipboard

Android Error

Open buskerone opened this issue 8 years ago • 18 comments
trafficstars

I've an error while trying to share via Facebook or Twitter on an Android device (iOS ok):

captura de pantalla 2017-03-22 a las 16 53 34

_shareOnFacebook() { shareOnFacebook({ 'link':'https://artboost.com/' }, (results) => { console.log(results); } ); } Maybe I've skipped something in the documentation?

buskerone avatar Mar 22 '17 19:03 buskerone

Hi @buskerone I can't help you much with Android. Maybe @Jberlinsky or @minhtule can help you 😄

doefler avatar Mar 23 '17 10:03 doefler

@Jberlinsky @minhtule can you help me guys?

buskerone avatar Mar 23 '17 14:03 buskerone

@buskerone I'm sorry that I'm not familiar with the share-via-Facebook feature. I would recommend you to use the official Facebook react native sdk. If you have a problem with share-via-Twitter, please share the stack trace here!

minhtule avatar Mar 24 '17 13:03 minhtule

Ok thanks @minhtule . I'll try with Facebook RN SDK. The problem is also with sharing via twitter (Android). Same error.

buskerone avatar Mar 24 '17 13:03 buskerone

@buskerone After installing the module (npm install react-native-social-share --save), did you run react-native link? I just checked and it's not part of the readme but it worked for me 😬

minhtule avatar Mar 24 '17 13:03 minhtule

yes I did but for some reason it didn't work. Now I did a clean installation of the module and it seems to be working fine for Twitter, about Facebook isn't working but no errors at all, I assume that is b/c I'm using the simulator and without the Facebook app installed! Thanks for your help @minhtule.

buskerone avatar Mar 24 '17 18:03 buskerone

@buskerone You're welcome! I'm glad that it's finally working for you! 😄

minhtule avatar Mar 26 '17 06:03 minhtule

I got the same error on android emulator, I was unable to make shareOnTwitter to work.

I added an import : import com.barefootcoders.android.react.KDSocialShare.KDSocialShare; to the MainApplication.java and new KDSocialShare() in the getPackages method and finally got it working, but only the text field.

Not tested on device with the twitter app installed yet.

Hope these two lines will help !

fab-devtag avatar Apr 03 '17 16:04 fab-devtag

@minhtule or @Jberlinsky I seem to be having the same issue as the people above. I have the module installed and working on IOS, no luck with Android yet.

Things I've tried:

  • Running the Link (which runs successfully)
  • Manually adding the 2 lines @Tigrakto suggested above
  • Uninstalling the Module and reinstalling it (along with linking it after re-installing)

I've attached a picture of the error I get, along with the MainApplication file where you can see the 2 lines in there (these were added through the Link).

If I remove the 2 lines from MainApplication I can get the app to compile, but when I try to tweet I get undefined is not an object (evaluating 'KDSocialShare.tweet')

Any suggestions are very appreciated.

Thanks!

image image

angusmccloud avatar May 09 '17 01:05 angusmccloud

Here are the changes I had when installing this library.

  • In package.json
...
 "react-native-social-share": "^1.0.0",
...
  • In android/settings.gradle
...
include ':react-native-social-share'
project(':react-native-social-share').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-social-share/android')
...
  • In android/app/build.gradle
dependencies(
    compile project(':react-native-social-share')
   ...
)

And the 2 lines in MainApplication.java that Tigrakto mentioned. @angusmccloud Could you please check that you have all these changes?

minhtule avatar May 09 '17 14:05 minhtule

@minhtule you got me on the right path, thank you! I was missing the line in build.gradle (and package.json was referring to 0.9.0 instead of 1.0). Once I added the link into build.gradle the package started building successfully on Android, but wouldn't actually post anything (i'd just get an "error" as the result).

To get it to actually work, I needed to uninstall and reinstall specifically installing version 1.0.0. Once I installed, re-linked, checked all files were right, it actually worked (for twitter only, as expected)!

This did break iPhone from building, time to go try and figure out why fixing this broke iOS...

EDIT: For anyone else in the future who breaks their iOS instance this way. I realized my issue was from re-running Link after downloading 1.0.0. To fix this:

  • I created a new branch from Master (where it was compiling and working on iOS, compiling but not working on Android)
  • I made sure I had 1.0.0 installed
  • I manually checked/updated the 4 files outlined above by @minhtule

Once I followed those steps I got my app back compiling on both platforms and twitter working on both platforms.

angusmccloud avatar May 10 '17 00:05 angusmccloud

Let me know if I should add/edit something in the README.md or other files, keeping in mind it should work for all scenarios 😄

doefler avatar May 10 '17 12:05 doefler

@doefler the only thing I would do is add to the website the steps of checking those 4 files as part of installation. It seems like running npm link takes care of 3 of the 4 - but checking all 4 can't hurt.

OR, I suppose that can continue to live in this thread where anyone trying to get Android working will find it (aka how I got here).

angusmccloud avatar May 10 '17 13:05 angusmccloud

I think some of your advice from above could be combined into a step by step guide and video. This could have its own section I can link to from the README.md What do you think? I could also link to this issue?

doefler avatar May 10 '17 17:05 doefler

this happen to me also.

Is there a way to separate the share system of twitter and facebook? I just want to use the twitter and the facebook part is having an issue with the current rn fbsdk module, so its much better if you can separate it because when I install it, it crash the app also it duplicates all codes that I added for rn-fbsdk for android, And I need to uninstall this and manually remove all codes that this plugin install.

thanks,

eggybot avatar May 23 '17 22:05 eggybot

Hey @eggybot

I am not quite sure how you imagine it to work/be implemented. As I haven't don't know much about the Android part, I can't tell if it is possible. Looking through the Android code, it seems to me that fallbacks have been built in, so I don't understand what is causing errors. See this code snippet from https://github.com/doefler/react-native-social-share/blob/master/android/src/main/java/com/barefootcoders/android/react/KDSocialShare/KDSocialShareModule.java:


if (options.hasKey("text") && doesPackageExist("com.facebook.katana")) {
	String shareText = options.getString("text");
	shareIntent = new Intent(Intent.ACTION_SEND);
	shareIntent.setType("text/plain");
	shareIntent.putExtra(Intent.EXTRA_TEXT, shareText);
} else if (options.hasKey("link")) {
	String shareUrl = options.getString("link");
	String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + shareUrl;
	shareIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
} else {
	if (options.hasKey("text") && !doesPackageExist("com.facebook.katana")) {
		callback.invoke("error", "If text is provided to Facebook sharing, the application must be installed");
	} else {
		callback.invoke("error");
	}
	return;
}

Would be awesome to find a sustainable fix for Android, so people don't get these issues :) @buskerone @minhtule @Tigrakto @angusmccloud

doefler avatar May 23 '17 22:05 doefler

image not loading in twitter share android and tweet button is also disable @minhtule can u help me fix i :)

nandhakishore-g avatar Jul 26 '17 07:07 nandhakishore-g

@nandhakishore14 I'm very sorry to disappoint you but I no longer do development on React Native so I'm not familiar with the latest changes on the platform to help you debug 😞

minhtule avatar Jul 26 '17 12:07 minhtule